Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WqQDO-000108-Pw for pgsql-pkg-debian@arkaria.postgresql.org; Fri, 30 May 2014 17:03:35 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WqQDO-0006AZ-0l for pgsql-pkg-debian@arkaria.postgresql.org; Fri, 30 May 2014 17:03:34 +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 1WqQDN-0006AS-2x for pgsql-pkg-debian@postgresql.org; Fri, 30 May 2014 17:03:33 +0000 Received: from smtp.pobox.com ([208.72.237.35]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WqQDG-0001kr-Ow for pgsql-pkg-debian@postgresql.org; Fri, 30 May 2014 17:03:30 +0000 Received: from smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp0.pobox.com (Postfix) with ESMTP id B281F1BDCF for ; Fri, 30 May 2014 13:03:22 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=date:from:to :subject:message-id:mime-version:content-type:in-reply-to; s= sasl; bh=OpXVtMhQCkrD/wvVcJSiKhda2Kg=; b=fg4gDDfn4pniTOP0Pc9BTYa MxlpDchbLAmjJlbzKyA52hiVjVzD9LS58t0e20BUCfJspKCdKUVuaTwlQfbIPwlQ 75K4cbIkvEED1dVyjvoP9gd+BQxyEU27RlSKDOFAiWKnNHv0v0b/BLdOlvRaRaBK 2rsiTSOiNOiqMU+4H5Nw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=date:from:to :subject:message-id:mime-version:content-type:in-reply-to; q= dns; s=sasl; b=cqppo/PtgM7YQRQ3QgNQk22ci4DP41b3iDvwizEIGXYxssFeW whJXqa4Fv2IbTl7fF4ihV0F+1TuS8G7cyoe+ydvEHKFWZdd2dKI+jJe6RseVko4z sK3W3rM3QodyS4vywh82Uvh0nfs6UpxqRUnT8fMUMpTPTn7WitobOap1Ww= Received: from pb-smtp0. (unknown [127.0.0.1]) by pb-smtp0.pobox.com (Postfix) with ESMTP id AABB01BDCE for ; Fri, 30 May 2014 13:03:22 -0400 (EDT) Received: from localhost (unknown [75.112.235.167]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-smtp0.pobox.com (Postfix) with ESMTPSA id 6D52A1BDC8 for ; Fri, 30 May 2014 13:03:18 -0400 (EDT) Date: Fri, 30 May 2014 13:03:16 -0400 From: Chris Nehren To: pgsql-pkg-debian@postgresql.org Subject: Re: [BUGS] BUG #8177: initscript should create /var/run/postgresql Message-ID: <20140530170316.GC13595@behemoth> Mail-Followup-To: pgsql-pkg-debian@postgresql.org MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ncSAzJYg3Aa9+CRW" Content-Disposition: inline In-Reply-To: <20130530025835.GB974@msgid.df7cb.de> User-Agent: Mutt/1.5.23 (2014-03-12) X-Pobox-Relay-ID: 4C185AFC-E81C-11E3-8A81-9903E9FBB39C-49531120!pb-smtp0.pobox.com X-Pg-Spam-Score: -1.2 (-) X-Mailing-List: pgsql-pkg-debian List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Precedence: bulk Sender: pgsql-pkg-debian-owner@postgresql.org --ncSAzJYg3Aa9+CRW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable > On Mon, 2013-05-27 at 09:27 +0000, stronny@celestia.ru wrote: > > The following bug has been logged on the website: > >=20 > > Bug reference: 8177 > > Logged by: stronny > > Email address: stronny@celestia.ru > > PostgreSQL version: 9.2.4 > > Operating system: wheezy > > Description: =20 > >=20 > > When installed from apt.postgresql.org Postgres fails to start on system > > boot. > >=20 > > Wheezy changed /var/run to become memory-based so initscript should cre= ate > > /var/run/postgresql if necessary. >=20 > 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 >=20 > do_ctl_all start "$1" "Starting PostgreSQL $1 database server" > } >=20 > 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_crea= tecluster"' exit 0 fi pg_lsclusters is a Perl application that gets most of its logic =66rom 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 =66rom 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. --=20 Chris Nehren --ncSAzJYg3Aa9+CRW Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (FreeBSD) iQJdBAABAgBHBQJTiLnUQBSAAAAAABUAInBrYS1hZGRyZXNzQGdudXBnLm9yZ2Nu ZWhyZW4rcGdzcWwtcGtnLWRlYmlhbkBwb2JveC5jb20ACgkQEcD4YkAzS8/SXg// R6eHXCipXWHfe3iL0wAz+VcregrSNKpq1HSuXnh+rDRfkJ/2RgfspJl1fk6pEcLn lBhPMHKPAYSGW8cZ0QsxIrcnLPpPwTe5MX7u50jn/slg1exiLSwGIbcIV10P15UJ sPDO5EqlESaZluRvqJnJkCfJ3zoOcVZRn9pw1g8+FCWdiR4p6S1bH9lFQgfoujiZ ci+Kbv279fWZTo7G8wCEbH5Ime5cBCTCX2oDgVpJdGotEAygmyOYsysTJfR0ajwe OhrCyvibhm2uM+VTBKd+FKSBoPi+qSVWzUC7PNx2q9IU3nixbZrwAuhBXMJtSriw vh1SEuo+g6lchsM9gbmqEUPy6IA0Dl9rvGvYIIGSQnQnrgwdfdIky543GkzsF0ch SbduGNhV/Lnsb4sXCrxRF4RNLbGLyY03dpbP3RbAjButS16t9UnBG1+6NYkJ8by6 EXbi6ooDEtbYFobdii3etxJm6WE8kHEWBzWc67afJIWcPQy7Rlw2OZZazNqf+uB8 maMwsJ0p/beQZpqCc61vssU3elEUhO3yoE4IJWEnz3NZ2GBv3icMQ9VHsA+SUEEb lgZI0/7lBaRSA4MZBIGEvXwdl5BEd9hmOXkRrIkIHKdfgfnAHe5lF6wdoNA5YQFt ojWhTotBsC0jH/IK5AQ54RtLzAuGh533LnHKrvYZlsU= =MFgL -----END PGP SIGNATURE----- --ncSAzJYg3Aa9+CRW--