Skip site navigation (1) Skip section navigation (2)

Re: How to know killed by pg_terminate_backend

From: Tatsuo Ishii <ishii(at)postgresql(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Cc: robertmhaas(at)gmail(dot)com, heikki(dot)linnakangas(at)enterprisedb(dot)com
Subject: Re: How to know killed by pg_terminate_backend
Date: 2011-01-02 14:01:59
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
>> >> Seems reasonable. Does the victim backend currently know why it has been
>> >> killed?
>> >
>> > I don't think so.
>> >
>> > One idea is postmaster sets a flag in the shared memory area
>> > indicating it rceived SIGTERM before forwarding the signal to
>> > backends.
>> >
>> > Backend check the flag and if it's not set, it knows that the signal
>> > has been sent by pg_terminate_backend(), not postmaster.
>> Or it could also be sent by some other user process, like the user
>> running "kill" from the shell.
> No problem (at least for pgpool-II).
> If the flag is not set, postgres returns the same code as the one
> killed by pg_terminate_backend(). The point is, backend is killed by
> postmaster or not. Because if backend was killed by postmaster,
> pgpool-II should not expect the PostgreSQL server is usable since
> postmaster decided to shutdown.

Here is the patch to implement the feature.

1) pg_terminate_backend() sends SIGUSR1 signal rather than SIGTERM to
   the target backend.
2) The infrastructure used for message passing is
   storage/ipc/procsignal.c The new message type for ProcSignalReason
3) I assign new error code 57P04 which is returned from the backend
   killed by pg_terminate_backend().


Comments are welcome.
Tatsuo Ishii
SRA OSS, Inc. Japan

Attachment: pg_terminate_backend.patch
Description: text/x-patch (4.5 KB)

In response to


pgsql-hackers by date

Next:From: Peter EisentrautDate: 2011-01-02 14:07:29
Subject: Re: Libpq PGRES_COPY_BOTH - version compatibility
Previous:From: Tatsuo IshiiDate: 2011-01-02 13:56:28
Subject: Re: How to know killed by pg_terminate_backend

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group