hsivru
hsivru

Reputation: 55

Postgres: COPY TO error

I need help turning my Postgres table into a CSV file. First, I type

sudo su postgres (then I enter my password)
psql -d postgres -U postgres

The terminal looks like:

postgres=#

I typed in the COPY TO command to try to create a .csv file with all the information in my table, but I get an error:

postgres=# COPY venues TO '/usr/file.csv';
ERROR:  could not open file "/usr/file.csv" for writing: Permission denied

I also tried using the \copy command, but I get:

postgres=# \COPY venues TO '/usr/file.csv';
/usr/file.csv: Permission denied

I read a couple answers that said that I might not have permission to write in a certain directory. Is this true?

Also, in postgres, the schema lists my_name as the owner of the table I am trying to export information from (venues). However, this is when I am logged in as a postgres user, and I am only able to access the table when I am a logged is as a postgres user.

When I log into postgres by simply typing "psql," I get:

my_name=>

and when I type the command "\d" to see the tables under this user, I do not see the venues table listed. Can someone please help me with this issue? Thank you in advance.

Upvotes: 0

Views: 3361

Answers (1)

Vao Tsun
Vao Tsun

Reputation: 51609

postgres=# COPY venues TO '/tmp/file.csv';

should work for u

Upvotes: 1

Related Questions