您将如何在 sql 脚本或存储过程中连接到两个 postgres 数据库?

How would you connect to two postgres databases in a sql script or a stored procedure?

我需要将一些旧数据从一个数据库移动到另一个数据库 - 两者都有相似的架构。在 db1.mytable 中的旧行插入到 db2.mytable 之后 - 这些相同的行应该从 db1.mytable 中删除。

这是减少数据库大小和存档数据,虽然不是那么需要但仍然很重要。

您应该为 Postgres 使用外部数据包装器 - https://www.postgresql.org/docs/current/static/postgres-fdw.html使用外部表,您可以将查询发送到另一个数据库。