0

I'm on a GCE instance with a postgresql DB and I'm running the following command:

COPY (Select * from mytable) TO '/home/myuser/myfile.txt' DELIMITER '#' CSV HEADER;

and getting the following error:

could not open file "/home/myuser/myfile.txt" for writing: Permission denied

how to fix it? (on my local machine this command works fine)

Vivek S.
  • 19,945
  • 7
  • 68
  • 85
liv a
  • 3,232
  • 6
  • 35
  • 76
  • 1
    Did you search for it before ask this very popular question ? – Houari May 16 '15 at 10:08
  • @Houari yes I did, as well as read some of the answers here. I also worked around it by creating the file using nano and changing the chmod to 777 but the reason I'm asking is because there must be a better way to do it – liv a May 16 '15 at 10:40
  • In most of the case, a directory is created and used for copying to it from postgresql. with that way, you have to fix the permission problem only one time to this folder. Please look at [this](http://stackoverflow.com/a/28595245/1216680) – Houari May 16 '15 at 10:50
  • It looks like you probably want `\copy` not `COPY`. This is a FAQ. – Craig Ringer May 17 '15 at 00:19

0 Answers0