Terminating a backend

Lists: pgsql-hackerspgsql-patches
From: Bruce Momjian <bruce(at)momjian(dot)us>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Terminating a backend
Date: 2008-03-07 01:21:44
Message-ID: 200803070121.m271Li315581@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

I have an idea for this TODO item:

* Allow administrators to safely terminate individual sessions either
via an SQL function or SIGTERM

Lock table corruption following SIGTERM of an individual backend
has been reported in 8.0. A possible cause was fixed in 8.1, but
it is unknown whether other problems exist. This item mostly
requires additional testing rather than of writing any new code.

http://archives.postgresql.org/pgsql-hackers/2006-08/msg00174.php

When we get the termination signal, why can't we just set a global
boolean, do a query cancel, and in the setjmp() code block check the
global and exit --- at that stage we know we have released all locks and
can exit cleanly.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Terminating a backend
Date: 2008-03-07 01:34:29
Message-ID: 29980.1204853669@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> I have an idea for this TODO item:
> ...
> When we get the termination signal, why can't we just set a global
> boolean, do a query cancel, and in the setjmp() code block check the
> global and exit --- at that stage we know we have released all locks and
> can exit cleanly.

How does that differ from what happens now?

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Terminating a backend
Date: 2008-03-07 01:40:56
Message-ID: 200803070140.m271eu603496@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > I have an idea for this TODO item:
> > ...
> > When we get the termination signal, why can't we just set a global
> > boolean, do a query cancel, and in the setjmp() code block check the
> > global and exit --- at that stage we know we have released all locks and
> > can exit cleanly.
>
> How does that differ from what happens now?

We would _terminate_/exit, not just cancel the query.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Terminating a backend
Date: 2008-03-10 17:48:26
Message-ID: 200803101748.m2AHmQT08650@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian wrote:
> I have an idea for this TODO item:
>
> * Allow administrators to safely terminate individual sessions either
> via an SQL function or SIGTERM
>
> Lock table corruption following SIGTERM of an individual backend
> has been reported in 8.0. A possible cause was fixed in 8.1, but
> it is unknown whether other problems exist. This item mostly
> requires additional testing rather than of writing any new code.
>
> http://archives.postgresql.org/pgsql-hackers/2006-08/msg00174.php
>
> When we get the termination signal, why can't we just set a global
> boolean, do a query cancel, and in the setjmp() code block check the
> global and exit --- at that stage we know we have released all locks and
> can exit cleanly.

Should I add this as a TODO? Seems so. Tom commented in the patches
queue that it will not work but I don't understand why.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Terminating a backend
Date: 2008-03-10 17:57:45
Message-ID: 6402.1205171865@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Bruce Momjian wrote:
>> When we get the termination signal, why can't we just set a global
>> boolean, do a query cancel, and in the setjmp() code block check the
>> global and exit --- at that stage we know we have released all locks and
>> can exit cleanly.

> Should I add this as a TODO? Seems so. Tom commented in the patches
> queue that it will not work but I don't understand why.

The problem with treating it like elog(ERROR) is that you're at the
mercy of user-defined code as to whether you'll actually exit or not.
UDFs can trap elog(ERROR).

regards, tom lane


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Terminating a backend
Date: 2008-03-10 18:17:49
Message-ID: 20080310181749.GE8199@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Bruce Momjian wrote:
> >> When we get the termination signal, why can't we just set a global
> >> boolean, do a query cancel, and in the setjmp() code block check the
> >> global and exit --- at that stage we know we have released all locks and
> >> can exit cleanly.
>
> > Should I add this as a TODO? Seems so. Tom commented in the patches
> > queue that it will not work but I don't understand why.
>
> The problem with treating it like elog(ERROR) is that you're at the
> mercy of user-defined code as to whether you'll actually exit or not.
> UDFs can trap elog(ERROR).

