如何将pg_dump文件还原到Postgres数据库 [英] How to restore pg_dump file into postgres database
问题描述
因此,我定期使用pgadmin4备份和还原数据库和架构。我想使用批处理文件使用pg_dump和pg_restore命令来执行此操作。但是,我总是无法成功完成此工作,可以使用一些帮助。我尝试转储一个模式(带有数据)的方式如下:
So I regularly backup and restore databases and schema's using pgadmin4. I would like to do it with a batch file using commands as pg_dump and pg_restore. I however always fail to succeed in this and could use some help. The way I try to dump one schema (with data) is the following:
pg_dump -U postgres -F c -d database -n schema > mw2
然后我尝试使用pg_restore还原它:
Then I try to restore it with pg_restore:
pg_restore -U postgres -d otherdatabase -n schema mw2
首先,我尝试使用.dump代替tar,但是结果保持不变;
First I tried to use .dump in stead of tar but the result stays the same; which is an empty schema in my database.
或以下错误消息:
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将自动确定格式
。如果指定,则可以是以下之一:
--format=format Specify format of the archive. It is not necessary to specify the format, since pg_restore will determine the format automatically. If specified, it can be one of the following:
自定义,目录和tar
https:// www .postgresql.org / docs / current / static / app-pgdump.html
-format = format
--format=format
选择输出格式。格式可以是以下格式之一:
Selects the format of the output. format can be one of the following:
p plain输出纯文本SQL脚本文件(默认)。
p plain Output a plain-text SQL script file (the default).
其他自定义,目录和tar
简而言之-您使用的是默认格式 格式,该格式是用于 psql
而不是 pg_restore
的格式。因此,要么使用 pg_dump
指定其他格式,要么将文件用作
in short - you used defualt plain format, which is meant for using with psql
, not pg_restore
. So either specify different format with pg_dump
or use your file as
psql -f mw2.tar
这篇关于如何将pg_dump文件还原到Postgres数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!