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

问题描述 投票:0回答:2

我已经备份了我想要恢复到新数据库中的特定表,使用:

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

我没有问题。

然后我想通过使用 pg_restore 创建一个新数据库来恢复转储:

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

这给了我一个“数据库临时不存在”的错误。据我所知,这应该已经创建并恢复了数据库。

I 然而,然后手动创建“临时”数据库并运行:

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

这跟进了,但没有创建表并给我一个错误“关系表 1”和“关系表 2”不存在,只为两个表创建相应的 id_sequences。

我真正想要的是不必手动创建新数据库,并且备份中的所有表都通过 pg_restore 恢复到一个全新的数据库中,使用:

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

据我了解。

postgresql psql exists pg-dump pg-restore
2个回答
3
投票

为了创建数据库

temp
pg_restore
需要先连接到不同的数据库。

所以用

-d temp
不行;你必须指定一个现有的数据库,通常是
postgres
.

pg_restore
将连接到该数据库,发出
CREATE DATABASE temp
,连接到
temp
并继续恢复数据。


0
投票

对我来说,我安装了 pgAdmin 4 并通过 pgAdmin 4 UI 进行了恢复,而不是通过 cmd 进行恢复:

pg_restore -d <database_name> -p 5432 -Fc -O -a --no-tablespaces --no-privileges -v -U postgres -j 8 <database_name>.dmp
© www.soinside.com 2019 - 2024. All rights reserved.