postgresql - 如何从自定义格式转储中恢复 postgres 数据库?
问题描述
我在使用 pg_restore 恢复数据库时遇到问题。我在运行 High Sierra (10.13.6) 的 Mac 上安装了 Postgres 12.2。它是用 Brew 安装的。
我用表“foo”创建了一个简单的数据库“foo”来测试它:
Nates-MacBook-Pro:k8s natereed$ psql -d foo
psql (12.2, server 12.1)
Type "help" for help.
foo=# SELECT table_schema,table_name
FROM information_schema.tables
WHERE table_schema='public' ORDER BY table_schema,table_name;
table_schema | table_name
--------------+------------
public | foo
(1 row)
生成转储:
pg_dump -Fc foo -f foo.backup
当我尝试恢复时,什么也没有发生。pg_restore 只是挂起:
pg_restore -h localhost -p 5432 -U postgres -v -Fc -f foo.backup
我已经尝试过这个命令的各种排列,但每次它只是挂起。在活动监视器中,我看到了进程,但它没有使用任何 CPU。
解决方案
在线帮助说:
pg_restore restores a PostgreSQL database from an archive created by pg_dump.
Usage:
pg_restore [OPTION]... [FILE]
General options:
-d, --dbname=NAME connect to database name
-f, --file=FILENAME output file name
-F, --format=c|d|t backup file format (should be automatic)
-l, --list print summarized TOC of the archive
-v, --verbose verbose mode
-V, --version output version information, then exit
-?, --help show this help, then exit
对于 pg_restore -f 是输出文件的参数:它不是输入文件。在您的示例中删除 -f :
pg_restore -h localhost -p 5432 -U postgres -v -Fc foo.backup
推荐阅读
- java - 在 XML 中,必须填写和添加附件的字段之一也是强制性的
- c++ - 用指针创建静态数组?
- javascript - 删除子元素jquery
- javascript - 修改模板内容失败
- java - jdbc:前端java,后端Oracle 10g express版
- angular - 打字稿版本 3.7.2 和 Angular
- combinations - 在概率上相同的项目被视为不同的项目?
- node.js - 如何将 vuejs - express 应用程序部署到本地 Ubuntu?
- node.js - 我的 API 的删除部分有什么问题?
- c++ - 为什么在这种情况下使用 new 和 std::unique_ptr 会导致崩溃?