PostgreSQL逻辑复制自定义列表达式

发布于 2025-02-05 09:27:30 字数 945 浏览 3 评论 0原文

我正在尝试PostgreSQL15逻辑复制。

我在数据库中有一个名为“ test”的表“ test1”,带有列“ ID” int(primary)和“ name” varchar

id int (primary) | name varchar

i也有一个名为“ test”的表“ test”,test0“ test0”列,带“租户” int(primary) ,“ id” int(primary)和“ name varchar

tenant int (primary/default=1) | id int (primary) | name varchar

i i在数据库“ test1”上都有以下发布者,

CREATE PUBLICATION pb_test FOR TABLE test ("id", "name")
SELECT pg_create_logical_replication_slot('test_slot_v1', 'pgoutput');

我还具有以下订户数据库“ test0”。

CREATE SUBSCRIPTION sb_test CONNECTION 'dbname=test1 host=localhost port=5433 user=postgres password=*********' PUBLICATION pb_test WITH (slot_name = test_slot_v1, create_slot = false);

结果是,每次在数据库“ test1”上添加新记录时,然后将同一记录插入带有租户= 1的数据库“ test0”上,就像默认值一样。

问题是,在复制时,有什么方法可以在此附加列“租户”中获得自定义表达式?例如,来自数据库“ Test1”的记录应具有租户= 1,但来自数据库“ Test2”的记录将具有房客= 2。

I am experimenting with PostgreSQL15 logical replication.

I have a table called "test" in database "test1" with columns "id" int (primary) and "name" varchar

id int (primary) | name varchar

I also have a table called "test" in database "test0" with columns "tenant" int (primary), "id" int (primary) and "name" varchar

tenant int (primary/default=1) | id int (primary) | name varchar

I have the following publisher on database "test1"

CREATE PUBLICATION pb_test FOR TABLE test ("id", "name")
SELECT pg_create_logical_replication_slot('test_slot_v1', 'pgoutput');

I also have the following subscriber database "test0"

CREATE SUBSCRIPTION sb_test CONNECTION 'dbname=test1 host=localhost port=5433 user=postgres password=*********' PUBLICATION pb_test WITH (slot_name = test_slot_v1, create_slot = false);

The result is that every time a new record is added on the database "test1", then the same record is inserted on database "test0" with tenant=1 as is the default value.

The question, is there any way to have custom expression for this additional column "tenant" while being replicated? For example records coming from database "test1" should have tenant=1 but records coming from database "test2" will have tenant=2.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

胡大本事 2025-02-12 09:27:30

似乎当前,PostgreSQL14逻辑复制不支持此要求具有具有固定值的其他列。

更新

postgresql15允许在表的列的子集上发布和订阅,但仍然不支持自定义表达式作为键或值列

Seems that currently, PostgreSQL14 Logical Replication does not support this requirement to have additional columns with fixed values.

UPDATE

PostgreSQL15 allows to publish and subscribe on subset of columns of a table but still is not supporting custom expression as key or value column

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文