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

Re: Something is fairly whacko about shutdown in CVS HEAD

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Something is fairly whacko about shutdown in CVS HEAD
Date: 2007-07-01 02:42:14
Message-ID: 2308.1183257734@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackers
Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
> Tom Lane wrote:
>> I'm seeing two sets of shutdown messages, and apparently a second
>> shutdown checkpoint being forced, during a normal database stop:

> Huh, I can't reproduce it here.

It looks to me like this is a race condition induced by the
autovacuum-launcher patches.  Observe the following chunk of
postmaster.c, which responds to exit of the bgwriter child:

        /*
         * Was it the bgwriter?
         */
        if (BgWriterPID != 0 && pid == BgWriterPID)
        {
            BgWriterPID = 0;
            if (EXIT_STATUS_0(exitstatus) &&
                Shutdown > NoShutdown && !FatalError &&
                !DLGetHead(BackendList) && AutoVacPID == 0)
            {
                /*
                 * Normal postmaster exit is here: we've seen normal exit of
                 * the bgwriter after it's been told to shut down. We expect
                 * that it wrote a shutdown checkpoint.  (If for some reason
                 * it didn't, recovery will occur on next postmaster start.)
                 *
                 * Note: we do not wait around for exit of the archiver or
                 * stats processes.  They've been sent SIGQUIT by this point,
                 * and in any case contain logic to commit hara-kiri if they
                 * notice the postmaster is gone.
                 */
                ExitPostmaster(0);
            }

            /*
             * Any unexpected exit of the bgwriter (including FATAL exit)
             * is treated as a crash.
             */
            HandleChildCrash(pid, exitstatus,
                             _("background writer process"));

If AutoVacPID is still nonzero when bgwriter exit is detected,
then we think we've seen a crash.  I'm not clear why it happens
reliably for me and not for you, but this is certainly a bug.

To resolve this I think we need a clearer definition of the autovac
launcher's role in life.  I see that it is attached to shared memory;
is it supposed to be able to execute transactions or otherwise do
anything the bgwriter might have to clean up after?  If so we need
to fix things so that we don't tell the bgwriter to exit until after
the launcher is gone.  If not, we could possibly allow these things
to happen asynchronously, though I wonder whether it wouldn't be best
to force the ordering anyway.

			regards, tom lane

In response to

Responses

pgsql-hackers by date

Next:From: Alvaro HerreraDate: 2007-07-01 03:57:57
Subject: Re: Something is fairly whacko about shutdown in CVS HEAD
Previous:From: Alvaro HerreraDate: 2007-07-01 00:58:10
Subject: Re: Something is fairly whacko about shutdown in CVS HEAD

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