美文网首页
使用psql还原Postgres数据库方法

使用psql还原Postgres数据库方法

作者: 通靈鹿小六 | 来源:发表于2020-11-19 13:41 被阅读0次

1、问题说明

使用pgAdmin客户端工具还原pg数据库的备份时,有时候会出现因为格式不对导致的还原数据库错误的情况。如下图所示报错情况:

报错详细信息:

D:/Program Files/PostgreSQL/9.2/bin\pg_restore.exe --host localhost --port 5432 --username "postgres" --dbname "testdb" --no-password  --verbose "D:\db\db20201112.backup"
pg_restore: [归档] 输入文件看起来像是文本格式的dump. 请使用psql.

进程退出并返回 1。

2、使用psql

2.1、进入Postgres安装包的bin目录下面
cd C:\Program Files\PostgreSQL\9.2\bin
2.2、执行还原命令
psql -h localhost -U postgres -d test001 <  D:\databasebake\db20201112.backup

命令解释:

  • -U 后面是数据库用户名;
  • -d 后面的test001是要还原的数据库名称;
  • D:\databasebake\db20201112.backup 是数据库备份的路径;

点击“回车”,直接开始恢复数据库。

相关文章

网友评论

      本文标题:使用psql还原Postgres数据库方法

      本文链接:https://www.haomeiwen.com/subject/ypokiktx.html