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?

asked Oct 28, 2017 at 1:11
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
answered Oct 28, 2017 at 8:33
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") Commented Oct 28, 2017 at 21:07
  • @Arya: well in the part -C bp bp.custom the first bp is wrong Commented Oct 28, 2017 at 21:14
  • but bp is the name of the database I want created. bp.custom is the backup file Commented 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 Commented 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? Commented Oct 29, 2017 at 6:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.