Re: COPY command and required file permissions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Harold A(dot) Giménez Ch(dot) <harold(dot)gimenez(at)gmail(dot)com>
Cc: "sql pgsql" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: COPY command and required file permissions
Date: 2008-06-12 14:48:00
Message-ID: 9073.1213282080@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"=?ISO-8859-1?Q?Harold_A._Gim=E9nez_Ch.?=" <harold(dot)gimenez(at)gmail(dot)com> writes:
> In migrating an application from sql server to Postgres, I created a ruby
> script that extracts csv files from sql server (from a windows box), then
> SCPs them into a directory (/home/ruby_process) on the server running
> Postgres (a Fedora core 8) and finally runs the Postgres COPY command for
> each of the csv files.

> When the script runs the COPY commnand, I get the following error (for the
> genders table):

> ERROR C42501 M could not open file "/home/ruby_process/genders.csv" for
> reading: Permission denied Fcopy.c L1694 RCopyFrom (RuntimeError)

If you have the directory and file permissions straight, then my guess
is that you have SELinux turned on and it's disallowing the postgres
daemon from accessing anything "out of the ordinary". The best fix
is probably to adjust the security labeling on your transfer directory.
I can't give you a cookbook recipe for that, but something along the
line of

/usr/bin/chcon -u system_u -r object_r -t postgresql_db_t /home/ruby_process

might do it. I'm not sure if you'd need to fool with the permissions on
/home as well.

The easiest fix is to disable SELinux, but I wouldn't recommend that
unless the machine is entirely isolated from the internet.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Harold A. Giménez Ch. 2008-06-12 14:55:56 Re: COPY command and required file permissions
Previous Message Pavel Stehule 2008-06-12 14:28:34 Re: COPY command and required file permissions