pg.ddx.io  pgsql-pkg-debian@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #8177: initscript should create /var/run/postgresql
7+ messages / 5 participants
[nested] [flat]

* BUG #8177: initscript should create /var/run/postgresql
@ 2013-05-27 09:27  stronny@celestia.ru
  0 siblings, 1 reply; 7+ messages in thread

From: stronny@celestia.ru @ 2013-05-27 09:27 UTC (permalink / raw)
  To: pgsql-bugs@postgresql.org

The following bug has been logged on the website:

Bug reference:      8177
Logged by:          stronny
Email address:      stronny@celestia.ru
PostgreSQL version: 9.2.4
Operating system:   wheezy
Description:        

When installed from apt.postgresql.org Postgres fails to start on system
boot.

Wheezy changed /var/run to become memory-based so initscript should create
/var/run/postgresql if necessary.



-- 
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] 7+ messages in thread

* Re: [BUGS] BUG #8177: initscript should create /var/run/postgresql
@ 2013-05-30 02:22  Peter Eisentraut <peter_e@gmx.net>
  parent: stronny@celestia.ru
  0 siblings, 1 reply; 7+ messages in thread

From: Peter Eisentraut @ 2013-05-30 02:22 UTC (permalink / raw)
  To: stronny@celestia.ru; +Cc: pgsql-pkg-debian

On Mon, 2013-05-27 at 09:27 +0000, stronny@celestia.ru wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      8177
> Logged by:          stronny
> Email address:      stronny@celestia.ru
> PostgreSQL version: 9.2.4
> Operating system:   wheezy
> Description:        
> 
> When installed from apt.postgresql.org Postgres fails to start on system
> boot.
> 
> Wheezy changed /var/run to become memory-based so initscript should create
> /var/run/postgresql if necessary.

pgsql-pkg-debian@postgresql.org is where the people who know about this
hang out.




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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [BUGS] BUG #8177: initscript should create /var/run/postgresql
@ 2013-05-30 02:58  Christoph Berg <myon@debian.org>
  parent: Peter Eisentraut <peter_e@gmx.net>
  0 siblings, 2 replies; 7+ messages in thread

From: Christoph Berg @ 2013-05-30 02:58 UTC (permalink / raw)
  To: Peter Eisentraut <peter_e@gmx.net>; +Cc: stronny@celestia.ru; pgsql-pkg-debian

On Mon, 2013-05-27 at 09:27 +0000, stronny@celestia.ru wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      8177
> Logged by:          stronny
> Email address:      stronny@celestia.ru
> PostgreSQL version: 9.2.4
> Operating system:   wheezy
> Description:        
> 
> When installed from apt.postgresql.org Postgres fails to start on system
> boot.
> 
> Wheezy changed /var/run to become memory-based so initscript should create
> /var/run/postgresql if necessary.

start() {
    # create socket directory
    if [ -d /var/run/postgresql ]; then
        chmod 2775 /var/run/postgresql
    else
        install -d -m 2775 -o postgres -g postgres /var/run/postgresql
    fi

    do_ctl_all start "$1" "Starting PostgreSQL $1 database server"
}

We create the directory, what specifically doesn't work for you?

Christoph
-- 
cb@df7cb.de | http://www.df7cb.de/


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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [BUGS] BUG #8177: initscript should create /var/run/postgresql
@ 2013-05-30 07:29  stronny red <stronny@celestia.ru>
  parent: Christoph Berg <myon@debian.org>
  1 sibling, 1 reply; 7+ messages in thread

From: stronny red @ 2013-05-30 07:29 UTC (permalink / raw)
  To: Christoph Berg <myon@debian.org>; Peter Eisentraut <peter_e@gmx.net>; pgsql-pkg-debian

I was able to reproduce the problem.

Package versions
-----------------
ii  postgresql-9.2                      9.2.4-1.pgdg60+1
object-relational SQL database, version 9.2 server
ii  postgresql-common                   142.pgdg60+1
PostgreSQL database-cluster manager

The failure
-----------------
# /etc/init.d/postgresql stop
# rm -rf /var/run/postgresql
# /etc/init.d/postgresql start
Error: Cannot stat /var/run/postgresql
No PostgreSQL clusters exist; see "man pg_createcluster" ... (warning).