Well, we can punt and blame the writer of the UDF if the signal is not
timely honored. Having something that works for 98% of the cases, can
be fixed for 1% of the remainder, and only fails in 1% (proprietary code
that cannot be fixed) is better than having nothing at all.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Terminating a backend
Date: 2008-03-10 18:22:20
Message-ID: 200803101822.m2AIMKv12176@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Bruce Momjian wrote:
> >> When we get the termination signal, why can't we just set a global
> >> boolean, do a query cancel, and in the setjmp() code block check the
> >> global and exit --- at that stage we know we have released all locks and
> >> can exit cleanly.
>
> > Should I add this as a TODO? Seems so. Tom commented in the patches
> > queue that it will not work but I don't understand why.
>
> The problem with treating it like elog(ERROR) is that you're at the
> mercy of user-defined code as to whether you'll actually exit or not.
> UDFs can trap elog(ERROR).

I don't understand. I was never considering elog(ERROR).

Right now for cancel we have:

pqsignal(SIGINT, StatementCancelHandler);

I am suggesting we add a new fuction pg_terminate_backend() that does
everything just like cancel, but also sets a global variable that we
check in the loop where we look for the next command and if it is set,
we exit the backend.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Terminating a backend
Date: 2008-03-10 19:13:35
Message-ID: 20164.1205176415@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> I am suggesting we add a new fuction pg_terminate_backend() that does
> everything just like cancel, but also sets a global variable that we
> check in the loop where we look for the next command and if it is set,
> we exit the backend.

And if you never *get* to that loop, what have you accomplished?

Keep in mind that 99% of the excuse for people to want to use SIGTERM is
that the backend isn't responding to SIGINT. If you've fixed things so
that SIGTERM cannot get them out of any situation that SIGINT doesn't
get them out of, I don't think it's a step forward.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Terminating a backend
Date: 2008-03-10 19:18:19
Message-ID: 200803101918.m2AJIJ527080@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > I am suggesting we add a new fuction pg_terminate_backend() that does
> > everything just like cancel, but also sets a global variable that we
> > check in the loop where we look for the next command and if it is set,
> > we exit the backend.
>
> And if you never *get* to that loop, what have you accomplished?
>
> Keep in mind that 99% of the excuse for people to want to use SIGTERM is
> that the backend isn't responding to SIGINT. If you've fixed things so
> that SIGTERM cannot get them out of any situation that SIGINT doesn't
> get them out of, I don't think it's a step forward.

What I hear people ask is that they don't want the backend to read the
next command but to exit. That seems like a reasonable request.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Terminating a backend
Date: 2008-03-10 19:30:48
Message-ID: 21557.1205177448@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Tom Lane wrote:
>> Keep in mind that 99% of the excuse for people to want to use SIGTERM is
>> that the backend isn't responding to SIGINT. If you've fixed things so
>> that SIGTERM cannot get them out of any situation that SIGINT doesn't
>> get them out of, I don't think it's a step forward.

> What I hear people ask is that they don't want the backend to read the
> next command but to exit. That seems like a reasonable request.

[shrug...] They can do that now, most of the time. What this is about
is dealing with corner cases, and in that respect what your proposal
will do is replace soluble problems with insoluble ones. But I suppose
I can't stop you if you're insistent.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Terminating a backend
Date: 2008-03-11 03:03:58
Message-ID: 200803110303.m2B33wX22364@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Tom Lane wrote:
> >> Keep in mind that 99% of the excuse for people to want to use SIGTERM is
> >> that the backend isn't responding to SIGINT. If you've fixed things so
> >> that SIGTERM cannot get them out of any situation that SIGINT doesn't
> >> get them out of, I don't think it's a step forward.
>
> > What I hear people ask is that they don't want the backend to read the
> > next command but to exit. That seems like a reasonable request.
>
> [shrug...] They can do that now, most of the time. What this is about
> is dealing with corner cases, and in that respect what your proposal
> will do is replace soluble problems with insoluble ones. But I suppose
> I can't stop you if you're insistent.

I am kind of confused by your reaction to my idea. I thought we agreed
that there was going to be no way to cleanly terminate a backend at an
arbitrary time, and I thought we were getting better at having query
cancel work in most cases, so it seems combining these two ideas that
query cancel with an immediate exit from the query loop was a perfect
solution to a feature request we get regularly.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Terminating a backend
Date: 2008-04-12 14:04:09
Message-ID: 200804121404.m3CE49419634@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian wrote:
> I have an idea for this TODO item:
>
> * Allow administrators to safely terminate individual sessions either
> via an SQL function or SIGTERM
>
> Lock table corruption following SIGTERM of an individual backend
> has been reported in 8.0. A possible cause was fixed in 8.1, but
> it is unknown whether other problems exist. This item mostly
> requires additional testing rather than of writing any new code.
>
> http://archives.postgresql.org/pgsql-hackers/2006-08/msg00174.php
>
> When we get the termination signal, why can't we just set a global
> boolean, do a query cancel, and in the setjmp() code block check the
> global and exit --- at that stage we know we have released all locks and
> can exit cleanly.

