我可以在同一个 postgres 服务器中的 2 个数据库之间进行逻辑复制吗?

Can I have a logical replication between 2 databases in the same postgres server?

我正在两个不同应用程序的数据库之间创建逻辑复制。但是在开发环境中,我的数据库保留在同一个 postgres docker 容器中。

我的应用程序使用 rails,因此我创建了一个迁移以创建来自发布者的订阅。但是当我 运行 它时,它就永远存在。如果我创建另一个容器并将数据库分开,订阅就会膨胀。

无论如何我可以在同一个容器中做到 运行 吗?

看起来您 运行 了解 the docs 中阐明的警告,需要遵循那里描述的两步程序:

Creating a subscription that connects to the same database cluster (for example, to replicate between databases in the same cluster or to replicate within the same database) will only succeed if the replication slot is not created as part of the same command. Otherwise, the CREATE SUBSCRIPTION call will hang. To make this work, create the replication slot separately (using the function pg_create_logical_replication_slot with the plugin name pgoutput) and create the subscription using the parameter create_slot = false.