Question

i used below command to backup my database

sudo -u user_name pg_dump dbName -f /home ..../someWhere/db.sql

but it gives me this :

pg_dump: [archiver] could not open output file "/home ..../someWhere/db.sql": Permission denied

after googling this issue i find that i must backup my data under the /tmp path , but doesn't work

how can i resolve this issue ?

thanks in advance,


i am using Ubuntu 12.04 lts

Was it helpful?

Solution 2

try pg_dump from psql command-line as below:

postgres=# \! pg_dump dbName -f /home ..../someWhere/db.sql

OTHER TIPS

It looks like your pg_dump is working fine, but it is having problems opening the output file as the sudo user. Just guessing, but, if you do the redirection as the user (presumably the one running the pg_dump command) id, that should do it, that is:

sudo -u user_name pg_dump dbName > /home ..../someWhere/db.sql

Using this technique your pg_dump will run as the postgres user (assuming that is who user_name is) and the file being written in /home... will be written using the permission of the user running the command (this user might have different permissions than the postgres user).

Do it from psql command line like below

-bash-4.1$ pg_dump -Fp dbName -f /home ..../someWhere/db.sql &

-F selects the format of the output in which p is Output a plain-text SQL script file

and & at the end will run your backup in the background.

Just in case somebody else lands here like I did, be aware that pg_dump shows this error too if the folder doesn't exist. In that case, just create the directory beforehand using mkdir -p folder_name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top