FS#16507 - [postgresql] $PG_ROOT created with incorrect permissions

Attached to Project: Arch Linux
Opened by Byron Clark (byronc) - Wednesday, 07 October 2009, 20:39 GMT
Last edited by Dan McGee (toofishes) - Sunday, 12 September 2010, 23:34 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To Paul Mattal (paul)
Architecture x86_64
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Description: The first run of /etc/rc.d/postgresql creates $PG_ROOT owned by root with permissions 700. Postgresql fails to start because the postgres user must have access to $PG_ROOT/data.

Here's the output from the first run of /etc/rc.d/postgresql:
$ sudo /etc/rc.d/postgresql start
:: Starting PostgreSQL [BUSY]
:: Adding postgres group [DONE]
:: Adding postgres user [DONE]
su: warning: cannot change directory to /var/lib/postgres: Permission denied
could not change directory to "/home/byron"
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale C.
The default database encoding has accordingly been set to SQL_ASCII.
The default text search configuration will be set to "english".

initdb: could not access directory "/var/lib/postgres/data": Permission denied
su: warning: cannot change directory to /var/lib/postgres: Permission denied
could not change directory to "/home/byron"
pg_ctl: could not open PID file "/var/lib/postgres/data/postmaster.pid": Permission denied
[FAIL]

Additional info:
* postgresql 8.4.1-1

This task depends upon

Closed by  Dan McGee (toofishes)
Sunday, 12 September 2010, 23:34 GMT
Reason for closing:  Fixed
Additional comments about closing:  8.4.4-3 should resolve this now, coming soon.
Comment by Byron Clark (byronc) - Wednesday, 07 October 2009, 21:04 GMT
The bigger trouble is that initdb fails to run because of the permission problems.
Comment by Geoff Hull (smiths_cloud) - Wednesday, 16 December 2009, 09:01 GMT
I had a similar problem on my 32-bit system, same version of PostgreSQL.

I think the problem is on line 23 of the Arch startup script /etc/rc.d/postgresql:
18 useradd -u 88 -g postgres -d $PGROOT -s /bin/bash postgres
19 [ -d $PGROOT ] && chown -R postgres.postgres $PGROOT
20 stat_done
21 fi
22 if [ ! -d $PGROOT ]; then
23 mkdir -p $PGROOT/data && chown postgres.postgres $PGROOT/data
24 su - postgres -c "/usr/bin/initdb -D $PGROOT/data"
25 fi
26 if [ ! -e /var/log/postgresql.log ]; then
27 touch /var/log/postgresql.log
28 chown postgres /var/log/postgresql.log

This is creating the $PGROOT directory and data subdirectory and changing ownership only on the subdirectory. I copied part of line 19 above:

23 mkdir -p $PGROOT/data && chown -R postgres.postgres $PGROOT

Patch is (I think - haven't done this before):

--- etc/rc.d/postgresql 2009-09-16 17:15:54.000000000 +1200
+++ /etc/rc.d/postgresql 2009-12-05 22:16:27.617702668 +1300
@@ -20,7 +20,7 @@
stat_done
fi
if [ ! -d $PGROOT ]; then
- mkdir -p $PGROOT/data && chown postgres.postgres $PGROOT/data
+ mkdir -p $PGROOT/data && chown -R postgres.postgres $PGROOT
su - postgres -c "/usr/bin/initdb -D $PGROOT/data"
fi
if [ ! -e /var/log/postgresql.log ]; then
Comment by Hampus Wessman (hampusw) - Sunday, 10 January 2010, 14:59 GMT
I also encountered this problem, with PostgreSQL 8.4.2 on x86_64. The automatic creation of $PGROOT always fails.

I (independently) solved the problem exctly like the above patch. It looks like a small typo. Making the small change suggested above solves everything and is probably what was originally intended.
Comment by Byron Clark (byronc) - Thursday, 15 July 2010, 14:29 GMT
  • Field changed: Percent Complete (100% → 0%)
The applied fix on changes the 'chown postgres.postgres $PGROOT/data' line to 'chown -R postgres.postgres $PGROOT/data' when it should be 'chown -R postgres.postgres $PGROOT'

Loading...