小编iai*_*ain的帖子

pg_restore 到一个新的数据库

我正在使用 Heroku 的 Postgres 选项并从中下载了一个备份。我想将它恢复到一个新的数据库中,以便我可以查看它。我一直在尝试不同的命令,但收效甚微。我的第一次尝试:

$ sudo -u postgres psql < db/backups/myapp_2018-05-27.pg.dump 
The input is a PostgreSQL custom-format dump.
Use the pg_restore command-line client to restore this dump to a database.
Run Code Online (Sandbox Code Playgroud)

所以我尝试:

$ sudo -u postgres pg_restore -d myapp3 -C db/backups/myapp_2018-05-27.pg.dump
pg_restore: [archiver (db)] connection to database "myapp3" failed: FATAL:  database "myapp3" does not exist
Run Code Online (Sandbox Code Playgroud)

我真的不明白这个-C选项

-C --创建

在恢复之前创建数据库。如果还指定了 --clean,则在连接之前删除并重新创建目标数据库。

使用此选项时,以 -d 命名的数据库仅用于发出初始 DROP DATABASE 和 CREATE DATABASE 命令。所有数据都恢复到出现在存档中的数据库名称。

恢复到新数据库对我来说似乎是合乎逻辑的。我离题了……(也许这里已经正确解释

我尝试从另一个具有相同架构的较早版本的模板创建一个新数据库:

$ …
Run Code Online (Sandbox Code Playgroud)

postgresql restore pg-restore

14
推荐指数
2
解决办法
2万
查看次数

标签 统计

pg-restore ×1

postgresql ×1

restore ×1