The config file
-----------------
# ls -lA /etc/postgresql/9.2
total 0
lrwxrwxrwx 1 root root 23 May 22 20:36 main -> /var/lib/postgresql/etc
# cat /etc/postgresql/9.2/main/postgresql.conf
data_directory = '/var/lib/postgresql/9.2/main'
hba_file = '/var/lib/postgresql/etc/pg_hba.conf'
external_pid_file = '/var/run/postgresql/9.2-main.pid'
ssl = true
ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem'
ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key'
log_line_prefix = '%t '
log_timezone = 'Europe/Moscow'

listen_addresses = '*'
wal_level = hot_standby
max_wal_senders = 3
wal_keep_segments = 8



On Thu, May 30, 2013 at 6:58 AM, Christoph Berg <myon@debian.org> wrote:

> On Mon, 2013-05-27 at 09:27 +0000, stronny@celestia.ru wrote:
> > The following bug has been logged on the website:
> >
> > Bug reference:      8177
> > Logged by:          stronny
> > Email address:      stronny@celestia.ru
> > PostgreSQL version: 9.2.4
> > Operating system:   wheezy
> > Description:
> >
> > When installed from apt.postgresql.org Postgres fails to start on system
> > boot.
> >
> > Wheezy changed /var/run to become memory-based so initscript should
> create
> > /var/run/postgresql if necessary.
>
> start() {
>     # create socket directory
>     if [ -d /var/run/postgresql ]; then
>         chmod 2775 /var/run/postgresql
>     else
>         install -d -m 2775 -o postgres -g postgres /var/run/postgresql
>     fi
>
>     do_ctl_all start "$1" "Starting PostgreSQL $1 database server"
> }
>
> We create the directory, what specifically doesn't work for you?
>
> Christoph
> --
> cb@df7cb.de | http://www.df7cb.de/
>

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [BUGS] BUG #8177: initscript should create /var/run/postgresql
@ 2013-06-01 04:33  Christoph Berg <myon@debian.org>
  parent: stronny red <stronny@celestia.ru>
  0 siblings, 0 replies; 7+ messages in thread

From: Christoph Berg @ 2013-06-01 04:33 UTC (permalink / raw)
  To: stronny red <stronny@celestia.ru>; +Cc: Peter Eisentraut <peter_e@gmx.net>; pgsql-pkg-debian

Re: stronny red 2013-05-30 <CALOvDf7fpScGUJBai69S3=Mr5wC-Xj5BZEqnV4qQBjOHXcj+Zg@mail.gmail.com>
> I was able to reproduce the problem.
> 
> Package versions
> -----------------
> ii  postgresql-9.2                      9.2.4-1.pgdg60+1
> object-relational SQL database, version 9.2 server
> ii  postgresql-common                   142.pgdg60+1
> PostgreSQL database-cluster manager
> 
> The failure
> -----------------
> # /etc/init.d/postgresql stop
> # rm -rf /var/run/postgresql
> # /etc/init.d/postgresql start
> Error: Cannot stat /var/run/postgresql

Can you try "sh -x /etc/init.d/postgresql start" there and send us the
output?

Here it does:

+ [ -d /var/run/postgresql ]
+ install -d -m 2775 -o postgres -g postgres /var/run/postgresql

> No PostgreSQL clusters exist; see "man pg_createcluster" ... (warning).

Btw, this seems to be the actual problem here.

> The config file
> -----------------
> # ls -lA /etc/postgresql/9.2
> total 0
> lrwxrwxrwx 1 root root 23 May 22 20:36 main -> /var/lib/postgresql/etc

That's a non-standard setup. Could it be the case that this partition
wasn't mounted during your tests, or something like that?

Christoph
-- 
cb@df7cb.de | http://www.df7cb.de/


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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [BUGS] BUG #8177: initscript should create /var/run/postgresql
@ 2014-05-30 17:03  Chris Nehren <cnehren+pgsql-pkg-debian@pobox.com>
  parent: Christoph Berg <myon@debian.org>
  1 sibling, 1 reply; 7+ messages in thread

