繁体   English   中英

如何将 pg_dump 文件恢复到 postgres 数据库中

[英]How to restore pg_dump file into postgres database

所以我定期使用 pgadmin4 备份和恢复数据库和架构。 我想使用 pg_dump 和 pg_restore 等命令使用批处理文件来完成。 然而,我总是无法成功,可以使用一些帮助。 我尝试转储一个模式(带有数据)的方式如下:

pg_dump -U postgres -F c -d database -n schema > mw2

然后我尝试用 pg_restore 恢复它:

pg_restore -U postgres -d otherdatabase -n schema mw2

首先,我尝试使用 .dump 代替 tar 但结果保持不变; 这是我的数据库中的一个空模式。

或以下错误消息:

pg_restore: [archiver] input file does not appear to be a valid archive

https://www.postgresql.org/docs/current/static/app-pgrestore.html

--format=format 指定存档格式。 没有必要指定格式,因为 pg_restore 会自动确定格式。 如果指定,它可以是以下之一:

自定义、目录和 tar

https://www.postgresql.org/docs/current/static/app-pgdump.html

--格式=格式

选择输出的格式。 格式可以是以下之一:

p plain 输出一个纯文本的 SQL 脚本文件(默认)。

其他是自定义、目录和 tar

简而言之 - 您使用了 defualt格式,这意味着与psql一起使用,而不是pg_restore 因此,要么使用pg_dump指定不同的格式,要么将您的文件用作

psql -f  mw2.tar

暂无
暂无

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

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