Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

postgresql

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!

like image 519
user2449984 Avatar asked Oct 19 '13 06:10

user2449984


People also ask

How do I fix Postgres permission denied?

Grant privileges to a new user We resolve this permission denied error using the command. GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO new_user; The new_user was then able to read data from the table. Similarly, we can also resolve the permission denied error by setting DEFAULT privileges to the user.

How do I import a CSV file into PgAdmin?

To import CSV using this PgAdmin Import CSV method, you have to do the following: Click on the Tools tab at the top of your PgAdmin Home Page. Select the Query Tool in the drop-down menu that appears. Enter the title and columns in your CSV file as an SQL Query.

How do I use Copy command in postgresql?

PSQL \Copy Command for Client-Side ExportTo copy the entire table to a csv file, use \copy. This will copy the contents of a table to the client computer as a csv file. The file will not contain the headers of the table. \copy employees to '/var/lib/postgresql/emp.


2 Answers

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.

like image 64
Daniel Vérité Avatar answered Sep 24 '22 14:09

Daniel Vérité


Copy the CSV file to /tmp

For me this solved the issue.

like image 26
user637338 Avatar answered Sep 21 '22 14:09

user637338