Re: BUG #12072: init script creates pid file with wrong owner

From: Henrik Størner <henrik(at)hswn(dot)dk>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Sandeep Thakkar <sandeep(dot)thakkar(at)enterprisedb(dot)com>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #12072: init script creates pid file with wrong owner
Date: 2014-12-01 21:00:19
Message-ID: 547CD6E3.3070304@hswn.dk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Tom Lane wrote:
> =?UTF-8?B?SGVucmlrIFN0w7hybmVy?= <henrik(at)hswn(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Devrim Gündüz 2014-12-01 23:32:28 Re: BUG #12072: init script creates pid file with wrong owner
Previous Message Tom Lane 2014-12-01 15:41:15 Re: BUG #12072: init script creates pid file with wrong owner