0

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.

Alex
  • 516
  • 5
  • 12
  • 1
    note : the complete path ` /var/www/vhosts/[vhostname]/httpdocs/` upto `adc_downloads` must *at least* have an `x` bit for postgres (probably: as others) – joop Dec 05 '17 at 17:57
  • Is [this](https://dba.stackexchange.com/questions/75548/change-permissions-of-postgres-copy-to-exported-file) helpful? – pirho Dec 05 '17 at 18:02
  • @pirho no luck using the `chgrp` and `chmod` commands as suggested in the accepted answer – Alex Dec 06 '17 at 15:35
  • Can you paste minimal sample of the script that re-produces the error and the actual error message in whole? how do you run it? `psql`? Where do you run it? – pirho Dec 06 '17 at 17:08
  • @pirho fixed it, see my answer below – Alex Dec 07 '17 at 10:19

1 Answers1

0

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

Alex
  • 516
  • 5
  • 12