Re: Postgresql 8.0.3, symbolic link to /var/lib/pgsql/data/base

Lists: pgsql-admin
From: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
To: pgsql-admin(at)postgresql(dot)org
Subject: Postgresql 8.0.3, symbolic link to /var/lib/pgsql/data/base
Date: 2005-09-28 18:51:34
Message-ID: 433AE636.7030506@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

I'm trying to move my databases to another drive.

With postmaster off, I create:

/home/pgsql

mv /var/lib/pgsql/data/base /home/pgsql/

I make sure that /home/pgsql is owned by postgres, and only 'rwx' for
the owner. All the permissions look fine.

from /var/lib/pgsql/data, I do

ln -s /home/pgsql/base

Of course the link permissions look like:

lrwxrwxrwx 1 postgres postgres 16 Sep 28 14:21 base -> /home/pgsql/base

The postmaster starts, but attempts to access the database complain that
permission is denied:

$ psql -l
psql: FATAL: could not access directory "/var/lib/pgsql/data/base/1":
Permission denied

Any clues about why this won't work?
I've searched the archives, but most references were to invalid
permissions on the directories and I'm pretty sure I've got those right.

All my pgsql dirs look pretty much like:
drwx------ 3 postgres postgres 4096 Sep 28 14:21 pgsql

Both in the original /var/lib/pgsql area, and the /home/pgsql area.


From: Sergiusz Jarczyk <sergiusz(dot)jarczyk(at)qresc(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: Postgresql 8.0.3, symbolic link to /var/lib/pgsql/data/base
Date: 2005-09-28 19:34:10
Message-ID: 433AF032.3090305@qresc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Hi Jeffrey

Jeffrey Tenny wrote:

> I'm trying to move my databases to another drive.
>
> With postmaster off, I create:
>
> /home/pgsql
>
> mv /var/lib/pgsql/data/base /home/pgsql/
>
>
> I make sure that /home/pgsql is owned by postgres, and only 'rwx' for
> the owner. All the permissions look fine.
>
> from /var/lib/pgsql/data, I do
>
> ln -s /home/pgsql/base
>
> Of course the link permissions look like:
>
> lrwxrwxrwx 1 postgres postgres 16 Sep 28 14:21 base -> /home/pgsql/base
>
>
> The postmaster starts, but attempts to access the database complain
> that permission is denied:
>
> $ psql -l
> psql: FATAL: could not access directory "/var/lib/pgsql/data/base/1":
> Permission denied
>
>
> Any clues about why this won't work?
> I've searched the archives, but most references were to invalid
> permissions on the directories and I'm pretty sure I've got those right.
>
> All my pgsql dirs look pretty much like:
> drwx------ 3 postgres postgres 4096 Sep 28 14:21 pgsql
>
> Both in the original /var/lib/pgsql area, and the /home/pgsql area.
>

Try to issue chown -R postgres.postgres /home/pgsql

Sergiusz


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Postgresql 8.0.3, symbolic link to /var/lib/pgsql/data/base
Date: 2005-09-28 19:42:50
Message-ID: 8410.1127936570@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net> writes:
> I'm trying to move my databases to another drive.

On what platform?

One theory that fits the available facts is that you're running on a
machine with SELinux enabled; the usual selinux policy forbids the
postmaster from accessing files outside /var/lib/pgsql.

regards, tom lane


From: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Postgresql 8.0.3, symbolic link to /var/lib/pgsql/data/base
Date: 2005-09-28 21:15:30
Message-ID: 433B07F2.40906@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

The platform is Redhat 9, so no SELinux.

Tom Lane wrote:
> Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net> writes:
>
>>I'm trying to move my databases to another drive.
>
>
> On what platform?
>
> One theory that fits the available facts is that you're running on a
> machine with SELinux enabled; the usual selinux policy forbids the
> postmaster from accessing files outside /var/lib/pgsql.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>


From: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
To: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-admin(at)postgresql(dot)org
Subject: Re: Postgresql 8.0.3, symbolic link to /var/lib/pgsql/data/base
Date: 2005-09-28 21:17:33
Message-ID: 433B086D.7020709@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Sorry, I take that back. The platform is Fedora Core 4, so SELinux may
be a concern, though during the installation I selected all the minimal
options for SELinux because I wasn't prepared to deal with it.

Apologies for the previous incorrect answer, I was typing it on a Redhat
9 machine :-)

