Search code examples
postgresqltimescaledbpg-restore

How to restore .bak file using pg_restore command through cmd in PostgreSQL?


I have a test.bak file created with pg_dump command which has a hypertable and i have created a new database Performance_Test in postgreSQL.

The database was dumped using the command:

pg_dump -h localhost -U postgres -p 5432 -Fc -f "D:\Database Backup\temp.bak" Performace_Test

I want to restore that test.bak file in Performance_Test.

How can i do that?


Solution

  • You can restore doing the below(with caveats noted further on):

    pg_restore -h localhost -d Performace_Test -U postgres -p 5432 "D:\Database Backup\temp.bak"
    
    

    The caveats are:

    1. If Performace_Test was created as mixed case by quoting you will need to quote the name above e.g. "Performace_Test"

    2. If Performace_Test is not empty then you will get a bunch of errors.

    3. Also assumes that Performace_Test is on the same cluster as you specified in the pg_dump command.