1

Aim: backup a database and restore it in database2

pg_dump

A PG Dump has been created by issuing the following command:

c:\Temp>pg_dump -U postgres postgres > backupTest2.sql

Opening backupTest2.sql shows SQL statements.

restore pg_dump

However, once the backup would like to be restored in another database nothing seems to happen (number of tables in database2 remains 0, command hangs).

c:\Temp>psql -U postgres -d utrechtTest > backupTest2.sql

^C
  • 1
    The syntax of your restore command is incorrect. Change the direction of the redirect "arrow" (ie < instead of >) or use the -f option of psql. – Colin 't Hart Aug 7 '14 at 11:17
2

This:

psql -U postgres -d utrechtTest > backupTest2.sql

runs psql and writes its stdout to backupTest2.sql, which will be overwritten.

You meant:

psql -U postgres -d utrechtTest < backupTest2.sql

which is better written as:

psql -U postgres -d utrechtTest -f backupTest2.sql

because if you use -f then psql can show line numbers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.