Re: How to tell when postmaster is ready - Mailing list pgsql-general

From Tom Lane
Subject Re: How to tell when postmaster is ready
Date
Msg-id 24299.1086877334@sss.pgh.pa.us
Whole thread Raw
In response to How to tell when postmaster is ready  (Thomas Hallgren <thhal@mailblocks.com>)
Responses Re: How to tell when postmaster is ready
List pgsql-general
Thomas Hallgren <thhal@mailblocks.com> writes:
> I'm writing a small test harness. I have two threads. One that starts
> the postmaster and another that does all the testing and finally stops
> the postmaster with a pg_ctl stop. At present, the second thread starts
> with a sleep sufficient to ensure that the postmaster is running. Is
> there a proper way to test when the postmaster is ready to receive commands?

Check to see if it answers a connection request.  If you look in the
archives for discussion of a "pg_ping" utility you'll find more about
this.  My recollection is that we'd tweaked the postmaster's behavior
so that a useful pg_ping could be written (in particular, that you'd
not need to know a valid database/user name to check for postmaster
ready), but then no one got round to actually writing it.

Now that pg_ctl is in C, it would likely make sense to rewrite its
postmaster probing as per the pg_ping ideas instead of trying to open
a normal connection.

(As for your test harness, though, you could just use pg_ctl start
with the wait option, and wait for it to finish...)

            regards, tom lane

pgsql-general by date:

Previous
From: Doug McNaught
Date:
Subject: Re: Record order change after update
Next
From: Tom Lane
Date:
Subject: Re: VACUUM FULL produce warnings