From: Chris Nehren @ 2014-05-30 17:03 UTC (permalink / raw)
  To: pgsql-pkg-debian

> On Mon, 2013-05-27 at 09:27 +0000, stronny@celestia.ru wrote:
> > The following bug has been logged on the website:
> > 
> > Bug reference:      8177
> > Logged by:          stronny
> > Email address:      stronny@celestia.ru
> > PostgreSQL version: 9.2.4
> > Operating system:   wheezy
> > Description:        
> > 
> > When installed from apt.postgresql.org Postgres fails to start on system
> > boot.
> > 
> > Wheezy changed /var/run to become memory-based so initscript should create
> > /var/run/postgresql if necessary.
> 
> start() {
>     # create socket directory
>     if [ -d /var/run/postgresql ]; then
>         chmod 2775 /var/run/postgresql
>     else
>         install -d -m 2775 -o postgres -g postgres /var/run/postgresql
>     fi
> 
>     do_ctl_all start "$1" "Starting PostgreSQL $1 database server"
> }
> 
> We create the directory, what specifically doesn't work for you?

I've been able to reproduce this as well, and have found the root
cause.  Presently, the init script itself
(/etc/init.d/postgresql) does this:

    start|stop|restart|reload)
        if [ -z "`pg_lsclusters -h`" ]; then
            log_warning_msg 'No PostgreSQL clusters exist; see "man pg_createcluster"'
            exit 0
        fi

pg_lsclusters is a Perl application that gets most of its logic
from PgCommon.pm.  Its entry point into PgCommon.pm (the one we
care about, anyway) is the subroutine &cluster_info.
&cluster_info, at line 575, calls &get_cluster_socketdir.  This
subroutine, at line 360, gets the 'unix_socket_directories' value
from the configuration file. If the value is defined in the
configuration file (the default), it immediately returns that
value to &cluster_info.  This is important.  If the value is
*not* defined, then &get_cluster_socketdir defaults it to
'/var/run/postgresql' and attempts to stat() this directory.  As
'/var/run' is now a tmpfs in Debian, this fails, because no
attempt has been made to create that directory before the stat()
runs.

There are actually two bugs here.  The first is attempting to
stat() a directory that the code has not ensured exists, which is
what this bug is about.  The second, more general, is that the
code makes no attempts at creating or even verifying the
existence of any unix_socket_{directory,directories} before
returning.  I've attached a patch to the init script that ensures
/var/run/postgresql actually exists before the code tries to
stat() it.

The reproduction steps for this bug are as follows:

1. install fresh Debian wheezy machine
2. Add official Postgres mirror to apt, installing the keyring
for same
3. Install the Postgres server
4. Remove any unix_socket_{directory,directories} directive from
/etc/postgresql/9.?/main/postgresql.conf
5. Reboot, observe Postgres startup failure

I've been able to reproduce this 100% of the time with the above
steps.

-- 
Chris Nehren

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [BUGS] BUG #8177: initscript should create /var/run/postgresql
@ 2014-05-30 17:05  Chris Nehren <cnehren+pgsql-pkg-debian@pobox.com>
  parent: Chris Nehren <cnehren+pgsql-pkg-debian@pobox.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Chris Nehren @ 2014-05-30 17:05 UTC (permalink / raw)
  To: pgsql-pkg-debian

It would help if I actually attached the patch.  My apologies.

