如何导出本地 Postgres 数据库中的一些数据并将其导入远程而不删除远程中的所有数据?

How do I export some data my local Postgres db and import it to a remote without deleting all the data from the remote?

我在 Mac Sierra 上使用 Postgres 9.5。我想从我的本地计算机导出一些 table 数据并将其导入到 Linux 计算机上的 Postgres 9.5 数据库中。请注意,我不想破坏 Linux 机器上的数据,只将我的本地机器 table 行添加到 table 中已经存在的行中 Linux 环境(并忽略重复项)。所以在我的本地机器上,我 运行

pg_dump -U myusername --format custom --section data --inserts --file "t1.backup" --table "table1" --table "table2" --table "addresses" "mydb"

但是在我的远程机器上,当我尝试导入文件时,出现错误

myuser@remote-machine:/tmp$ psql db_production < t1.backup
The input is a PostgreSQL custom-format dump.
Use the pg_restore command-line client to restore this dump to a database.

但我不想使用pg_restore,因为我不想删除现有的table数据,我只是想添加它。我怎样才能做到这一点?

使用 --format plain 而不是 custom 一个。后者专门用于 pg_restore。纯格式还允许您使用文本编辑器查看转储数据并验证这是否是您想要的。

但是我的快速测试表明,也可以使用 pg_restore 和自定义格式的仅数据转储来附加数据:

pg_restore -d db_production --data-only t1.backup