Re: Something is fairly whacko about shutdown in CVS HEAD - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Something is fairly whacko about shutdown in CVS HEAD
Date
Msg-id 20070701035757.GA29338@alvh.no-ip.org
Whole thread Raw
In response to Re: Something is fairly whacko about shutdown in CVS HEAD  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Something is fairly whacko about shutdown in CVS HEAD  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Tom Lane wrote:
> Alvaro Herrera <alvherre@commandprompt.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
ojosde virgen"
 


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Something is fairly whacko about shutdown in CVS HEAD
Next
From: KaiGai Kohei
Date:
Subject: [ANN] SE-PostgreSQL 1.0 Beta released