Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XvYcn-0008Iz-VP for pgsql-bugs@arkaria.postgresql.org; Mon, 01 Dec 2014 21:35:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XvYcm-0001vJ-Po for pgsql-bugs@arkaria.postgresql.org; Mon, 01 Dec 2014 21:35:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XvY53-00050m-N9 for pgsql-bugs@postgresql.org; Mon, 01 Dec 2014 21:00:25 +0000 Received: from mx.hswn.dk ([5.9.72.7]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XvY4z-0004hC-Ub for pgsql-bugs@postgresql.org; Mon, 01 Dec 2014 21:00:24 +0000 X-Virus-Scanned: Debian amavisd-new at mx.hswn.dk Received: from [IPv6:2001:16d8:dda8:0:16da:e9ff:feed:d5a7] (osiris.hswn.dk [IPv6:2001:16d8:dda8:0:16da:e9ff:feed:d5a7]) by vmail.hswn.dk (Postfix) with ESMTPSA id 90AD120D27; Mon, 1 Dec 2014 22:00:10 +0100 (CET) Message-ID: <547CD6E3.3070304@hswn.dk> Date: Mon, 01 Dec 2014 22:00:19 +0100 From: =?UTF-8?B?SGVucmlrIFN0w7hybmVy?= Organization: Xymon User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Tom Lane CC: Sandeep Thakkar , "pgsql-bugs@postgresql.org" Subject: Re: BUG #12072: init script creates pid file with wrong owner References: <20141126141924.15506.75024@wrigleys.postgresql.org> <547C1467.2020307@hswn.dk> <11031.1417448475@sss.pgh.pa.us> In-Reply-To: <11031.1417448475@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Tom Lane wrote: > =3D?UTF-8?B?SGVucmlrIFN0w7hybmVy?=3D 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=20 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 --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs