permission denied postgres \copy csv command line

PHOTO EMBED

Fri Feb 18 2022 07:50:49 GMT+0000 (UTC)

Saved by @irfan309 #psql #chown #export/copy-table-to-csv #permission-denied #\copy

# here when tries to copy the table to csv file, was getting Erro Like
# /home/ubuntu/file.csv : permission denied 
# actually we are trying to copy or do/perform some action like excuting/read/write a new 
# file or exsting file, but understand one thing is from any user to any other user
# location directory if we want to perfom any thing we do not have permissions for that.
# we have to have a right access for that users directory.
# so here we are trying to copy/export  the table to  csv file from postgres to user        # Ubuntu's /home/ubuntu  Directroy for that we have to have permission of Rwx Permission on # ubuntu for that here we use - ''' sudo chown user:user <path/to/access> ''' to get access of
# ubuntu user.

\COPY person  TO /home/ubuntu/data.csv DELIMITER ',' CSV HEADER;
# Gets This error -- /home/ubuntu/data.csv: Permission denied
# now user chown as shown below to get permission of directory-path  to write/execute

sudo chown postgres:postgres /home/ubuntu/
content_copyCOPY

To export / copy the tabel to csv or any format from postgres database table.