将多个数据库从一个远程数据库移动到另一个 PostgreSQL 数据库中。

huangapple go评论59阅读模式
英文:

Move several databases from one remote database to another in PostgreSQL

问题

我必须将一个远程数据库中的多个表移动到另一个PostgreSQL数据库中。

根据我的理解,唯一的方法是通过使用pg_dump来完成。

pg_dump -h <source_db_host> -U <source_db_user> -d <source_db_name> -f database_dump.sql

psql -h <target_db_host> -U <target_db_user> -d <target_db_name> -f database_dump.sql

但是,由于目标数据库中的架构与源数据库中的不同,所以会出错,我会收到特定架构在源数据库中不存在的错误消息。

是否有任何方法可以更改目标架构?

是否有其他更简单的选项来传输数据集?

英文:

I have to move several tables from one remote database to another in PostgreSQL.

From my understanding the only way of doing it is via the pg_dump.

pg_dump -h &lt;source_db_host&gt; -U &lt;source_db_user&gt; -d &lt;source_db_name&gt; -f database_dump.sql

psql -h &lt;target_db_host&gt; -U &lt;target_db_user&gt; -d &lt;target_db_name&gt; -f database_dump.sql

However, it fails as the schema in destination database is different from the one in source, so I receive the error message that particular schema is not exist in source db.

Is there anyway how to change the destination schema?

Is there any other easier option for transferring the datasets?

答案1

得分: 1

以下是已翻译的内容:

可以使用带有 pg_dump 的模式选项

pg_dump -h &lt;source_db_host&gt; -U &lt;source_db_user&gt; -d &lt;source_db_name&gt; --schema=schema_name -f database_dump.sql 然后包括模式名称,或者您可以使用 pg_dumpall 来转储数据库和模式。

pg_dumpall -h &lt;source_db_host&gt; -U &lt;source_db_user&gt; -f database_dumpall.sql

psql -h &lt;target_db_host&gt; -U &lt;target_db_user&gt; -f database_dumpall.sql

您还可以查看 pg 文档 以获取更多关于 pg_dump 的见解。

英文:

You can either use the schema option with pg_dump

pg_dump -h &lt;source_db_host&gt; -U &lt;source_db_user&gt; -d &lt;source_db_name&gt; --schema=schema_name -f database_dump.sql then include the schema name or you can use pg_dumpall to dump both the databases and the schemas.

pg_dumpall -h &lt;source_db_host&gt; -U &lt;source_db_user&gt; -f database_dumpall.sql

psql -h &lt;target_db_host&gt; -U &lt;target_db_user&gt; -f database_dumpall.sql

You can also take a look at the pg Docs to get more insight into pg_dump

huangapple
  • 本文由 发表于 2023年8月5日 00:54:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76837854.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定