如何将 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 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
--格式=格式
Selects the format of the output. format can be one of the following:
p plain Output a plain-text SQL script file (the default).
其他是自定义、目录和tar
简而言之 - 您使用了默认的 plain 格式,这是为了与 psql
一起使用,而不是 pg_restore
。因此,要么使用 pg_dump
指定不同的格式,要么将您的文件用作
psql -f mw2.tar
所以我定期使用 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 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
--格式=格式
Selects the format of the output. format can be one of the following:
p plain Output a plain-text SQL script file (the default).
其他是自定义、目录和tar
简而言之 - 您使用了默认的 plain 格式,这是为了与 psql
一起使用,而不是 pg_restore
。因此,要么使用 pg_dump
指定不同的格式,要么将您的文件用作
psql -f mw2.tar