Thread: Shutting down server from a backend process, e.g. walrceiver
Hi,<br /><br />I want to shut down the server under certain conditions that can be checked inside a backend process. Forinstance, while running symmetric replication, if the primary dies, I want the the walreceiver to detect that and shutdownthe standby. The reason for shutdown is that I want to execute some other stuff before I start the standby as a primary.Creating a trigger file doesn't help as it converts the standby into primary at run time.<br /><br />Using proc_exit()inside walreceiver only terminates the walreceiver process, which postgres starts again. The other way I see isusing ereport(PANIC, ...). Is there some other way to shutdown the main server from within a backend process?<br /><br/>Thanks.<br /><br /><br /><br />
On Tue, Sep 21, 2010 at 9:48 AM, fazool mein <fazoolmein@gmail.com> wrote: > Hi, > > I want to shut down the server under certain conditions that can be checked > inside a backend process. For instance, while running symmetric replication, > if the primary dies, I want the the walreceiver to detect that and shutdown > the standby. The reason for shutdown is that I want to execute some other > stuff before I start the standby as a primary. Creating a trigger file > doesn't help as it converts the standby into primary at run time. > > Using proc_exit() inside walreceiver only terminates the walreceiver > process, which postgres starts again. The other way I see is using > ereport(PANIC, ...). Is there some other way to shutdown the main server > from within a backend process? Are you going to change the source code? If yes, you might be able to do that by making walreceiver send the shutdown signal to postmaster. If no, I think that a straightforward approach is to use a clusterware like pacemaker. That is, you need to make a clusterware periodically check the master and cause the standby to end when detecting the crash of the master. Regards, -- Fujii Masao NIPPON TELEGRAPH AND TELEPHONE CORPORATION NTT Open Source Software Center
On Mon, Sep 20, 2010 at 05:48:40PM -0700, fazool mein wrote: > Hi, > > I want to shut down the server under certain conditions that can be > checked inside a backend process. For instance, while running > symmetric Synchronous? > replication, if the primary dies, I want the the walreceiver to > detect that and shutdown the standby. The reason for shutdown is > that I want to execute some other stuff before I start the standby > as a primary. Creating a trigger file doesn't help as it converts > the standby into primary at run time. > > Using proc_exit() inside walreceiver only terminates the walreceiver > process, which postgres starts again. The other way I see is using > ereport(PANIC, ...). Is there some other way to shutdown the main > server from within a backend process? Perhaps I've misunderstood, but since there's already Something Else(TM) which takes actions, why not send a message to it so it can take appropriate action on the node, starting with shutting it down? Cheers, David. -- David Fetter <david@fetter.org> http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter@gmail.com iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate
On Mon, Sep 20, 2010 at 9:44 PM, Fujii Masao <masao.fujii@gmail.com> wrote:
Yes, I'll be modifying the code. In the walreceiver, I used the following to send a shutdown to the postmaster:
kill(getppid(), SIGTERM);
This was another option, but I have to modify the code for this particular case.Are you going to change the source code? If yes, you might be able toOn Tue, Sep 21, 2010 at 9:48 AM, fazool mein <fazoolmein@gmail.com> wrote:
> Hi,
>
> I want to shut down the server under certain conditions that can be checked
> inside a backend process. For instance, while running symmetric replication,
> if the primary dies, I want the the walreceiver to detect that and shutdown
> the standby. The reason for shutdown is that I want to execute some other
> stuff before I start the standby as a primary. Creating a trigger file
> doesn't help as it converts the standby into primary at run time.
>
> Using proc_exit() inside walreceiver only terminates the walreceiver
> process, which postgres starts again. The other way I see is using
> ereport(PANIC, ...). Is there some other way to shutdown the main server
> from within a backend process?
do that by making walreceiver send the shutdown signal to postmaster.
Yes, I'll be modifying the code. In the walreceiver, I used the following to send a shutdown to the postmaster:
kill(getppid(), SIGTERM);
If no, I think that a straightforward approach is to use a clusterware
like pacemaker. That is, you need to make a clusterware periodically
check the master and cause the standby to end when detecting the crash
of the master.
Thanks for your help.
Regards,
On Tue, Sep 21, 2010 at 8:32 AM, David Fetter <david@fetter.org> wrote:
I meant streaming :), but the question is in general for any process forked by the postmaster.
(wondering)
Thanks.
On Mon, Sep 20, 2010 at 05:48:40PM -0700, fazool mein wrote:Synchronous?
> Hi,
>
> I want to shut down the server under certain conditions that can be
> checked inside a backend process. For instance, while running
> symmetric
I meant streaming :), but the question is in general for any process forked by the postmaster.
Perhaps I've misunderstood, but since there's already Something
> replication, if the primary dies, I want the the walreceiver to
> detect that and shutdown the standby. The reason for shutdown is
> that I want to execute some other stuff before I start the standby
> as a primary. Creating a trigger file doesn't help as it converts
> the standby into primary at run time.
>
> Using proc_exit() inside walreceiver only terminates the walreceiver
> process, which postgres starts again. The other way I see is using
> ereport(PANIC, ...). Is there some other way to shutdown the main
> server from within a backend process?
Else(TM) which takes actions, why not send a message to it so it can
take appropriate action on the node, starting with shutting it down?
(wondering)
Thanks.
On Wed, Sep 22, 2010 at 2:50 AM, fazool mein <fazoolmein@gmail.com> wrote: > Yes, I'll be modifying the code. In the walreceiver, I used the following to > send a shutdown to the postmaster: > > kill(getppid(), SIGTERM); You can use the global variable "PostmasterPid" instead of getppid. There are three types of shutdown. SIGTERM triggers smart shutdown. Smart shutdown is suitable for your case? If not, you might need to send SIGINT or SIGQUIT instead. Regards, -- Fujii Masao NIPPON TELEGRAPH AND TELEPHONE CORPORATION NTT Open Source Software Center
Thanks for the tips.
In our case, SIGINT makes more sense. I'll use that.
Regards
In our case, SIGINT makes more sense. I'll use that.
Regards
On Tue, Sep 21, 2010 at 7:50 PM, Fujii Masao <masao.fujii@gmail.com> wrote:
On Wed, Sep 22, 2010 at 2:50 AM, fazool mein <fazoolmein@gmail.com> wrote:You can use the global variable "PostmasterPid" instead of getppid.
> Yes, I'll be modifying the code. In the walreceiver, I used the following to
> send a shutdown to the postmaster:
>
> kill(getppid(), SIGTERM);
There are three types of shutdown. SIGTERM triggers smart shutdown.
Smart shutdown is suitable for your case? If not, you might need to
send SIGINT or SIGQUIT instead.
Regards,
--
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center