Re: need a method to ping a running database - Mailing list pgsql-general

From Tom Lane
Subject Re: need a method to ping a running database
Date
Msg-id 26498.1055392368@sss.pgh.pa.us
Whole thread Raw
In response to need a method to ping a running database  (Travis Hume <travis.hume@tenzing.com>)
List pgsql-general
Travis Hume <travis.hume@tenzing.com> writes:
> I need a shell scriptable method to determine if a postgresql database
> is running and accepting connections.

Right now I think the best you can do is see if a command actually
succeeds, eg try
    psql -c "select 1"
and see if it complains.

There are some speculations in the archives about writing a pg_ping
utility that would check to see if the postmaster is alive without
expending the overhead of really executing a SQL command --- but no
one's got round to writing any code for it, AFAIK.  In any case, psql -c
is a bit more thorough of a test, since it not only checks whether the
database is alive but whether it is willing to accept commands from
*you*.  I can think of scenarios where each kind of test would be more
appropriate, so it's something you have to make up your own mind about.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: LC_COLLATE=es_MX in PgSQL 7.3.2
Next
From: Alvaro Herrera
Date:
Subject: Re: LC_COLLATE=es_MX in PgSQL 7.3.2