I'm testing a PostgreSQL 8.2.1 to 9.2 upgrade on a virtual machine running a custom Linux distro. The upgrade procedure is as follows:
- Start the
pgservice - Vacuum all DBs (not sure if this is needed)
- Backup with
pg_dumpall - Stop the
pgservice - Move away the directory where the data is stored (
/var/pg; it's a simple, single-server setup) - Install PostgreSQL 9.2
initdb- Start the server
- Restore the dumped data
reindexdball DBs- Recreate the
referential_constraintsview - Vacuum all DBs (AFAIK required after this upgrade)
This procedure works fine on one host, backing up and restoring without a hitch. On another machine with a different database points 1 through 7 work fine, but the server won't start unless I add a sleep 1 after initdb, and even then the dumped data can't be restored because "the database system is starting up". What are the standard ways to deal with this, except for these terrible hacks:
sleeping for some generous amount of time before either operation,- looping until it works or until a generous timeout is reached, or
- looping until it accepts a trivial query or a timeout is reached.
Edit: The "solution" didn't work after all. What does it take to make sure the database is ready to run a restore?

initdbexit status? I suppose when it's set work is done. – dezso Oct 16 '12 at 16:32initdbis run synchronously, so when the server is startedinitdbis already finished successfully. – l0b0 Oct 16 '12 at 20:26