pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrew Sullivan <ajs@crankycanuck.ca>
Cc: pgsql-sql@postgresql.org
Subject: Re: How to check postgres running or not ?
Date: Sun, 19 Sep 2004 13:12:07 -0400
Message-ID: <19876.1095613927@sss.pgh.pa.us> (raw)
In-Reply-To: <20040919165748.GB15746@phlogiston.dyndns.org>
References: <414A7395.8070503@vertex.co.in>
	<414CE76E.2050405@noggon.com>
	<414D7533.10708@3times25.net>
	<19430.1095611100@sss.pgh.pa.us>
	<20040919165748.GB15746@phlogiston.dyndns.org>

Andrew Sullivan <ajs@crankycanuck.ca> writes:
> On Sun, Sep 19, 2004 at 12:25:00PM -0400, Tom Lane wrote:
>> ps aux | grep postmaster | grep -v grep
>> (or use "ps -ef" if using a SysV-ish ps).

> Except that on Solaris, ps -ef _always_ shows "postmaster", even for
> the individual back ends.

Right, but if you see a backend then you can figure the system is up.

If you are concerned about the case where the postmaster has crashed and
yet there are still backends laying about, then the whole "ps" approach
is probably wrong anyway.  It would make more sense to check whether the
postmaster is answering the doorbell --- ie, send a connection request
and see what happens.

At one time there was discussion of writing a "pg_ping" utility program
to do exactly this, but it still hasn't got done.  You can fake it to
some extent by just running "psql -l >/dev/null" and checking the exit
code, but this does require supplying a valid username and possibly a
password (because psql's exit code doesn't distinguish "could not
connect" from authentication errors).

BTW, "pg_ctl status" doesn't answer this need because it only looks for
a postmaster.pid file, it doesn't attempt to verify that the postmaster
is really alive.

			regards, tom lane



view thread (22+ messages)  latest in thread

Message-ID: <19876.1095613927@sss.pgh.pa.us>
Permalink:  ../19876.1095613927@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19876.1095613927@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ajs@crankycanuck.ca
  Subject: Re: How to check postgres running or not ?
  In-Reply-To: <19876.1095613927@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox