我想复制一个'本地' postgres数据库,其中生活在docker,到远程机器。本地docker的数据库默认名称为postgres
,远程为proddb
。我运行以下命令:
pg_dump --format=custom --dbname=postgresql://postgres:postgres@localhost:5432/postgres | PGPASSWORD=pa$$word pg_restore -v --clean --create --host=production.local --username=swasher --dbname=proddb
在终端中,我看到这个命令创建postgres
数据库,而不是proddb
:
pg_restore: connecting to database for restore
pg_restore: dropping DATABASE postgres
pg_restore: creating DATABASE "postgres"
pg_restore: connecting to new database "postgres"
pg_restore: creating COMMENT "DATABASE postgres"
pg_restore: creating EXTENSION "hstore"
pg_restore: creating COMMENT "EXTENSION hstore"
pg_restore: terminated by user
为什么pg_restore忽略指定的dbname
键?
1条答案
按热度按时间h43kikqp1#
如果将
--create
选项与pg_restore
配合使用,则将首先执行恢复进程然后使用连接到新数据库
并继续恢复转储。
如果另外添加
--clean
,则pg_restore
将首先执行因此,使用
pg_restore
连接的数据库是无关紧要的,因为pg_restore
无论如何都会创建并连接到数据库postgres
。如果要将转储还原到其他数据库,请忽略
--create
选项,以便pg_restore
连接到proddb
并将转储还原到该数据库。