Jeffrey Tenny wrote:
> The platform is Redhat 9, so no SELinux.
>
> Tom Lane wrote:
>
>> Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net> writes:
>>
>>> I'm trying to move my databases to another drive.
>>
>>
>>
>> On what platform?
>>
>> One theory that fits the available facts is that you're running on a
>> machine with SELinux enabled; the usual selinux policy forbids the
>> postmaster from accessing files outside /var/lib/pgsql.
>>
>> regards, tom lane
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 6: explain analyze is your friend
>>
>


From: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
To: Sergiusz Jarczyk <sergiusz(dot)jarczyk(at)qresc(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Postgresql 8.0.3, symbolic link to /var/lib/pgsql/data/base
Date: 2005-09-28 21:22:00
Message-ID: 433B0978.8070701@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Sergiusz Jarczyk wrote:
>
> Try to issue chown -R postgres.postgres /home/pgsql
>

I checked the ownership, and it was already ok because aside from
the 'root' creation of the alternate directory location and assigning it
the correct ownership and permissions, I did the 'mv' of the old
directory to the new location logged in as 'postgres'.

Ditto the symlink creation (did it as 'postgres').


From: Sergiusz Jarczyk <sergiusz(dot)jarczyk(at)qresc(dot)com>
To: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Postgresql 8.0.3, symbolic link to /var/lib/pgsql/data/base
Date: 2005-09-28 21:26:30
Message-ID: 433B0A86.7040907@qresc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Hi again
Have you tried to run the postmaster with the new location by hand, i.e.:
postmaster -i -D /home/pgsql

Sergiusz


From: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
To: Sergiusz Jarczyk <sergiusz(dot)jarczyk(at)qresc(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Postgresql 8.0.3, symbolic link to /var/lib/pgsql/data/base
Date: 2005-09-28 21:29:48
Message-ID: 433B0B4C.3060104@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

I've been focusing on the potentially simpler case of just relocating
the 'base' directory, so that I don't have to worry about whether
postmaster is finding my config files and such.

I was hoping the symlink would be a pretty transparent operation,
and it doesn't seem that other people have had difficulty doing similar
th ings.

Sergiusz Jarczyk wrote:
> Hi again
> Have you tried to run the postmaster with the new location by hand, i.e.:
> postmaster -i -D /home/pgsql
>
> Sergiusz
>
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Postgresql 8.0.3, symbolic link to /var/lib/pgsql/data/base
Date: 2005-09-28 21:33:15
Message-ID: 5092.1127943195@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net> writes:
> Sorry, I take that back. The platform is Fedora Core 4, so SELinux may
> be a concern, though during the installation I selected all the minimal
> options for SELinux because I wasn't prepared to deal with it.

Better check what /usr/sbin/getenforce tells you, then... or look in
/var/log/messages to see if the postmaster's operations are being
refused.

regards, tom lane


From: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-admin(at)postgresql(dot)org
Subject: Re: Postgresql 8.0.3, symbolic link to /var/lib/pgsql/data/base
Date: 2005-09-28 21:42:30
Message-ID: 433B0E46.1030303@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Tom Lane wrote:
> Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net> writes:
>
>>Sorry, I take that back. The platform is Fedora Core 4, so SELinux may
>>be a concern, though during the installation I selected all the minimal
>>options for SELinux because I wasn't prepared to deal with it.
>
>
> Better check what /usr/sbin/getenforce tells you, then... or look in
> /var/log/messages to see if the postmaster's operations are being
> refused.
>

Interesting. getenforce says "Enforcing".
There are no suspicious messages in /var/log/messages or any other log I
can find there.


From: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Postgresql 8.0.3, symbolic link to /var/lib/pgsql/data/base
Date: 2005-09-28 22:03:33
Message-ID: 433B1335.70404@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Here's the /var/lib/pgsql/data directory ('.')

-bash-3.00$ ls -ldZ
drwx------ postgres postgres system_u:object_r:postgresql_db_t .

Here are the children:

-bash-3.00$ ls -ldZ *
lrwxrwxrwx postgres postgres user_u:object_r:postgresql_db_t base ->
/home/pgsql/base
drwx------ postgres postgres root:object_r:postgresql_db_t global
drwx------ postgres postgres root:object_r:postgresql_db_t pg_clog
-rw------- postgres postgres user_u:object_r:postgresql_db_t pg_hba.conf
-rw------- postgres postgres user_u:object_r:postgresql_db_t pg_hba.conf~
-rw------- postgres postgres root:object_r:postgresql_db_t pg_ident.conf
drwx------ postgres postgres root:object_r:postgresql_db_t pg_log
drwx------ postgres postgres root:object_r:postgresql_db_t pg_subtrans
drwx------ postgres postgres root:object_r:postgresql_db_t pg_tblspc
-rw------- postgres postgres root:object_r:postgresql_db_t PG_VERSION
drwx------ postgres postgres root:object_r:postgresql_db_t pg_xlog
-rw------- postgres postgres user_u:object_r:postgresql_db_t
postgresql.conf
-rw------- postgres postgres user_u:object_r:postgresql_db_t
postgresql.conf~
-rw------- postgres postgres root:object_r:postgresql_db_t
postmaster.opts

-bash-3.00$ ls -ldZ /home/pgsql
drwx------ postgres postgres root:object_r:user_home_dir_t /home/pgsql
-bash-3.00$ ls -ldZ /home/pgsql/base
drwx------ postgres postgres root:object_r:postgresql_db_t
/home/pgsql/base
-bash-3.00$ ls -ldZ /home/pgsql/base/*
drwx------ postgres postgres root:object_r:postgresql_db_t
/home/pgsql/base/1
drwx------ postgres postgres root:object_r:postgresql_db_t
/home/pgsql/base/17229
drwx------ postgres postgres system_u:object_r:postgresql_db_t
/home/pgsql/base/17230
drwx------ postgres postgres system_u:object_r:postgresql_db_t
/home/pgsql/base/29144
drwx------ postgres postgres system_u:object_r:postgresql_db_t
/home/pgsql/base/29149

Somewhere in here is probably the clue, and a 'chcon' is probably
necessary. I'm clueless about selinux though and have no idea what to do.

Tom Lane wrote:
> Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net> writes:
>
>>Sorry, I take that back. The platform is Fedora Core 4, so SELinux may
>>be a concern, though during the installation I selected all the minimal
>>options for SELinux because I wasn't prepared to deal with it.
>
>
> Better check what /usr/sbin/getenforce tells you, then... or look in
> /var/log/messages to see if the postmaster's operations are being
> refused.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>


From: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
To: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-admin(at)postgresql(dot)org
Subject: Re: Postgresql 8.0.3, symbolic link to /var/lib/pgsql/data/base
Date: 2005-09-29 01:11:49
Message-ID: 433B3F55.2040407@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

I tried a few:

chcon -t postgresql_db_t /home/pgsql

type things. No luck.

It's interesting that there are no permission denials
logged in /var/log/messages, but postgresql
says it can't access /var/lib/pgsql/data/base
because permission is denied (in the postgres log).

I played with the symlink chcon user, and the /home/pgsql user
as well (again, chcon, not chown).

It's clearly selinux though. If I do this:

/usr/sbin/setenforce 0

Then everything works peachy for my testing.

But turning off selinux is probably a one way road,
since all files created in that environment won't have their
context set. So I really need to solve this in the correct fashion.

For now I'll run with the database files under /var/lib/pgsql/data
until I (or someone else) can figure out the selinux/postgresql magic.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Postgresql 8.0.3, symbolic link to /var/lib/pgsql/data/base
Date: 2005-09-29 02:10:45
Message-ID: 6688.1127959845@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net> writes:
> It's clearly selinux though. If I do this:
> /usr/sbin/setenforce 0
> Then everything works peachy for my testing.

OK, that's pretty conclusive as to the source of the issue.

> It's interesting that there are no permission denials
> logged in /var/log/messages, but postgresql
> says it can't access /var/lib/pgsql/data/base
> because permission is denied (in the postgres log).

I've run into this more than a few times myself. What I've been told
when I complained about it is "that's normal because selinux log
messages are rate-limited to avoid inflating the log files too much".
Which is plausible in itself, but rate-limiting to zero is not helpful.
Feel free to file another gripe in Red Hat's bugzilla.

regards, tom lane