pg_ctl is fragile

Started by Neil Conwayover 23 years ago5 messagesbugs
Jump to latest
#1Neil Conway
neilc@samurai.com

After an unclean shutdown (e.g. a kernel crash), pg_ctl isn't smart
enough to realize that it won't be able to successfully shut down the
postmaster:

$ pg_ctl -D /pgsql/data stop
/pgsql/bin/pg_ctl: line 269: kill: (2039) - No such process
waiting for postmaster to shut down................................................................ failed
pg_ctl: postmaster does not shut down

We should probably check the exit code produced by kill(1).

Cheers,

Neil

--
Neil Conway <neilc@samurai.com> || PGP Key ID: DB3C29FC

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Neil Conway (#1)
Re: pg_ctl is fragile

Neil Conway <neilc@samurai.com> writes:

After an unclean shutdown (e.g. a kernel crash), pg_ctl isn't smart
enough to realize that it won't be able to successfully shut down the
postmaster:

$ pg_ctl -D /pgsql/data stop
/pgsql/bin/pg_ctl: line 269: kill: (2039) - No such process
waiting for postmaster to shut down................................................................ failed
pg_ctl: postmaster does not shut down

We should probably check the exit code produced by kill(1).

Doesn't seem like kill's exit code is going to tell you enough.
If you got, say, "Permission denied" rather than "No such process",
you shouldn't report that the postmaster isn't running.

regards, tom lane

#3Neil Conway
neilc@samurai.com
In reply to: Tom Lane (#2)
Re: pg_ctl is fragile

Tom Lane <tgl@sss.pgh.pa.us> writes:

Doesn't seem like kill's exit code is going to tell you enough.
If you got, say, "Permission denied" rather than "No such process",
you shouldn't report that the postmaster isn't running.

Ok, fair enough -- so is there any way to improve this behavior?

Cheers,

Neil

--
Neil Conway <neilc@samurai.com> || PGP Key ID: DB3C29FC

#4Bruce Momjian
bruce@momjian.us
In reply to: Neil Conway (#3)
Re: pg_ctl is fragile

Neil Conway wrote:

Tom Lane <tgl@sss.pgh.pa.us> writes:

Doesn't seem like kill's exit code is going to tell you enough.
If you got, say, "Permission denied" rather than "No such process",
you shouldn't report that the postmaster isn't running.

Ok, fair enough -- so is there any way to improve this behavior?

Seems we could grab some of kill's stderr and grep it for "No such":

$ kill -0 32323
bash: kill: (32323) - No such pid

Probably can't hurt.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#5Peter Eisentraut
peter_e@gmx.net
In reply to: Neil Conway (#3)
Re: pg_ctl is fragile

Neil Conway writes:

Tom Lane <tgl@sss.pgh.pa.us> writes:

Doesn't seem like kill's exit code is going to tell you enough.
If you got, say, "Permission denied" rather than "No such process",
you shouldn't report that the postmaster isn't running.

Ok, fair enough -- so is there any way to improve this behavior?

Merge pg_ctl and postmaster executables.

--
Peter Eisentraut peter_e@gmx.net