pg_restore 不工作 - 输入文件似乎不是有效的存档

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

我正在使用 -

做 pg_dump
pg_dump -U <username> -h <host> <database> > backup.sql

pg_dump 工作正常。 我正在尝试做 pg_restore 做 -

pg_restore -U <username> -h <host> -d <databse> backup.sql

然后显示 pg_restore: error: input file does not appear to be a valid archive

我已经检查了很多关于这个的 StackOverflow 答案,但我什么都想不通。请帮我。提前致谢。

更新:根据评论,我们不能将 pg_restore 用于 .sql 文件。实际上我有一个限制,我必须使用 pg_restore 命令来恢复数据库。您能否提供 pg_dump 命令,我可以使用该命令使用 pg_restore 恢复它?

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

您创建了一个纯格式转储,它是一个 SQL 文件。您必须使用

psql
:

恢复纯格式转储
psql -U <username> -h <host> -d <databse> -f backup.sql

pg_restore
用于恢复所有其他格式的转储。通过将适当的
-F
选项与
pg_dump
一起使用,您可以获得其他格式的转储:例如,
-F c 
生成自定义格式转储。

如果您想使用

psql
以外的客户端恢复纯格式转储,您必须使用选项
--inserts
创建它。


0
投票

在我的例子中,我使用 nohup 输出 pg_dump,因为它很耗时,这混淆了重定向器并在文件中混合了不必要的数据,导致错误(pg_restore:错误:输入文件似乎不是有效的存档)。

nohup pg_dump *** > output.dump > nohup.out &

pg_dump:调试:为 pg_partitioned_table 重新散列目录缓存 id 41; 65 把,32 桶 pg_dump:调试:为 pg_partitioned_table 重新散列目录缓存 id 41; 129 把,64 桶 pg_dump:调试:为 pg_partitioned_table 重新散列目录缓存 id 41; 257 把,128 桶 pg_dump:调试:为 pg_statistic 重新散列目录缓存 id 59; 257 把,128 桶 pg_dump:调试:为 pg_opclass 重新散列目录缓存 id 14; 17 把,8 个桶

© www.soinside.com 2019 - 2024. All rights reserved.