postgresql/src/bin
Tom Lane 250108b6f3 Fix "pg_ctl start -w" to test child process status directly.
pg_ctl start with -w previously relied on a heuristic that the postmaster
would surely always manage to create postmaster.pid within five seconds.
Unfortunately, that fails much more often than we would like on some of the
slower, more heavily loaded buildfarm members.

We have known for quite some time that we could remove the need for that
heuristic on Unix by using fork/exec instead of system() to launch the
postmaster.  This allows us to know the exact PID of the postmaster, which
allows near-certain verification that the postmaster.pid file is the one
we want and not a leftover, and it also lets us use waitpid() to detect
reliably whether the child postmaster has exited or not.

What was blocking this change was not wanting to rewrite the Windows
version of start_postmaster() to avoid use of CMD.EXE.  That's doable
in theory but would require fooling about with stdout/stderr redirection,
and getting the handling of quote-containing postmaster switches to
stay the same might be rather ticklish.  However, we realized that
we don't have to do that to fix the problem, because we can test
whether the shell process has exited as a proxy for whether the
postmaster is still alive.  That doesn't allow an exact check of the
PID in postmaster.pid, but we're no worse off than before in that
respect; and we do get to get rid of the heuristic about how long the
postmaster might take to create postmaster.pid.

On Unix, this change means that a second "pg_ctl start -w" immediately
after another such command will now reliably fail, whereas previously
it would succeed if done within two seconds of the earlier command.
Since that's a saner behavior anyway, it's fine.  On Windows, the case can
still succeed within the same time window, since pg_ctl can't tell that the
earlier postmaster's postmaster.pid isn't the pidfile it is looking for.
To ensure stable test results on Windows, we can insert a short sleep into
the test script for pg_ctl, ensuring that the existing pidfile looks stale.
This hack can be removed if we ever do rewrite start_postmaster(), but that
no longer seems like a high-priority thing to do.

Back-patch to all supported versions, both because the current behavior
is buggy and because we must do that if we want the buildfarm failures
to go away.

Tom Lane and Michael Paquier
2015-10-12 18:30:37 -04:00
..
initdb Translation updates 2015-10-05 11:00:57 -04:00
pg_basebackup Translation updates 2015-10-05 11:00:57 -04:00
pg_config Translation updates 2015-10-05 11:00:57 -04:00
pg_controldata Translation updates 2015-10-05 11:00:57 -04:00
pg_ctl Fix "pg_ctl start -w" to test child process status directly. 2015-10-12 18:30:37 -04:00
pg_dump Translation updates 2015-10-05 11:00:57 -04:00
pg_resetxlog Translation updates 2015-10-05 11:00:57 -04:00
pgevent Run pgindent on 9.2 source tree in preparation for first 9.3 2012-06-10 15:20:04 -04:00
psql Translation updates 2015-10-05 11:00:57 -04:00
scripts Translation updates 2015-10-05 11:00:57 -04:00
Makefile Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00