debugsqlModerate
pg_restore ERROR: "Relation does not exist" and creating new database
Viewed 0 times
errornewcreatingexistdatabasedoesandrelationpg_restorenot
Problem
I have made a backup of my specific tables that I want to restore into a new database using:
And I have no problems.
I then want to restore the dump by creating a new database with pg_restore using:
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:
This follows through, but does not create the tables and gives me an error "
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:
as I understand it.
Please Help, very frustrating
call pg_dump -Fc -h server -d database -U user -p password -v -f dump.sql -t public.table1 -t public.table2And 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.sqlThis 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.sqlThis 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_sewuences 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.sqlas I understand it.
Please Help, very frustrating
Solution
When
This is documented as:
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.
This is why
You should add a
For the second problem, it's a completely different question, hard to guess why it happens without complete error messages.
Also note that
--create and -d are used together, the argument to -d is not the name of the database to create, it's the name of an existing database to connect to run the CREATE DATABASE statement, because it's impossible to create a database if you're not already connect to another database.This is documented as:
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.
This is why
pg_restore errors out with database temp does not existYou should add a
createdb step in your restore procedure since you want to create a specific database name anyway, not one that comes from the backup.For the second problem, it's a completely different question, hard to guess why it happens without complete error messages.
Also note that
-p is not followed by a password but by a port number.Context
StackExchange Database Administrators Q#203142, answer score: 10
Revisions (0)
No revisions yet.