PostgreSQL Permissions – COPY TO Doesn’t Honor Linux Group Privileges

permissionspostgresql

I have issues executing COPY to command, receiving below error msg:

ERROR: could not open file "/home/pgsql/TMP/out.txt" for writing:
Permission denied

  • Postgres engine is being run as postgres user
  • Postgres user belongs to app group
  • TMP folder has below privileges set:
drwxrws---  2 pgsql app       23 Mar 28 19:47 TMP

I don’t understand why it doesn’t work.

I did quick check login as postgres user and creating file and this worked:

sudo -i -u postgres

If I change privileges to 777 all works as expected (I can do copy to command with no issues)
So as to me it looks postgres doesn’t somehow honor Linux groups rights

Can someone guide me how to resolve that (777 is not an option to me)

Best Answer

Server reboot helped. Privileges are treated as expected (Not sure if only DB engine is enough to fix that thought - I had to reboot entire machine)

Thanks @Colin for tip