如何从自定义格式的转储中恢复 postgres 数据库?
How to restore a postgres database from a custom-format dump?
我在使用 pg_restore 恢复数据库时遇到问题。我在 Mac 运行 High Sierra (10.13.6) 上安装了 Postgres 12.2。它是用 Brew 安装的。
我用 table "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
我已经尝试过此命令的各种排列组合,但每次它都挂起。在 Activity 监视器中,我看到了进程,但它没有使用任何 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
我在使用 pg_restore 恢复数据库时遇到问题。我在 Mac 运行 High Sierra (10.13.6) 上安装了 Postgres 12.2。它是用 Brew 安装的。
我用 table "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
我已经尝试过此命令的各种排列组合,但每次它都挂起。在 Activity 监视器中,我看到了进程,但它没有使用任何 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