I have implemented this idea with the attached patch.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Attachment Content-Type Size
/rtmp/diff text/x-diff 10.7 KB

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Terminating a backend
Date: 2008-04-12 15:32:00
Message-ID: 200804121532.m3CFW0Y23826@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian wrote:
> Bruce Momjian wrote:
> > I have an idea for this TODO item:
> >
> > * Allow administrators to safely terminate individual sessions either
> > via an SQL function or SIGTERM
> >
> > Lock table corruption following SIGTERM of an individual backend
> > has been reported in 8.0. A possible cause was fixed in 8.1, but
> > it is unknown whether other problems exist. This item mostly
> > requires additional testing rather than of writing any new code.
> >
> > http://archives.postgresql.org/pgsql-hackers/2006-08/msg00174.php
> >
> > When we get the termination signal, why can't we just set a global
> > boolean, do a query cancel, and in the setjmp() code block check the
> > global and exit --- at that stage we know we have released all locks and
> > can exit cleanly.
>
> I have implemented this idea with the attached patch.

One problem I have with my patch is that SIGTERM is currently used by
the postmaster to shut down backends. Now because the postmaster knows
that all backend are terminating, it can accept a dirtier shutdown than
one where we are terminating just one backend and the rest are going to
keep running. The new SIGTERM coding is going to exit a backend only in
a place where cancel is checked.

I need some thoughts in this area.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Terminating a backend
Date: 2008-04-12 16:02:19
Message-ID: 16439.1208016139@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
>> When we get the termination signal, why can't we just set a global
>> boolean, do a query cancel, and in the setjmp() code block check the
>> global and exit --- at that stage we know we have released all locks and
>> can exit cleanly.

> I have implemented this idea with the attached patch.

It was already explained to you why this is a bad idea.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Terminating a backend
Date: 2008-04-12 16:18:34
Message-ID: 200804121618.m3CGIYa03346@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> >> When we get the termination signal, why can't we just set a global
> >> boolean, do a query cancel, and in the setjmp() code block check the
> >> global and exit --- at that stage we know we have released all locks and
> >> can exit cleanly.
>
> > I have implemented this idea with the attached patch.
>
> It was already explained to you why this is a bad idea.

Yes, I remember your comments:

http://archives.postgresql.org/pgsql-hackers/2008-03/msg00145.php

Keep in mind that 99% of the excuse for people to want to use SIGTERM is
that the backend isn't responding to SIGINT. If you've fixed things so
that SIGTERM cannot get them out of any situation that SIGINT doesn't
get them out of, I don't think it's a step forward.

...

[shrug...] They can do that now, most of the time. What this is about
is dealing with corner cases, and in that respect what your proposal
will do is replace soluble problems with insoluble ones. But I suppose
I can't stop you if you're insistent.

I need more than one person to tell me it is a bad idea because I think
it is a good idea.

If we tell people SIGTERM is not safe to use then why is making it safe
worse. And if it is safe, we can just add a function to enable SIGTERM
to the backend without doing the query cancel longjump().

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Terminating a backend
Date: 2008-04-13 18:12:10
Message-ID: 200804131812.m3DICAw21846@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian wrote:
> > > When we get the termination signal, why can't we just set a global
> > > boolean, do a query cancel, and in the setjmp() code block check the
> > > global and exit --- at that stage we know we have released all locks and
> > > can exit cleanly.
> >
> > I have implemented this idea with the attached patch.
>
> One problem I have with my patch is that SIGTERM is currently used by
> the postmaster to shut down backends. Now because the postmaster knows
> that all backend are terminating, it can accept a dirtier shutdown than
> one where we are terminating just one backend and the rest are going to
> keep running. The new SIGTERM coding is going to exit a backend only in
> a place where cancel is checked.

