Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql dump permission denied

Tags:

postgresql

I get this error while trying to dump database, i entered

linuxuser $ sudo su postgres
linuxuser $ [sudo] password for linuxuser:...
$ pg_dump -h localhost mydb >tempfile
$ sh: cannot create tempfile: Permission denied

What the problem? i've just installed fresh postgresql.

like image 739
Feanor Avatar asked Jan 12 '12 13:01

Feanor


3 Answers

Write into directory where postgres user has write access. For instance /tmp.

$ pg_dump -h localhost mydb >/tmp/tempfile

In your attempt postgres user tries to create a file in some random directory belonging to the other user.

like image 70
Michael Krelin - hacker Avatar answered Nov 15 '22 05:11

Michael Krelin - hacker


backup and restore can be done by any unpriviledged user that knows the postgres superuser password by changing permissions on the working directory:

% mkdir backup

% chmod 0777 backup

% su postgres

[enter password]

$ cd backup

$ pg_dump mydb >tempfile

$ exit

"tempfile" will be owned by postgres and same group as the user

like image 9
shoshinsha Avatar answered Nov 15 '22 04:11

shoshinsha


sudo su postgres doesn't change the current directory so you're still in linuxuser's home directory and postgres has no permission to write into it. Change to a different directory

like image 6
Daniel Vérité Avatar answered Nov 15 '22 05:11

Daniel Vérité