Commit 36ae9809 authored by Martin Pitt's avatar Martin Pitt

Refine postmaster startup checks

parent 9364a6d9
......@@ -6,8 +6,14 @@ postgresql-common (27) unstable; urgency=low
postgresql-client-X.Y packages.
* pg_ctlcluster: Have autovac-* commands error out with a meaningful message
instead of claiming success if pg_autovacuum is not available.
* pg_ctlcluster:
- Increase the timeout for the started postmaster to 20 seconds to cope
with slow startup. Closes: #320444
- Immediately fail if the postmaster produced log output and does not run
any more. This avoids unnecessary timeouts on configuration errors and
the like.
-- Martin Pitt <mpitt@debian.org> Wed, 21 Sep 2005 19:43:26 +0200
-- Martin Pitt <mpitt@debian.org> Wed, 21 Sep 2005 21:15:45 +0200
postgresql-common (26) unstable; urgency=low
......
......@@ -54,21 +54,34 @@ sub get_running_pid {
}
}
# If a pid file is already present, delete it if it is stale/invalid, or exit
# with an error if it belongs to an already running postmaster.
sub start_check_pid_file {
my $pidfile = $info{'pgdata'}.'/postmaster.pid';
my $pid = get_running_pid $pidfile;
# Check whether a pid file for the %info cluster is present and belongs to a
# running postmaster.
# Arguments: <pid file path>
sub check_running_postmaster {
my $pid = get_running_pid $_[0];
if (defined $pid and $pid =~ /^\d+$/) {
if (open PS, '-|', '/bin/ps', '-o', 'comm', 'h', 'p', $pid) {
my $process = <PS>;
chomp $process if defined $process;
close PS;
if (defined $process and $process eq 'postmaster') {
print "Cluster is already running.\n";
exit (0);
}
}
return 1;
}
} else {
error "Could not exec /bin/ps";
}
}
return 0;
}
# If a pid file is already present, delete it if it is stale/invalid, or exit
# with a notice if it belongs to an already running postmaster.
sub start_check_pid_file {
my $pidfile = $info{'pgdata'}.'/postmaster.pid';
if (check_running_postmaster $pidfile) {
print "Cluster is already running.\n";
exit (0);
}
# Remove invalid or stale PID file
......@@ -220,12 +233,19 @@ sub start {
# wait a bit until the socket exists
$success = 0;
for (my $attempt = 0; $attempt < 10; $attempt++) {
$currlogsize = 0;
my $pidfile = $info{'pgdata'}.'/postmaster.pid';
for (my $attempt = 0; $attempt < 40; $attempt++) {
select (undef, undef, undef, 0.5);
$currlogsize = (stat $info{'logfile'})[7] if -r $info{'logfile'};
if (cluster_port_running $version, $cluster, $info{'port'}) {
$success = 1;
last;
}
# if the postmaster wrote something, but the process does not exist any
# more, there must be a problem and we can stop immediately
last if ($currlogsize > $logsize && !check_running_postmaster $pidfile);
}
if ($success) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment