I wrote a bat script for executing the Postgres backup and restore tool.
I have a little issue with the restore flow: Its works fine as long as my database exists. But if it doesn't it will fail. My restore command:
"pg_restore.exe" -d postgres://postgres:[email protected]:9195/mydb -w -c -v -F c --if-exists "DatabaseBackup_mydb.tar" 2>> "DatabaseRestore_mydb.log"
So I need to modify that command somehow that will handle also a use case in which the database "mydb" doesn't exist, and create it in such a case.
just adding the -C flag won't work in that case.
Any suggestion?
postgres://postgres:[email protected]:9195/postgres
and adding-C
. Obviously test on throw away instance. This will connect topostgres
databaseDROP DATABASE IF EXISTS mydb;
, thenCREATE DATABASE mydb
, connect tomydb
and then restore the database objects.