I have a idea --- to have pg_terminate_backend() set a PGPROC boolean
and then send a query cancel signal to the backend --- the backend can
then check the boolean and exit if required. I will work on a new
version of this patch tomorrow/Monday.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Terminating a backend
Date: 2008-04-13 20:04:51
Message-ID: 20080413200451.GC21979@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian wrote:

> I have a idea --- to have pg_terminate_backend() set a PGPROC boolean
> and then send a query cancel signal to the backend --- the backend can
> then check the boolean and exit if required. I will work on a new
> version of this patch tomorrow/Monday.

That's fine, even if it fails on 0.1% of the cases, but you can't use
SIGTERM to implement that because it already has a different meaning.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Terminating a backend
Date: 2008-04-14 17:52:38
Message-ID: 200804141752.m3EHqcI13649@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

oikBruce Momjian wrote:
> Bruce Momjian wrote:
> > > > When we get the termination signal, why can't we just set a global
> > > > boolean, do a query cancel, and in the setjmp() code block check the
> > > > global and exit --- at that stage we know we have released all locks and
> > > > can exit cleanly.
> > >
> > > I have implemented this idea with the attached patch.
> >
> > One problem I have with my patch is that SIGTERM is currently used by
> > the postmaster to shut down backends. Now because the postmaster knows
> > that all backend are terminating, it can accept a dirtier shutdown than
> > one where we are terminating just one backend and the rest are going to
> > keep running. The new SIGTERM coding is going to exit a backend only in
> > a place where cancel is checked.
>
> I have a idea --- to have pg_terminate_backend() set a PGPROC boolean
> and then send a query cancel signal to the backend --- the backend can
> then check the boolean and exit if required. I will work on a new
> version of this patch tomorrow/Monday.

Updated patch attached. I didn't modify SIGTERM at all but set a PRPROC
boolean and piggybacked on SIGINT. I think I got the PGPROC locking
right. I had to split apart pg_signal_backend() so I could do the
permission and pid checks independent of the signalling, because I
pg_terminate_backend() needs to check, then set the PGPROC variable,
then send the signal.

I also added an administration doc mention about when to use
pg_terminate_backend().

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Attachment Content-Type Size
/pgpatches/terminate text/x-diff 9.8 KB

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: Terminating a backend
Date: 2008-04-15 13:53:32
Message-ID: 200804151353.m3FDrWB09489@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


Applied.

---------------------------------------------------------------------------

Bruce Momjian wrote:
> oikBruce Momjian wrote:
> > Bruce Momjian wrote:
> > > > > When we get the termination signal, why can't we just set a global
> > > > > boolean, do a query cancel, and in the setjmp() code block check the
> > > > > global and exit --- at that stage we know we have released all locks and
> > > > > can exit cleanly.
> > > >
> > > > I have implemented this idea with the attached patch.
> > >
> > > One problem I have with my patch is that SIGTERM is currently used by
> > > the postmaster to shut down backends. Now because the postmaster knows
> > > that all backend are terminating, it can accept a dirtier shutdown than
> > > one where we are terminating just one backend and the rest are going to
> > > keep running. The new SIGTERM coding is going to exit a backend only in
> > > a place where cancel is checked.
> >
> > I have a idea --- to have pg_terminate_backend() set a PGPROC boolean
> > and then send a query cancel signal to the backend --- the backend can
> > then check the boolean and exit if required. I will work on a new
> > version of this patch tomorrow/Monday.
>
> Updated patch attached. I didn't modify SIGTERM at all but set a PRPROC
> boolean and piggybacked on SIGINT. I think I got the PGPROC locking
> right. I had to split apart pg_signal_backend() so I could do the
> permission and pid checks independent of the signalling, because I
> pg_terminate_backend() needs to check, then set the PGPROC variable,
> then send the signal.
>
> I also added an administration doc mention about when to use
> pg_terminate_backend().
>
> --
> Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
> EnterpriseDB http://enterprisedb.com
>
> + If your life is a hard drive, Christ can be your backup. +

>
> --
> Sent via pgsql-patches mailing list (pgsql-patches(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-patches

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +