Postgresql 如何从自定义格式转储恢复postgres数据库?
我在使用pg_restore进行数据库还原时遇到问题。我已经在Mac上安装了Postgres 12.2,运行High Sierra(10.13.6)。它是用Brew安装的 我用表“foo”创建了一个简单的数据库“foo”,以测试这一点:Postgresql 如何从自定义格式转储恢复postgres数据库?,postgresql,pg-restore,Postgresql,Pg Restore,我在使用pg_restore进行数据库还原时遇到问题。我已经在Mac上安装了Postgres 12.2,运行High Sierra(10.13.6)。它是用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 FR
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_还原刚刚挂起:
pg_restore -h localhost -p 5432 -U postgres -v -Fc -f foo.backup
我尝试过这个命令的各种排列,但每次都挂起。在Activity Monitor中,我看到了进程,但它没有使用任何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.Nates MacBook Pro:k8s natereed$pg_restore-h localhost-p 5432-U natereed-v-Fc pg_restore:错误:必须指定-d/--dbname和-f/--file中的一个文件。请说明我希望从备份中创建数据库。必须指定要从中还原的文件或数据库之一。指定要从中恢复的备份文件的正确方法是什么?输出文件名(-f)不是指我们要从中还原的文件吗?@NateReed:“
-f
为生成的脚本或与-l一起使用时的列表指定输出文件”Try:pg\U restore-h localhost-p 5432-U postgres-v-C-d-Fc foo.backup
。(-C表示创建数据库)。-f
指定输出文件,而不是输入文件。从命令行中删除-f
-最后一个参数(不带“开关”)指定输入文件(如手册中所述):pg\U restore-h localhost-p 5432-U postgres-v-Fc foo.backup