1

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?

0

1 Answer 1

2

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
6
  • 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 message pg_restore: too many command-line arguments (first is "bp.custom")
    – Arya
    Oct 28, 2017 at 21:07
  • @Arya: well in the part -C bp bp.custom the first bp is wrong
    – user1822
    Oct 28, 2017 at 21:14
  • but bp is the name of the database I want created. bp.custom is the backup file
    – Arya
    Oct 28, 2017 at 21:19
  • You do not need to specify the database to be created because that information is stored in the backup
    – user1822
    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
    Oct 29, 2017 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.