Postgresql – Why is the pg_restore command not working

backuppg-restorepostgresqlpostgresql-9.6restore

Yesterday, I created backups of my various PostgreSQL databases using the following command:

pg_dump -Fc -d junk -h localhost -p 5434 -U postgres -W > z:\pg_dump\96_junk.dump

I created an individual backup for each database.

Today, I'm trying to restore them to an upgraded database server using the following command:

pg_restore -h localhost -p 5434 -U postgres -W -C -v z:\pg_dump\96_junk.dump

When I run pg_restore using the above it seems that the database was restored. The console screen displays a series of SQL statements and other messages I would expect to see for this database and, at the end, "PostreSQL database dump complete" is the output shown.

When I check the database, the database is not present. What am I doing wrong?

Employed versions info

  • Backups created with version 9.6.0

  • Attempting to restore using version 9.6.1

Best Answer

Try specifying the name of the DB to start in, using the -d or --dbname argument. This worked for me when I had the same problem. Note that it doesn't have to be the target DB:

pg_restore -h localhost -p 5434 -U postgres -d postgres -W -C -v z:\pg_dump\96_junk.dump