postgresql 无法使用 pg_restore 恢复 Postgres 的转储备份文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29634404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:51:53  来源:igfitidea点击:

Can't restore a dump backup file for Postgres using pg_restore

postgresqlpsql

提问by Eki Eqbal

I generated a dump backup file for my Postgres 9.3.4 using this:

我使用这个为我的 Postgres 9.3.4 生成了一个转储备份文件:

pg_dump table_name -U myusername -h localhost -O > backup.dump

Now I'm trying to backup the old database using:

现在我正在尝试使用以下方法备份旧数据库:

pg_restore -U myusername -n public -d table_name  backup.dump

But I keep getting this error:

但我不断收到此错误:

pg_restore: [archiver] input file appears to be a text format dump. Please use psql.

Please note that the file is not plain sql file since I generated it using pg_dump.

请注意,该文件不是普通的 sql 文件,因为我使用 pg_dump 生成了它。

I used the follwoing command:

我使用了以下命令:

psql perchwell -U myusername -f backup.dump -v ON_ERROR_STOP=1

and start receiving the following error:

并开始收到以下错误:

SET
SET
SET
SET
SET
SET
psql:backup.dump:16: ERROR:  schema "propertydir" already exists

回答by Eelke

The default output format of pg_dump is actually plaintext sql script. So use psql for import or redump with the -Fcflag.

pg_dump 的默认输出格式实际上是明文 sql 脚本。因此,使用 psql 进行带有-Fc标志的导入或重新转储。

回答by Tejas Tank

Your bug: pg_restore: [archiver] input file appears to be a text format dump. Please use psql

您的错误:pg_restore: [archiver] 输入文件似乎是文本格式转储。请使用 psql

Bug indicate use psql command to import database.

Bug 表示使用 psql 命令导入数据库。

cat your-dump-pg-file.dump | psql -d your-database

This way, you can easily restore file

这样,您可以轻松地恢复文件

In additionally if you set character set UTF-8, will make better import too.

另外如果你设置字符集UTF-8,也会更好的导入。