首页 > 解决方案 > 如何从自定义格式转储中恢复 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。

标签: postgresqlpg-restore

解决方案


在线帮助说:

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

推荐阅读