On Fri, May 30, 2014 at 13:03:16 -0400, Chris Nehren wrote:
> > On Mon, 2013-05-27 at 09:27 +0000, stronny@celestia.ru wrote:
> > > The following bug has been logged on the website:
> > > 
> > > Bug reference:      8177
> > > Logged by:          stronny
> > > Email address:      stronny@celestia.ru
> > > PostgreSQL version: 9.2.4
> > > Operating system:   wheezy
> > > Description:        
> > > 
> > > When installed from apt.postgresql.org Postgres fails to start on system
> > > boot.
> > > 
> > > Wheezy changed /var/run to become memory-based so initscript should create
> > > /var/run/postgresql if necessary.
> > 
> > start() {
> >     # create socket directory
> >     if [ -d /var/run/postgresql ]; then
> >         chmod 2775 /var/run/postgresql
> >     else
> >         install -d -m 2775 -o postgres -g postgres /var/run/postgresql
> >     fi
> > 
> >     do_ctl_all start "$1" "Starting PostgreSQL $1 database server"
> > }
> > 
> > We create the directory, what specifically doesn't work for you?
> 
> I've been able to reproduce this as well, and have found the root
> cause.  Presently, the init script itself
> (/etc/init.d/postgresql) does this:
> 
>     start|stop|restart|reload)
>         if [ -z "`pg_lsclusters -h`" ]; then
>             log_warning_msg 'No PostgreSQL clusters exist; see "man pg_createcluster"'
>             exit 0
>         fi
> 
> pg_lsclusters is a Perl application that gets most of its logic
> from PgCommon.pm.  Its entry point into PgCommon.pm (the one we
> care about, anyway) is the subroutine &cluster_info.
> &cluster_info, at line 575, calls &get_cluster_socketdir.  This
> subroutine, at line 360, gets the 'unix_socket_directories' value
> from the configuration file. If the value is defined in the
> configuration file (the default), it immediately returns that
> value to &cluster_info.  This is important.  If the value is
> *not* defined, then &get_cluster_socketdir defaults it to
> '/var/run/postgresql' and attempts to stat() this directory.  As
> '/var/run' is now a tmpfs in Debian, this fails, because no
> attempt has been made to create that directory before the stat()
> runs.
> 
> There are actually two bugs here.  The first is attempting to
> stat() a directory that the code has not ensured exists, which is
> what this bug is about.  The second, more general, is that the
> code makes no attempts at creating or even verifying the
> existence of any unix_socket_{directory,directories} before
> returning.  I've attached a patch to the init script that ensures
> /var/run/postgresql actually exists before the code tries to
> stat() it.
> 
> The reproduction steps for this bug are as follows:
> 
> 1. install fresh Debian wheezy machine
> 2. Add official Postgres mirror to apt, installing the keyring
> for same
> 3. Install the Postgres server
> 4. Remove any unix_socket_{directory,directories} directive from
> /etc/postgresql/9.?/main/postgresql.conf
> 5. Reboot, observe Postgres startup failure
> 
> I've been able to reproduce this 100% of the time with the above
> steps.
> 
> -- 
> Chris Nehren



-- 
Chris Nehren

Attachments:

postgresql.mkdir.patch (text/x-diff, 872B) download --- /etc/init.d/postgresql 2013-08-02 04:50:43.000000000 -0400 +++ postgresql 2014-05-29 17:33:51.598667808 -0400 @@ -28,6 +28,16 @@ case "$1" in start|stop|restart|reload) + # we need to create the /var/run/postgresql directory as root before + # dropping privileges so that the postgres user can start the database + # later, even in the event of internal server crash at boot. this + # directory needs to exist for postgres to run, and things will fail to + # start if it doesn't exist (see BUG #8177). + if [ -d /var/run/postgresql ]; then + chmod 2775 /var/run/postgresql + else + install -d -m 2775 -o postgres -g postgres /var/run/postgresql + fi if [ -z "`pg_lsclusters -h`" ]; then log_warning_msg 'No PostgreSQL clusters exist; see "man pg_createcluster"' exit 0
^ permalink raw reply [nested|flat] 7+ messages in thread


end of thread, other threads:[~2014-05-30 17:05 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-05-27 09:27 BUG #8177: initscript should create /var/run/postgresql stronny@celestia.ru
2013-05-30 02:22 ` Peter Eisentraut <peter_e@gmx.net>
2013-05-30 02:58   ` Christoph Berg <myon@debian.org>
2013-05-30 07:29     ` stronny red <stronny@celestia.ru>
2013-06-01 04:33       ` Christoph Berg <myon@debian.org>
2014-05-30 17:03     ` Chris Nehren <cnehren+pgsql-pkg-debian@pobox.com>
2014-05-30 17:05       ` Chris Nehren <cnehren+pgsql-pkg-debian@pobox.com>

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