Nupur
Nupur

Reputation: 89

restoring PostgreSQL database after creating target database

Below code for restoring the database backup works when I run after manually creating the database_restore in postgresql.

os.putenv('PGPASSWORD', password)

from_backup_dir = ".\\Files\\DBBackups\\"

dumper = """ "C:\\Program Files\\PostgreSQL\\14\\bin\\pg_restore" -h %s -p %s -U %s -d %s -v -F t %s """
file_name = "dbbackup" + file_timestamp + ".backup"
command = dumper % (host, port, user, database_restore,
                    from_backup_dir + "dbbackup2024_07_31_16_00_29_859387.backup")

I want to use the -C option to create the target database instead of manually creating i.e.

dumper = """ "C:\\Program Files\\PostgreSQL\\14\\bin\\pg_restore" -h %s -p %s -U %s **-C** -d %s -v -F t %s """ 

But this gives error. Any directions will be helpful.

The error message is : pg_restore: connecting to database for restore pg_restore: error: connection to server at "localhost" (::1), port 5432 failed: FATAL: database "SDEDB1" does not exist

**SDEDB1 was my database_restore

Upvotes: 1

Views: 45

Answers (0)

Related Questions