Re: Something is fairly whacko about shutdown in CVS HEAD

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Something is fairly whacko about shutdown in CVS HEAD
Date: 2007-07-01 03:57:57
Message-ID: 20070701035757.GA29338@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> 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:

> 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.

Oops, you are right. So the problem predates the latest autovac patch;
it goes all the way back to when the launcher was introduced. I can't
imagine the reason, but I haven't ever seen the double shutdown
checkpoint (not that I've been looking too closely, but I almost always
run postmasters with stderr to a console in front of my eyes when I'm
testing autovac).

> 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.

No; the launcher is attached to shared memory, but it doesn't connect to
databases and it doesn't execute transactions either. In fact, the
launcher cannot do anything when the postmaster is not running (or when
it is not in a state where it doesn't want to start processes, anyway),
because it (the launcher) is only capable of sending signals to
postmaster (apart from that, it ocasionally grabs lwlocks, reads the
pg_database flat file, pgstats, and the Xid counter in shared memory).
It doesn't write anything. I think it is perfectly acceptable to have
the launcher shut down in parallel with bgwriter.

--
Alvaro Herrera http://www.amazon.com/gp/registry/5ZYLFMCVHXC
"Amanece. (Ignacio Reyes)
El Cerro San Cristóbal me mira, cínicamente, con ojos de virgen"

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2007-07-01 07:36:57 Re: pgsql: Improve logging of checkpoints.
Previous Message Tom Lane 2007-07-01 02:42:14 Re: Something is fairly whacko about shutdown in CVS HEAD