dump的文件 查看pg_如何将pg_dump文件还原到Postgres数据库

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

Then I try to restore it with pg_restore:

pg_restore -U postgres -d otherdatabase -n schema mw2

First I tried to use .dump in stead of tar but the result stays the same; which is an empty schema in my database.

Or the following error message:

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

解决方案--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:

custom, directory and tar

--format=format

Selects the format of the output. format can be one of the following:

p plain Output a plain-text SQL script file (the default).

others are custom, directory and tar

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值