pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start
5+ messages / 3 participants
[nested] [flat]
* BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start
@ 2016-09-09 10:50 andreas.papst@univie.ac.at
2016-09-13 15:52 ` Re: BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
0 siblings, 1 reply; 5+ messages in thread
From: andreas.papst@univie.ac.at @ 2016-09-09 10:50 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 14320
Logged by: Andreas Papst
Email address: andreas.papst@univie.ac.at
PostgreSQL version: 9.4.9
Operating system: Debian GNU/Linux 8.5 (jessie)
Description:
Hey,
when starting a hot standby database insstance with
`systemctl start postgresql',
anything works perfect: WAL files are beeing applied, r/o connections are
able to query the database, but after 90 seconds (systemd
DefaultTimeoutStartSec) postgresql is beeing shut down:
2016-09-01 10:30:15.235 CEST @ (/26671) LOG: received smart shutdown
request
2016-09-01 10:30:15.330 CEST @ (/26699) FATAL: terminating walreceiver
process
due to administrator command
2016-09-01 10:30:16.967 CEST @ (/26675) LOG: shutting down
2016-09-01 10:30:17.748 CEST @ (/26675) LOG: database system is shut down
and the systemctl start command returns too.
I guess this is due to a missing step in starting up postgresql in hot
standby configuration, where this process should be detached/daemonized
(calling setsid).
To proof it, I sent a signal with
`systemctl reload postgresql´ which caused the systemctl start command to
finish and kept postgresql running.
I've tried to find the respective lines in the code but I totally get lost.
So please if somebody can fix it.
Thank you
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start
2016-09-09 10:50 BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start andreas.papst@univie.ac.at
@ 2016-09-13 15:52 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-14 07:12 ` Re: BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start Andreas Papst <andreas.papst@univie.ac.at>
0 siblings, 1 reply; 5+ messages in thread
From: Peter Eisentraut @ 2016-09-13 15:52 UTC (permalink / raw)
To: andreas.papst@univie.ac.at; pgsql-bugs
On 9/9/16 6:50 AM, andreas.papst@univie.ac.at wrote:
> when starting a hot standby database insstance with
> `systemctl start postgresql',
> anything works perfect: WAL files are beeing applied, r/o connections are
> able to query the database, but after 90 seconds (systemd
> DefaultTimeoutStartSec) postgresql is beeing shut down:
This is all quite plausible, but it depends on how your systemd service
for postgresql is configured. So please post that if you want us to
analyze it.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start
2016-09-09 10:50 BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start andreas.papst@univie.ac.at
2016-09-13 15:52 ` Re: BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2016-09-14 07:12 ` Andreas Papst <andreas.papst@univie.ac.at>
2016-09-15 00:19 ` Re: BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
0 siblings, 1 reply; 5+ messages in thread
From: Andreas Papst @ 2016-09-14 07:12 UTC (permalink / raw)
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-bugs
Hey Peter,
thank you for your offer.
# cat /etc/debian_version
8.5
# dpkg -l | grep postgres
-------------------------------------------------------------------
ii pgdg-keyring 2014.1 all
keyring for apt.postgresql.org
ii postgresql-9.4 9.4.9-1.pgdg80+1
amd64 object-relational SQL database, version 9.4 server
ii postgresql-9.5 9.5.4-1.pgdg80+1
amd64 object-relational SQL database, version 9.5 server
ii postgresql-client-9.4 9.4.9-1.pgdg80+1
amd64 front-end programs for PostgreSQL 9.4
ii postgresql-client-9.5 9.5.4-1.pgdg80+1
amd64 front-end programs for PostgreSQL 9.5
ii postgresql-client-common 175.pgdg80+1 all
manager for multiple PostgreSQL client versions
ii postgresql-common 175.pgdg80+1 all
PostgreSQL database-cluster manager
ii postgresql-contrib-9.4 9.4.9-1.pgdg80+1
amd64 additional facilities for PostgreSQL
ii postgresql-contrib-9.5 9.5.4-1.pgdg80+1
amd64 additional facilities for PostgreSQL
-------------------------------------------------------------------
attached files:
systemctl cat postgresql.service
systemctl cat postgresql@9.4-at_run.service
/etc/postgresql/9.4/at_run/postgresql.conf
/etc/postgresql/9.4/at_run/start.conf
/usr/bin/pg_ctlcluster
Best regards
Andreas
On 09/13/2016 05:52 PM, Peter Eisentraut wrote:
> On 9/9/16 6:50 AM, andreas.papst@univie.ac.at wrote:
>> when starting a hot standby database insstance with
>> `systemctl start postgresql',
>> anything works perfect: WAL files are beeing applied, r/o connections are
>> able to query the database, but after 90 seconds (systemd
>> DefaultTimeoutStartSec) postgresql is beeing shut down:
>
> This is all quite plausible, but it depends on how your systemd service
> for postgresql is configured. So please post that if you want us to
> analyze it.
>
--
________________________________________________________________________
Andreas Papst |
Vienna University Computer Center | E-Mail: andreas.papst@univie.ac.at
Universitaetsstrasse 7 | Phone: +43 1 4277 / 140 36
A-1010 Vienna, Austria, Europe | Fax.: +43 1 4277 / 8 140 36
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
pg_ctlcluster (text/plain, 21.3K) download
#!/usr/bin/perl -wT
# multiversion/cluster aware pg_ctl wrapper; this also supplies the correct
# configuration parameters to 'start', and makes sure that postgres really
# stops on 'stop'.
#
# (C) 2005-2009 Martin Pitt <mpitt@debian.org>
# (C) 2009 Cyril Bouthors <cyril@bouthors.org>
# (C) 2013-2015 Christoph Berg <myon@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
use strict;
use warnings;
use Getopt::Long;
use POSIX qw/setsid dup2 setlocale LC_ALL :sys_wait_h/;
use PgCommon;
use Fcntl 'SEEK_SET';
my ($version, $cluster, $pg_ctl, $force);
my (@postmaster_auxoptions, @pg_ctl_opts_from_cli);
my (%postgresql_conf, %info);
my $mode = 'smart'; # default shutdown mode
my $foreground = 0; # don't daemonize, use postgres instead of pg_ctl
my $stdlog = 0; # when run in foreground, still log to the default logfile
# Check for known broken configurations of this cluster
sub check_valid_config {
my %postgresql_conf = read_cluster_conf_file $version, $cluster,
'postgresql.conf';
my $log_statement_stats = config_bool $postgresql_conf{'log_statement_stats'};
my $log_parser_stats = config_bool $postgresql_conf{'log_parser_stats'};
my $log_planner_stats = config_bool $postgresql_conf{'log_planner_stats'};
my $log_executor_stats = config_bool $postgresql_conf{'log_executor_stats'};
# statement and other statistics are mutually exclusive
if ($log_statement_stats && ($log_parser_stats || $log_planner_stats ||
$log_executor_stats)) {
error ('invalid postgresql.conf: log_statement_stats and the other log_*_stats options are mutually exclusive');
}
}
# 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 postgres.
sub start_check_pid_file {
my $pidfile = $info{'pgdata'}.'/postmaster.pid';
if (PgCommon::check_pidfile_running $pidfile) {
print "Cluster is already running.\n";
exit 2;
}
# Remove invalid or stale PID file
if (-e $pidfile) {
unlink $pidfile;
print "Removed stale pid file.\n";
}
}
# Check if a pid file is not present or it is invalid. If so, clean up/abort.
sub stop_check_pid_file {
my $pidfile = $info{'pgdata'}.'/postmaster.pid';
my $pid = read_pidfile $pidfile;
return if (defined $pid && PgCommon::check_pidfile_running $pidfile);
if ($info{'running'}) {
error 'pid file is invalid, please manually kill the stale server process.';
}
# Remove invalid or stale PID file
if (-e $pidfile) {
unlink $pidfile;
print "Removed stale pid file.\n";
}
print "Cluster is not running.\n";
exit 2;
}
# check if a cluster reliably connects or fails
# Arguments: <version> <cluster> <port> <socket dir>
sub cluster_port_ready {
my ($v, $c, $p, $sd) = @_;
my $psql = get_program_path 'psql', $v;
error 'cluster_port_ready: could not find psql binary' unless $psql;
my $n = 0;
my $result = 0;
# probe until we get three successful or failed connections in a row
$ENV{'PGPASSWORD'} = 'foo'; # prevent hangs if superuser cannot connect withouth password
my $out;
while ($n < ($result ? 10 : 3)) {
select undef, undef, undef, 0.5;
$out = `$psql -h '$sd' --port $p -l 2>&1 >/dev/null`;
if ($? == $result) {
$n++;
} else {
$n = 0;
}
$result = $?;
}
if ($out =~ 'FATAL:') {
print STDERR "Warning: connection to the database failed, disabling startup checks:\n$out\n";
return cluster_port_running $v, $c, $p;
}
return !$result;
}
sub start {
my $cdir = $info{'configdir'};
check_valid_config;
start_check_pid_file;
# check conflicting port
if (cluster_port_running $version, $cluster, $info{'port'}) {
my $sockdir = get_cluster_socketdir $version, $cluster;
error("Port conflict: another instance is already running on $sockdir with port $info{'port'}");
}
# prepare environment (empty except for content of 'environment', and LANG)
%ENV = read_cluster_conf_file $version, $cluster, 'environment';
# set LANG so non-ascii chars in the server log are not replaced by '?' (affected are non-session contexts)
unless (exists $ENV{LANG}) {
my $lc_messages = PgCommon::get_conf_value $version, $cluster, 'postgresql.conf', 'lc_messages';
$ENV{LANG} = $lc_messages if $lc_messages;
}
# 9.5 configures OOM killer using env vars
if ($version >= 9.5) {
$ENV{PG_OOM_ADJUST_FILE} = "/proc/self/oom_score_adj" unless (exists $ENV{PG_OOM_ADJUST_FILE});
# PG_OOM_ADJUST_VALUE defaults to 0, but can be overridden here
}
my $postmaster_opts = '';
my $usd = $version >= 9.3 ? 'unix_socket_directories' : 'unix_socket_directory';
if (!(PgCommon::get_conf_value $version, $cluster, 'postgresql.conf', $usd)) {
$postmaster_opts .= "-c $usd=\"$info{'socketdir'}\"";
}
$postmaster_opts .= " -c config_file=\"$cdir/postgresql.conf\"";
if (!(PgCommon::get_conf_value $version, $cluster, 'postgresql.conf', 'hba_file')) {
$postmaster_opts .= " -c hba_file=\"$cdir/pg_hba.conf\"";
}
if (!(PgCommon::get_conf_value $version, $cluster, 'postgresql.conf', 'ident_file')) {
$postmaster_opts .= " -c ident_file=\"$cdir/pg_ident.conf\"";
}
if ((-d '/var/run/postgresql') && !defined (PgCommon::get_conf_value $version, $cluster, 'postgresql.conf', 'external_pid_file')) {
# check whether /var/run/postgresql/ is writeable as the cluster owner
my $vrp_writable;
if ($> == 0) {
change_ugid $info{'owneruid'}, $info{'ownergid'};
$vrp_writable = -w '/var/run/postgresql';
$< = $> = 0;
$( = $) = 0;
} else {
$vrp_writable = -w '/var/run/postgresql';
}
if ($vrp_writable) {
$postmaster_opts .= " -c external_pid_file=\"/var/run/postgresql/$version-$cluster.pid\"";
}
}
$postmaster_opts .= ' ' . (join ' ', @postmaster_auxoptions);
($postmaster_opts) = $postmaster_opts =~ /(.*)/; # untaint
if ($foreground) {
if ($stdlog and $info{'logfile'}) {
dup2(POSIX::open($info{logfile}, POSIX::O_WRONLY|POSIX::O_APPEND), 1);
dup2(POSIX::open($info{logfile}, POSIX::O_WRONLY|POSIX::O_APPEND), 2);
}
my $postgres = get_program_path 'postgres', $version;
exec '/bin/sh', '-c', "exec $postgres $postmaster_opts" or
error "Executing $postgres failed: $!"
}
# only supply or default logfile path when none is given explicitly in
# postgresql.conf
my @options = ($pg_ctl, 'start', '-D', $info{'pgdata'});
my $logsize = 0;
if ($info{'logfile'}) {
push @options, ('-l', $info{'logfile'});
# remember current size of the log
$logsize = (stat $info{'logfile'})[7] || 0; # ignore stat errors
}
push @options, @pg_ctl_opts_from_cli if @pg_ctl_opts_from_cli;
my %pg_ctl_opts_from_file = read_cluster_conf_file $version, $cluster, 'pg_ctl.conf';
push @options, split(' ', $pg_ctl_opts_from_file{'pg_ctl_options'})
if defined $pg_ctl_opts_from_file{'pg_ctl_options'} and $pg_ctl_opts_from_file{'pg_ctl_options'} ne '';
push @options, ('-s', '-o', $postmaster_opts);
if (fork) {
wait;
error "could not exec $pg_ctl @options: $!" if $?;
} else {
setsid or error "could not start session: $!";
# without this, you'll get zombies on startup
dup2(POSIX::open('/dev/null', POSIX::O_WRONLY), 1);
dup2(POSIX::open('/dev/null', POSIX::O_WRONLY), 2);
exec $pg_ctl @options or error "could not exec $pg_ctl @options: $!";
}
# wait a bit until the socket exists
my $success = 0;
my $currlogsize = 0;
my $pidfile = $info{'pgdata'}.'/postmaster.pid';
for (my $attempt = 0; $attempt < 60; $attempt++) {
select (undef, undef, undef, 0.5);
$currlogsize = (stat $info{'logfile'})[7] if $info{'logfile'} && -r $info{'logfile'};
if (cluster_port_running $version, $cluster, $info{'port'}) {
$success = 1;
last;
}
# if postgres wrote something, but the process does not exist any
# more, there must be a problem and we can stop immediately
last if ($currlogsize > $logsize && !PgCommon::check_pidfile_running $pidfile);
}
# OK, the server runs, now wait until it stabilized
if ($success) {
$success = cluster_port_ready $version, $cluster, $info{'port'}, $info{'socketdir'};
}
if (!$success) {
if ($currlogsize) {
print STDERR "The PostgreSQL server failed to start. Please check the log output:\n";
open LOG, $info{'logfile'} or
error "Could not open log file " . $info{'logfile'};
seek LOG, $logsize, SEEK_SET;
print STDERR $_ while <LOG>;
} else {
print STDERR "The PostgreSQL server failed to start. Please check the log output.\n";
}
exit 1;
}
return 0;
}
sub stop {
stop_check_pid_file;
my $result = 1;
if ($force) {
if (!fork()) {
close STDOUT;
exec $pg_ctl, '-D', $info{'pgdata'}, '-s', '-w', '-m', 'fast', @pg_ctl_opts_from_cli, 'stop';
} else {
wait;
$result = $? >> 8;
}
# try harder if "fast" mode does not work
if (-f $info{'pgdata'}.'/postmaster.pid') {
print "(does not shutdown gracefully, now stopping immediately)\n";
$result = system $pg_ctl, '-D', $info{'pgdata'}, '-s', '-w', '-m', 'immediate', @pg_ctl_opts_from_cli, 'stop';
}
# if that still not helps, use the big hammer
if (-f $info{'pgdata'}.'/postmaster.pid') {
print "(does not shutdown, killing the process)";
my $pid = read_pidfile ($info{'pgdata'}.'/postmaster.pid');
kill (9, $pid) if $pid;
$result = 0;
}
} else {
if (!fork()) {
close STDOUT;
exec $pg_ctl, '-D', $info{'pgdata'}, '-s', '-w', '-m', $mode, @pg_ctl_opts_from_cli, 'stop';
} else {
wait;
$result = $? >> 8;
}
}
# external_pid_file files are currently not removed by postgres itself
if ($result == 0) {
unlink "/var/run/postgresql/$version-$cluster.pid";
}
return $result;
}
sub restart {
my $result;
if ($info{'running'}) {
$result = stop;
return $result if $result;
}
return start;
}
sub reload {
exec $pg_ctl, '-D', $info{'pgdata'}, '-s', @pg_ctl_opts_from_cli, 'reload';
}
sub status {
exec $pg_ctl, '-D', $info{'pgdata'}, 'status';
}
sub promote {
exec $pg_ctl, '-D', $info{'pgdata'}, '-s', @pg_ctl_opts_from_cli, 'promote';
}
#
# main
#
my ($skip_systemctl_redirect, $bindir);
exit 1 unless GetOptions ('o|options=s' => \@postmaster_auxoptions,
'f|force' => \$force,
'm|mode=s' => \$mode,
'foreground' => \$foreground,
'skip-systemctl-redirect' => \$skip_systemctl_redirect,
'stdlog' => \$stdlog,
'bindir=s' => \$bindir,
);
if ($mode =~ /^(s(mart)?|f(ast)?|i(mmediate)?)$/) {
$mode = $1; # untaint
} else {
print "Invalid -m mode, valid are: smart fast immediate\n";
exit 1;
}
($bindir) = $bindir =~ /^(\/.*)$/ if $bindir; # untaint
# accept both "version cluster action" and "version[-/]cluster action"
if (@ARGV < 2 or (@ARGV < 3 and $ARGV[0] !~ m![-/]!)) {
print "Usage: $0 <version> <cluster> <action>\n";
exit 1;
}
$version = shift @ARGV;
if ($version =~ m!^(\d+\.\d)[-/](.+)!) {
($version, $cluster) = ($1, $2);
} else {
$cluster = shift @ARGV;
}
my $action = shift @ARGV;
@pg_ctl_opts_from_cli=();
foreach my $argv (@ARGV) {
push @pg_ctl_opts_from_cli, $argv =~ /(.*)/; # untaint
}
($version) = $version =~ /^(\d+\.\d+)$/; # untaint
($cluster) = $cluster =~ /^([^'"\s]+)$/; # untaint
error 'specified cluster does not exist' unless $version && $cluster && cluster_exists $version, $cluster;
%info = cluster_info ($version, $cluster);
unless ($action eq 'stop') {
# check if cluster is disabled in start.conf
error 'Cluster is disabled' if $info{'start'} eq 'disabled';
}
# untaint environment
$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
unless (-d $info{'pgdata'} && defined $info{'owneruid'}) {
error $info{'pgdata'} . ' is not accessible or does not exist';
}
# check that owner uid/gid is valid
unless (getpwuid $info{'owneruid'}) {
error 'The cluster is owned by user id '.$info{'owneruid'}.' which does not exist'
}
unless (getgrgid $info{'ownergid'}) {
error 'The cluster is owned by group id '.$info{'ownergid'}.' which does not exist'
}
# owneruid and configuid need to match, unless configuid is root
if (($< == 0 or $> == 0) and $info{'configuid'} != 0 and
$info{'configuid'} != $info{'owneruid'}) {
my $configowner = (getpwuid $info{'configuid'})[0] || "(unknown)";
my $dataowner = (getpwuid $info{'owneruid'})[0];
error "Config owner ($configowner:$info{configuid}) and data owner ($dataowner:$info{owneruid}) do not match, and config owner is not root";
}
# redirect the request through systemd
if (not $skip_systemctl_redirect and getppid() != 1 and # not run from init
-d '/run/systemd/system' and not exists $ENV{_SYSTEMCTL_SKIP_REDIRECT} and # systemd is running
not exists $ENV{'PG_CLUSTER_CONF_ROOT'} and # not handling user clusters
$action =~ /^(start|stop|restart)$/ # redirect only these actions
) {
$action = $1; # untaint
system 'systemctl', 'is-active', '-q', "postgresql\@$version-$cluster";
my $unit_active = $? == 0;
# if extra options are given, proceed with pg_ctlcluster with a warning
if (@postmaster_auxoptions != 0 or @pg_ctl_opts_from_cli != 0 or $bindir) { # extra options given
print "Notice: extra pg_ctl/postgres options given, bypassing systemctl for $action operation\n" if (-t 1);
# if we are root, redirect to systemctl unless stopping a cluster running outside systemd
} elsif ($> == 0) {
if ($action eq 'stop' and not $unit_active) {
# proceed with pg_ctlcluster
} else {
print "Redirecting $action request to systemctl\n" if (-t 1);
system 'systemctl', $action, "postgresql\@$version-$cluster";
exit $? >> 8;
# program end
}
# as non-root, raise an error on restarting a cluster running from systemd
} elsif ($action eq 'restart' and $unit_active) {
error "cluster is running from systemd, can only restart it as root. Try instead:\n sudo systemctl $action postgresql\@$version-$cluster";
# program end
# otherwise just raise a warning on start and restart as non-root
} elsif (-t 1) {
if ($action =~ /start/) {
print "Warning: the cluster will not be running as a systemd service. Consider using systemctl:\n";
} elsif ($unit_active) { # on stop, warn when running from systemd
print "Warning: stopping the cluster using pg_ctlcluster will mark the systemd unit as failed. Consider using systemctl:\n";
}
print " sudo systemctl $action postgresql\@$version-$cluster\n";
}
}
# recreate missing standard log dir
if ($> == 0 && ! -e '/var/log/postgresql' &&
$info{'logfile'} =~ m!^/var/log/postgresql!) {
system 'install', '-d', '-m', '1775', '-o', 'root', '-g', 'postgres', '/var/log/postgresql';
}
# recreate missing log file
if ($action ne 'stop' && $info{'logfile'} && ! -e $info{'logfile'}) {
open L, '>', $info{'logfile'} or
error 'Could not create log file ' . $info{'logfile'};
chmod 0640, $info{'logfile'};
my $g;
if ($info{'owneruid'} < 500) {
$g = (getgrnam 'adm')[2];
} else {
$g = $info{'ownergid'};
}
chown $info{'owneruid'}, $g, $info{'logfile'};
close L;
}
# recreate /var/run/postgresql
if ($action ne 'stop' && ! -d $info{'socketdir'}) {
system 'install', '-d', '-m', 2775,
'-o', $info{'owneruid'}, '-g', $info{'ownergid'}, $info{'socketdir'};
}
# recreate stats_temp_directory
if ($action ne 'stop' && $info{'statstempdir'} && ! -d $info{'statstempdir'}) {
system 'install', '-d', '-m', 750,
'-o', $info{'owneruid'}, '-g', $info{'ownergid'}, $info{'statstempdir'};
}
if ($> == 0) {
# have postgres start with increased OOM killer protection; 9.0 and
# later has builtin support for resetting the adjustment of child processes
if ($action eq 'start' and $version >= '9.0' and not $PgCommon::rpm) {
if (-w '/proc/self/oom_score_adj') {
open F, '>/proc/self/oom_score_adj';
print F "-900\n";
close F;
}
}
chdir ('/var/lib/postgresql');
change_ugid $info{'owneruid'}, $info{'ownergid'};
}
# we are running as the cluster owner now
if( $> != $info{'owneruid'} ) {
error 'You must run this program as the cluster owner ('.
(getpwuid $info{'owneruid'})[0].') or root';
}
$pg_ctl = $bindir ? "$bindir/pg_ctl" : get_program_path ('pg_ctl', $version);
if ($action =~ /^(start|stop|restart|reload|status|promote)$/) {
no strict 'refs';
exit &$action;
} else {
error 'Invalid action (must be one of: start stop restart reload status promote)';
}
__END__
=head1 NAME
pg_ctlcluster - start/stop/restart/reload a PostgreSQL cluster
=head1 SYNOPSIS
B<pg_ctlcluster> [I<options>] I<cluster-version> I<cluster-name> I<action> B<--> [I<pg_ctl options>]
where I<action> = B<start>|B<stop>|B<restart>|B<reload>|B<status>|B<promote>
=head1 DESCRIPTION
This program controls the B<postgres> server for a particular cluster. It
essentially wraps the L<pg_ctl(1)> command. It determines the cluster version
and data path and calls the right version of B<pg_ctl> with appropriate
configuration parameters and paths.
You have to start this program as the user who owns the database cluster or as
root.
To ease integration with B<systemd> operation, the alternative syntax
"B<pg_ctlcluster> I<version>B<->I<cluster> I<action>" is also supported.
=head1 ACTIONS
=over 4
=item B<start>
A log file for this specific cluster is created if it does not exist yet (by
default,
C</var/log/postgresql/postgresql->I<cluster-version>C<->I<cluster-name>C<.log>),
and a PostreSQL server process (L<postgres(1)>) is started on it. Exits with
0 on success, with 2 if the server is already running, and with 1 on other
failure conditions.
=item B<stop>
Stops the L<postgres(1)> server of the given cluster. By default, "smart"
shutdown mode is used, which waits until all clients disconnected.
=item B<restart>
Stops the server if it is running and starts it (again).
=item B<reload>
Causes the configuration files to be re-read without a full shutdown of the
server.
=item B<status>
Checks whether a server is running. If it is, the PID and the command line
options that were used to invoke it are displayed.
=item B<promote>
Commands a running standby server to exit recovery and begin read-write
operations.
=back
=head1 OPTIONS
=over 4
=item B<-f>|B<--force>
For B<stop> and B<restart>, the "fast" mode is used which rolls back all active
transactions, disconnects clients immediately and thus shuts down cleanly. If
that does not work, shutdown is attempted again in "immediate" mode, which can
leave the cluster in an inconsistent state and thus will lead to a recovery run
at the next start. If this still does not help, the B<postgres> process is
killed. Exits with 0 on success, with 2 if the server is not running, and with
1 on other failure conditions. This mode should only be used when the machine
is about to be shut down.
=item B<-m>|B<--mode> [B<smart>|B<fast>|B<immediate>]
Shutdown mode to use for B<stop> and B<restart> actions, default is B<smart>.
See pg_ctl(1) for documentation.
=item B<--foreground>
Start B<postgres> in foreground, without daemonizing via B<pg_ctl>.
=item B<--stdlog>
When B<--foreground> is in use, redirect stderr to the standard logfile in
C</var/log/postgresql/>. (Default when not run in foreground.)
=item B<--bindir> I<directory>
Path to B<pg_ctl>. (Default is C</usr/lib/postgresql/>I<version>C</bin>.)
=item B<-o>|B<--options> I<option>
Pass given I<option> as command line option to the C<postgres> process. It is
possible to specify B<-o> multiple times. See L<postgres(1)> for a
description of valid options.
=item I<pg_ctl options>
Pass given I<pg_ctl options> as command line options to B<pg_ctl>. See L<pg_ctl(1)>
for a description of valid options.
=back
=head1 FILES
=over 4
=item C</etc/postgresql/>I<cluster-version>C</>I<cluster-name>C</pg_ctl.conf>
This configuration file contains cluster specific options to be passed to
L<pg_ctl(1)>.
=item C</etc/postgresql/>I<cluster-version>C</>I<cluster-name>C</start.conf>
This configuration file controls the start/stop behavior of the cluster. See
section "STARTUP CONTROL" in L<pg_createcluster(8)> for details.
=back
=head1 BUGS
Changing the port number on startup using B<-o -p> will not work as it breaks
the checks for running clusters.
=head1 SEE ALSO
L<pg_createcluster(8)>, L<pg_ctl(1)>, L<pg_wrapper(1)>, L<pg_lsclusters(1)>,
L<postgres(1)>
=head1 AUTHOR
Martin Pitt L<E<lt>mpitt@debian.orgE<gt>>
postgresql.conf (text/plain, 1.4K) download
#
# file is under control of puppet
# any update here will be reverted
#
# -----------------------------
# PostgreSQL configuration file
# -----------------------------
data_directory = '/pgdata/at_run/db'
hba_file = '/etc/postgresql/9.4/at_run/pg_hba.conf'
ident_file = '/pgdata/at_run/db/pg_ident.conf'
external_pid_file = '/pgcontrol/var/postgres.pid'
listen_addresses = '*'
port = 5432
max_connections = 2000
unix_socket_directories = '/pgcontrol/var'
shared_buffers = 1GB
work_mem = 512MB
maintenance_work_mem = 512MB
temp_file_limit = 2097152
wal_level = hot_standby
checkpoint_segments = 3
archive_mode = on
archive_command = 'true'
archive_timeout = 300
max_wal_senders = 3
wal_keep_segments = 30
hot_standby = on
hot_standby_feedback = on
effective_cache_size = 128MB
log_destination = 'stderr'
logging_collector = on
log_directory = '/pgcontrol/log'
syslog_facility = 'LOCAL3'
syslog_ident = 'postgres'
log_min_duration_statement = -1 # -1 is disabled
autovacuum_max_workers = 3
log_checkpoints = off
log_connections = on
log_disconnections = on
log_line_prefix = '%m %u@%d (%h/%p) '
log_timezone = 'Europe/Vienna'
track_counts = on
autovacuum = on # Enable autovacuum subprocess? 'on'
log_autovacuum_min_duration = 0 # 0 logs all actions
datestyle = 'iso, mdy'
timezone = 'Europe/Vienna'
lc_messages = 'en_US.UTF-8'
lc_monetary = 'en_US.UTF-8'
lc_numeric = 'en_US.UTF-8'
lc_time = 'en_US.UTF-8'
postgresql.service (text/plain, 379B) download
# /lib/systemd/system/postgresql.service
# systemd service for managing all PostgreSQL clusters on the system. This
# service is actually a systemd target, but we are using a service since
# targets cannot be reloaded.
[Unit]
Description=PostgreSQL RDBMS
[Service]
Type=oneshot
ExecStart=/bin/true
ExecReload=/bin/true
RemainAfterExit=on
[Install]
WantedBy=multi-user.target
postgresql@9.4-at_run.service (text/plain, 1.4K) download
# /lib/systemd/system/postgresql@.service
# systemd service template for PostgreSQL clusters. The actual instances will
# be called "postgresql@version-cluster", e.g. "postgresql@9.3-main". The
# variable %i expands to "version-cluster", %I expands to "version/cluster".
# (%I breaks for cluster names containing dashes.)
[Unit]
Description=PostgreSQL Cluster %i
ConditionPathExists=/etc/postgresql/%I/postgresql.conf
PartOf=postgresql.service
ReloadPropagatedFrom=postgresql.service
Before=postgresql.service
[Service]
Type=forking
# @: use "postgresql@%i" as process name
TimeoutStartSec=0
ExecStart=@/usr/bin/pg_ctlcluster postgresql@%i --skip-systemctl-redirect %i sta
ExecStop=/usr/bin/pg_ctlcluster --skip-systemctl-redirect -m fast %i stop
ExecReload=/usr/bin/pg_ctlcluster --skip-systemctl-redirect %i reload
PIDFile=/var/run/postgresql/%i.pid
SyslogIdentifier=postgresql@%i
# prevent OOM killer from choosing the postmaster (individual backends will
# reset the score to 0)
OOMScoreAdjust=-900
# restarting automatically will prevent "pg_ctlcluster ... stop" from working,
# so we disable it here. Also, the postmaster will restart by itself on most
# problems anyway, so it is questionable if one wants to enable external
# automatic restarts.
#Restart=on-failure
# (This should make pg_ctlcluster stop work, but doesn't:)
#RestartPreventExitStatus=SIGINT SIGTERM
[Install]
WantedBy=multi-user.target
start.conf (text/plain, 6B) download
auto
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start
2016-09-09 10:50 BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start andreas.papst@univie.ac.at
2016-09-13 15:52 ` Re: BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-14 07:12 ` Re: BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start Andreas Papst <andreas.papst@univie.ac.at>
@ 2016-09-15 00:19 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-15 06:28 ` Re: BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start Andreas Papst <andreas.papst@univie.ac.at>
0 siblings, 1 reply; 5+ messages in thread
From: Peter Eisentraut @ 2016-09-15 00:19 UTC (permalink / raw)
To: Andreas Papst <andreas.papst@univie.ac.at>; +Cc: pgsql-bugs
Something unusual is going on. Try running the commands in the unit
file by hand and see whether they succeed or print additional
diagnostics. Check the systemd logs, if any. The reason the process
ends up getting killed is that systemd thinks it has not started
successfully.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start
2016-09-09 10:50 BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start andreas.papst@univie.ac.at
2016-09-13 15:52 ` Re: BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-14 07:12 ` Re: BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start Andreas Papst <andreas.papst@univie.ac.at>
2016-09-15 00:19 ` Re: BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2016-09-15 06:28 ` Andreas Papst <andreas.papst@univie.ac.at>
0 siblings, 0 replies; 5+ messages in thread
From: Andreas Papst @ 2016-09-15 06:28 UTC (permalink / raw)
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-bugs
Hello,
On 09/15/2016 02:19 AM, Peter Eisentraut wrote:
> Something unusual is going on. Try running the commands in the unit
> file by hand and see whether they succeed or print additional
> diagnostics. Check the systemd logs, if any. The reason the process
> ends up getting killed is that systemd thinks it has not started
> successfully.
>
yeah, when systemd's startup process is running into it's timeout
it terminates postgres process. If I change the timeout threshold
to unlimited, postgres operates for ever.
And as I wrote, when I send Postgres a signal, i.e. `systemctl reload
postgresql´, postgres process detaches, the blocked startup script
is freed and returns success to systemd.
No more logs are available.
Thanks
Andreas
--
________________________________________________________________________
Andreas Papst |
Vienna University Computer Center | E-Mail: andreas.papst@univie.ac.at
Universitaetsstrasse 7 | Phone: +43 1 4277 / 140 36
A-1010 Vienna, Austria, Europe | Fax.: +43 1 4277 / 8 140 36
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2016-09-15 06:28 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-09-09 10:50 BUG #14320: systemd terminates postgresql hot standby instance 90 seconds after start andreas.papst@univie.ac.at
2016-09-13 15:52 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-14 07:12 ` Andreas Papst <andreas.papst@univie.ac.at>
2016-09-15 00:19 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-15 06:28 ` Andreas Papst <andreas.papst@univie.ac.at>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox