英文:
pg_restore using improper database name
问题
I want copy a 'local' postgres database, which living in docker, into remote machine. Local docker's database have default name postgres
, and remote have proddb
. I run following command:
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
In the terminal, i see that this command creating postgres
database instead 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
Why pg_restore ignored specified dbname
key?
英文:
I want copy a 'local' postgres database, which living in docker, into remote machine. Local docker's databse have default name postgres
, and remote have proddb
. I run following command:
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
In the terminal, i see that this command creating postgres
database instead 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
Why pg_restore ignored specified dbname
key?
答案1
得分: 2
If you use the --create
option with pg_restore
, the restore process will first execute:
使用 `pg_restore` 的 `--create` 选项,还原过程将首先执行:
CREATE DATABASE postgres;
then connect to the new database with:
然后连接到新数据库:
\c postgres
and proceed to restore the dump.
然后继续还原备份。
If you additionally add --clean
, pg_restore
will first execute:
如果您另外添加 --clean
,pg_restore
将首先执行:
DROP DATABASE postgres;
So the database you connect to with pg_restore
is irrelevant, because pg_restore
will create and connect to database postgres
anyway.
因此,您连接到的数据库与 pg_restore
无关,因为 pg_restore
无论如何都会创建并连接到数据库 postgres
。
If you want to restore the dump to a different database, omit the --create
option, so that pg_restore
connects to proddb
and restores the dump to that database.
如果您想将备份还原到不同的数据库,请省略 --create
选项,这样 pg_restore
将连接到 proddb
并还原备份到该数据库。
英文:
If you use the --create
option with pg_restore
, the restore process will first execute
CREATE DATABASE postgres;
then connect to the new database with
\c postgres
and proceed to restore the dump.
If you additionally add --clean
, pg_restore
will first execute
DROP DATABASE postgres;
So the database you connect to with pg_restore
is irrelevant, because pg_restore
will create and connect to database postgres
anyway.
If you want to restore the dump to a different database, omit the --create
option, so that pg_restore
connects to proddb
and restores the dump to that database.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论