Postgresql backup and restore

postgresql

I'm trying to backup the database I made in postgresql but it doesn't seem to work

root@localhost:/home/tests# sudo -s -u postgres
postgres@localhost:/home/tests$ psql
psql (8.4.17)
Type "help" for help.
postgres=# pg_dump test_site > payroll.dump.out  
postgres-# ls
postgres@localhost:/home/tests$ exit
root@localhost:/home/tests# ls # Where is the backup?
cars  manage.py  media  staticfiles  test.db  tests  tests.db  test.wsgi

Can someone help me , please 🙂

Best Answer

pg_dump is not an SQL command. It's a separate command, like psql. So you can't run it from within a psql session, you must run it from a regular shell.

The reason you're not getting an outright error is that you didn't write a semicolon on the end of the line. That's why the prompt changed, too:

postgres=# pg_dump test_site > payroll.dump.out  
postgres-# ls
        ^ <-- See how it goes from = to - ?

That indicates that it's a continuation line, so psql is buffering up a statement and hasn't sent it yet.