I understand that pg_restore needs to connect to a database before it can start the restore process, is there anyway pg_restore can use the "postgres" database to create another database?
I have the following command
pg_restore -h "192.168.1.212" -p 5432 -U mysuperusername -C -d bp bp.custom
when I run the command I get the following message
pg_restore: [archiver (db)] connection to database "bp" failed: FATAL: database "bp" does not exist
Is there anyway for pg_restore to create the "bp" database without me having to create it manually?
1 Answer 1
Specify -d postgres
on the command line.
Quote from the manual for the -C
option. The database to be restored is automatically take from the backup file
When this option is used, the database named with -d is used only to issue the initial DROP DATABASE and CREATE DATABASE commands. All data is restored into the database name that appears in the archive.
pg_restore -h "192.168.1.212" -p 5432 -U mysuperusername -C -d postgres bp.custom
-
I tried it with
pg_restore -h "192.168.1.212" -p 5432 -U mysuperusername -d postgres -C bp bp.custom
and I get the following messagepg_restore: too many command-line arguments (first is "bp.custom")
Arya– Arya2017年10月28日 21:07:15 +00:00Commented Oct 28, 2017 at 21:07 -
@Arya: well in the part
-C bp bp.custom
the firstbp
is wronguser1822– user18222017年10月28日 21:14:08 +00:00Commented Oct 28, 2017 at 21:14 -
but bp is the name of the database I want created. bp.custom is the backup fileArya– Arya2017年10月28日 21:19:57 +00:00Commented Oct 28, 2017 at 21:19
-
You do not need to specify the database to be created because that information is stored in the backupuser1822– user18222017年10月29日 06:05:03 +00:00Commented Oct 29, 2017 at 6:05
-
I understand now, is there anyway to have pg_restore to create the user that was used with the database? for example, for my "bp" database was used by the user "bp" anyway to create the user with pg_restore?Arya– Arya2017年10月29日 06:12:07 +00:00Commented Oct 29, 2017 at 6:12