Zue*_*nie 4 postgresql pg-dump pg-restore
所以我定期使用 pgadmin4 备份和恢复数据库和模式。我想使用 pg_dump 和 pg_restore 命令通过批处理文件来完成此操作。然而,我总是无法成功,需要一些帮助。我尝试转储一个模式(带有数据)的方法如下:
pg_dump -U postgres -F c -d database -n schema > mw2
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用 pg_restore 恢复它:
pg_restore -U postgres -d otherdatabase -n schema mw2
Run Code Online (Sandbox Code Playgroud)
首先,我尝试使用 .dump 代替 tar,但结果保持不变;这是我的数据库中的空架构。
或者出现如下错误信息:
pg_restore: [archiver] input file does not appear to be a valid archive
Run Code Online (Sandbox Code Playgroud)
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
简而言之 - 您使用了默认纯格式,这意味着与 一起使用psql,而不是pg_restore. 因此,要么指定不同的格式,pg_dump要么使用您的文件作为
psql -f mw2.tar
Run Code Online (Sandbox Code Playgroud)