pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Henrik Størner <henrik@hswn.dk>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #12072: init script creates pid file with wrong owner
Date: Mon, 01 Dec 2014 22:00:19 +0100
Message-ID: <547CD6E3.3070304@hswn.dk> (raw)
In-Reply-To: <11031.1417448475@sss.pgh.pa.us>
References: <20141126141924.15506.75024@wrigleys.postgresql.org>
	<CANFyU97+vW3x1c0b=cOy5CwcPAKw-oOqJ7p2hfwv2nNrn=3JoA@mail.gmail.com>
	<547C1467.2020307@hswn.dk>
	<11031.1417448475@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Tom Lane wrote:
> =?UTF-8?B?SGVucmlrIFN0w7hybmVy?= <henrik@hswn.dk> writes:
>> The problem is with the init script installed from the rpm package. From
>> line 161 it performs the server start by doing
> Why is the init script creating such a file at all? Surely it should
> be depending on the one created by the postmaster. However, if there
> is a reason to create a separate pidfile, I don't see the problem
> particularly: the postmaster will neither create nor remove it, so it
> hardly matters what the ownership is. regards, tom lane 
The problem lies in the interaction between a DBA using the pg_ctl
commands, and a system start/stop script which is executed when the
system boots or shuts down.

Consider this scenario:

1) The system boots, Postgres starts up automatically via the init.d
script. Two pid-files now exist - one created by the init.d script in
/var/run, and another in the PGDATA directory. They are identical.

2) DBA tweaks some configuration requiring a restart. Since the DBA
doesn't have root access, he logs into the "postgres" account and runs
"pg_ctl restart". This updates the pid-file in the PGDATA directory, but
not the one in /var/run because a) the postgres user does not have write
access to the file, and b) by default pg_ctl doesn't know about the pid
file in /var/run. So the two pid-files are no longer in sync, only the
PGDATA pid file is valid.

3) The server is shut down or rebooted. During shutdown the init.d
script looks at the pid-file in /var/run, and finds that the pid listed
no longer exists. Therefore it assumes that Postgres isn't running and
doesn't try to shut it down gracefully. It gets a 'kill -TERM' at a late
point in the shutdown proces, which is not optimal.


I suppose the /var/run pid-file is created by the RPM initscript because
the Linux Filesystem Hierarchy Standard dictates that system services
keep a pid-file in /var/run - not buried somewhere deep inside a service
specific directory.

Fixing the permission setting on the /var/run pidfile is only part of
the solution, for it to work completely you must also change
postgres.conf so the extra_pid_file setting (iirc) is set to the
/var/run pidfile. This makes sure that the 'postmaster' process updates
both pid-files - but it still requires that both pid-files are writable
by the "postgres" user.


Regards,
Henrik




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (7+ messages)  latest in thread

Message-ID: <547CD6E3.3070304@hswn.dk>
Permalink:  ../547CD6E3.3070304@hswn.dk/
Also on:    postgresql.org/message-id/547CD6E3.3070304@hswn.dk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: henrik@hswn.dk, tgl@sss.pgh.pa.us, sandeep.thakkar@enterprisedb.com
  Subject: Re: BUG #12072: init script creates pid file with wrong owner
  In-Reply-To: <547CD6E3.3070304@hswn.dk>
  References: <20141126141924.15506.75024@wrigleys.postgresql.org> <CANFyU97+vW3x1c0b=cOy5CwcPAKw-oOqJ7p2hfwv2nNrn=3JoA@mail.gmail.com> <547C1467.2020307@hswn.dk> <11031.1417448475@sss.pgh.pa.us> <547CD6E3.3070304@hswn.dk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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