1

I have made a backup of my specific tables that I want to restore into a new database using:

call pg_dump -Fc -h server -d database -U user -p password -v -f dump.sql -t public.table1 -t public.table2

And I have no problems.

I then want to restore the dump by creating a new database with pg_restore using:

call pg_restore --clean --create -d temp -h server -p password -U user dump.sql

This gives me a "database temp does not exist" error. This should have created the database and restored it as far as I understand.

I However then create the "temp" database manually and run:

call pg_restore --clean --create -d temp -h server -p password -U user dump.sql

This follows through, but does not create the tables and gives me an error "relation table1" and "relation table2" does not exist and only creates the corresponding id_sequences for the two tables.

What I actually want is to not have to manually create the new database and that all tables in the backup is restored into a brand new database via pg_restore using:

call pg_restore --clean --create -d temp -h server -p password -U user dump.sql

as I understand it.

2 Answers 2

3

In order to create the database temp, pg_restore needs to be connected to a different database first.

So it won't do to use -d temp; you must specify an existing database, typically postgres.

pg_restore will connect to that database, issue CREATE DATABASE temp, connect to temp and proceed to restore the data.

Sign up to request clarification or add additional context in comments.

Comments

-1

for me, I installed pgAdmin 4 and did the restore via pgAdmin 4 UI, instead of doing it via cmd:

pg_restore -d <database_name> -p 5432 -Fc -O -a --no-tablespaces --no-privileges -v -U postgres -j 8 <database_name>.dmp

2 Comments

This does not answer the question
restore over the pgAdmin 4 UI

Your Answer

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.