Search code examples
postgresqlpermissionscentoscopyplesk

Postgres COPY TO not working for intended destination directory


I have written a function that prepares data based on user-input from the web and copies the results down as a csv to a specified directory, from where the package (each request will contain information from 3 different tables/csv files) will be made available for the user to download.

The function itself works if the output directory is in the pg_data directory /var/lib/pgsql/data/adc_downloads, the permissions are:

drwxr-xr-x  2 postgres postgres  4096 Dec  5 15:18 adc_downloads

But ideally I want the output directory to be here: /var/www/vhosts/[vhostname]/httpdocs/adc_downloads. After getting it to work in pg_data, I used chown -R --reference=/var/lib/pgsql/data/adc_downloads /var/www/vhosts/[vhostname]/httpdocs/adc_downloads and chmod with the same parameters to mimic the permissions which appears to have worked:

drwxr-xr-x  2 postgres postgres  4096 Dec  5 14:19 adc_downloads

but I'm still getting a Permission denied error when trying to run the function with the intended output directory.

Something else then must be overriding the permissions I've (tried to?) set, any ideas what this might be? Given the function itself works in one directory but not another I don't think it's an SELinux issue, though I may of course be wrong.

Version Info: Postgres 8.4 CentOS 6.5 built with Plesk.


Solution

  • got this working (thanks to @joop's recommendation) in the intended location /var/www/vhosts/[vhostname]/httpdocs/adc_downloads by adding execute permission for the other users (including the postgres user) for the [vhostname] and httpdocs directories