Extracting postgresql data to file

Asked

Viewed 465 times

1

I am trying to extract data from a table to a file with the following command:

COPY historico TO '/home/jessica/teste.txt';

But the following error occurs:

ERROR: could not open file "/home/Jessica/teste.txt" for writing: Permission denied

  • which operating system? is doing this directly in the code? which language? or is trying by pgAdmin?

  • Use Ubuntu. I am doing by terminal, logged into the database inside the same postgresql.

  • I believe that the user "postgres", does not have permission to create files inside the user folder "Jessica", Log with the user "Jessica" and a chmod -R 0777 in the briefcase /home/jessica, after I try the process again

  • 1

    Jessica don’t use the chmod -R 0777 suggested by Guilherme lautert, 777 -R is "releases EVERYTHING to EVERYONE in that folder, in the subfolders and in the files contained" and you rarely want to do something like this on your system.

1 answer

1

The user you are accessing the database is not allowed to create the file in the /home/Jessica directory/

You can do the following command:

COPY historico TO '/tmp/teste.txt';

In the /tmp directory all system users can access it normally and from there, you manipulate your file.

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.