473,473 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to tell when postmaster is ready

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?

Kind regards,

Thomas Hallgren

Nov 23 '05 #1
8 1702
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 10 June 2004 09:10, Thomas Hallgren wrote:
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?


postmaster will not send a signal on its own,
but you can do some kind of busy polling:

# untested bash script
count=0
while true
do
if psql -c '\q' $MY_DATABASE 2>/dev/null
then
break
fi
count=$(($count + 1))
if [ $count > 10 ]
then
echo "Postgres seems not to be working" >&2
exit 1
fi
sleep 1
done
psql $MY_DATABASE

Mit freundlichem Gruß / With kind regards
Holger Klawitter
- --
lists <at> klawitter <dot> de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFAyBlE1Xdt0HKSwgYRAtoKAJ9uWwaSQPyFae+q7bZFP6 ovDRcTgwCcD2Dl
FdpLC9FtMsZ7PZtGqfW843g=
=BHoK
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 10 June 2004 09:10, Thomas Hallgren wrote:
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?


postmaster will not send a signal on its own,
but you can do some kind of busy polling:

# untested bash script
count=0
while true
do
if psql -c '\q' $MY_DATABASE 2>/dev/null
then
break
fi
count=$(($count + 1))
if [ $count > 10 ]
then
echo "Postgres seems not to be working" >&2
exit 1
fi
sleep 1
done
psql $MY_DATABASE

Mit freundlichem Gruß / With kind regards
Holger Klawitter
- --
lists <at> klawitter <dot> de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFAyBlE1Xdt0HKSwgYRAtoKAJ9uWwaSQPyFae+q7bZFP6 ovDRcTgwCcD2Dl
FdpLC9FtMsZ7PZtGqfW843g=
=BHoK
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #3
Thomas Hallgren wrote:
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?


I've always assumed once I can connect, then I can send queries. There's
certainly a "postmaster still starting up" error message I've seen,
which would support that view.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #4
Thomas Hallgren wrote:
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?


I've always assumed once I can connect, then I can send queries. There's
certainly a "postmaster still starting up" error message I've seen,
which would support that view.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #5
Thomas Hallgren <th***@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

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #6
Thomas Hallgren <th***@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

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #7
Tom Lane wrote:
Thomas Hallgren <th***@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

Thanks (to all who replied). I think have what I need to make good progress.

(I did try using pg_ctl start but I encountered several problems on
win32 when attempting to pass -c options to the postmaster. Seems to be
some problem concerning who parses what, the shell or pg_ctl (windows is
utterly stupid when it comes to command line parsing). And using the
wait option seemed to wait forever on win32. I'm still investigating,
will get back to you if I find something relevant).

Kind regards,

Thomas Hallgren

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #8
Tom Lane wrote:
Thomas Hallgren <th***@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

Thanks (to all who replied). I think have what I need to make good progress.

(I did try using pg_ctl start but I encountered several problems on
win32 when attempting to pass -c options to the postmaster. Seems to be
some problem concerning who parses what, the shell or pg_ctl (windows is
utterly stupid when it comes to command line parsing). And using the
wait option seemed to wait forever on win32. I'm still investigating,
will get back to you if I find something relevant).

Kind regards,

Thomas Hallgren

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mike | last post by:
Hi, In my web form, which registers email addresses, my php script does some email validation, but people still mistype email addresses which are in a valid format but don't exist. PHP tries to...
5
by: Chris Webster | last post by:
I have one process which writes a single float into 300 columns once per second. I then run 4 process, from remote computers, to query a small subset of the latest row. I have even commented...
2
by: psql-mail | last post by:
Help! Postmaster is segfaulting i think. I am running RH_AS_3beta, postgresql 7.3.4 compiled from postgresql-7.3. 4-1PGDG.src.rpm on ia64 arch. Tsearch2 compiled from tsearch-v2-stable.tar.gz ...
2
by: Andy Harrison | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Could anyone explain about the max_connections in postgres? We ran into the connection limit on one of our production servers. One reason is that we have...
0
by: Jeremiah Elliott | last post by:
I have a java application that pulls data off db2/400 an inserts it into a postgres(7.3.2) database. The jdbc errors out with this message: ConnectionBean: Driver not loaded Something unusual has...
0
by: wespvp | last post by:
I've got a 2 hour index build that has been running for 9 hours. With 'ps -efl' I see that there is a VACUUM ANALYZE running that started 24 hours ago and my index build is 'wating'. I sent a...
0
by: Thomas Hallgren | last post by:
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...
2
by: Tony O'Bryan | last post by:
I am normally the admin for our PostgreSQL servers, but someone else tried to kill a runaway query while I was out sick. Unfortunately, he tried killing the runaway query by killing the...
10
by: Tomás | last post by:
When you simply want to store a number, what integral type do you use? For instance, let's say we have the following in a Poker game: struct Card { enum Suit { Hearts, Diamonds, Spades, Clubs...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.