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)

  • Are you sure you restarted Postgres after adding its owner to the app group? Mar 29, 2021 at 5:05
  • User is added to that group (as I said I can wrtite to that folder being logged as postgres user - so this is honored by OS), but server wasnt restarted. Is it required ?
    – Maciej
    Mar 29, 2021 at 5:12
  • 1
    Yes. Linux only picks up group membership on login, or for system services when they are restarted. You may even need to reload or restart systemd -- not sure what semantics it has on changing group membership. Mar 29, 2021 at 5:39
  • postgres owns pgsql directory usually. However, if this isn't the case ,you can give a try to below. chown postgres:postgres home/pgsql/TMP
    – Shiwangini
    Mar 29, 2021 at 5:49
  • 1
    Thank you Guys - indeed Im doing that by intention - I dont want postgres to be owner of folder nor 'app' group owner. I cant easily restart engine during PROD hrs - but will schedule that on weekend and will let you know if helps
    – Maciej
    Mar 29, 2021 at 9:36

1 Answer 1


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.