Postgres ERROR: could not open file for reading: Permission denied

Computer: Mac OS X, version 10.8 Database: Postgres

Trying to import csv file into postgres.

pg> copy items_ordered from '/users/darchcruise/desktop/items_ordered.csv' with CSV;
ERROR:  could not open file "/users/darchcruise/desktop/items_ordered.csv" for reading: Permission denied

Then I tried

$> chown postgres /users/darchcruise/desktop/items_ordered.csv
chown: /users/darchcruise/desktop/items_ordered.csv: Operation not permitted

Lastly, I tried

$> ls -l
-rw-r--r--  1 darchcruise  staff      1016 Oct 18 21:04 items_ordered.csv

Any help is much appreciated!


Assuming the psql command-line tool, you may use \copy instead of copy.

\copy opens the file and feeds the contents to the server, whereas copy tells the server the open the file itself and read it, which may be problematic permission-wise, or even impossible if client and server run on different machines with no file sharing in-between.

Under the hood, \copy is implemented as COPY FROM stdin and accepts the same options than the server-side COPY.


Copy the CSV file to /tmp

For me this solved the issue.