简体   繁体   English

pg_restore错误:“关系不存在”并创建新数据库

[英]pg_restore ERROR: “Relation does not exist” and creating new database

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: 然后,我想通过使用pg_restore创建一个新数据库来还原转储:

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. 这会继续进行,但不会创建表,并且给我一个错误“ relation table1”和“ relation table2”不存在,并且只会为两个表创建相应的id_sequences。

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: 我真正想要的是不必手动创建新数据库,并且可以使用以下命令通过pg_restore将备份中的所有表还原到全新的数据库中:

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

as I understand it. 据我了解。

In order to create the database temp , pg_restore needs to be connected to a different database first. 为了创建数据库temp ,首先需要将pg_restore连接到另一个数据库。

So it won't do to use -d temp ; 因此,使用-d temp不会-d temp you must specify an existing database, typically postgres . 您必须指定一个现有数据库,通常是postgres

pg_restore will connect to that database, issue CREATE DATABASE temp , connect to temp and proceed to restore the data. pg_restore将连接到该数据库,发出CREATE DATABASE temp ,连接到temp并继续还原数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM