Login as a pgsql user

Typed the following command:

$ su - pgsql

Get list of database(s) to backup:

$ psql -l

I choosed users database

Type the following command

$ pg_dump users > users.dump.out

ok right, where I can find the users.dump.out ? , I need use that backup in other server.

  • That file (users.dump.out) should be in your current directory. Are you saying it isn't? Oct 12, 2015 at 20:39

4 Answers 4


su -pgsql changes the user to pgsql AND changes the current working directory (cwd) to pgsql's home directory.

You then ran the pg_dump command in ~pgsql/, so the file you are looking for will be in that directory: ~pgsql/users.dump.out


I found the database backup, in my case was in: /var/lib/postgresql#

Thanks all for the help.


users.dump.out is in the directory, where you ran the command.

You can also use the --file= option to specify the output file.

  • I did run the command inside my www folder , but that file is not there :(
    – raduken
    Oct 12, 2015 at 15:55
  • 1
    @user964836 you can try find / -name 'users.dump.out' to attempt to locate it. (Note that may take a while, depending on how many files you have, if you have mounted network shares, etc.)
    – derobert
    Oct 12, 2015 at 16:24
  • 1
    no, you ran the pg_dump command in user pgsql's home directory (why? because su - pgsql not only changed the uid to pgsql, it changes the cwd to pgsql's home dir). The file will be in ~pgsql/users.dump.out
    – cas
    Oct 12, 2015 at 22:52

In Ubuntu, try this

sudo su - postgres
pg_dump db_name > db_name.bak

and find backup in /var/lib/postgresql

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .