pg_ctl(1)'s -w option works well if the default user can automatically
authenticate without any user intervention. The attached patch checks
the error message to see if it's asking for a password. The theory
being that if it's asking for a password, the backend is up. I'm not
entirely happy with the fact that I'm dependent on the error message
text, but I couldn't easily figure out a better way to test this via
libpq(3), so I'm not too unhappy... it's just not elegant. This patch
does not encompass all possible scenarios for the backend being up, but
CONNECTION_BAD being set in libpq(3). Regardless, it's a start and
hopefully someone can apply this. I also cleaned up a small memory
leak when a connection is bad (PGconn not being free(3)'ed). -sc
% pg_ctl -w start && psql
waiting for postmaster to start....done
postmaster started
test=>