无法更新 table Temp Table 因为它没有副本身份并在 Postgres 中发布更新
cannot update table Temp Table because it does not have a replica identity and publishes updates in Postgres
我使用带复制功能的 Postgres 数据库。
我在 postgres 函数中使用了 temp table 。我无法在通过加入更新 Temp Table 时更新它。
下面是 Postgres 查询(tempallergyupdates
是临时 table):
drop table if exists tempallergyupdates;
create temp table tempallergyupdates(patientallergyid int,updateid int, newupdateid int);
update tempallergyupdates set patientallergyid = 1;
以上查询抛出以下异常:
cannot update table "tempallergyupdates" because it does not have a
replica identity and publishes updates
我们刚刚遇到这个问题并找到了解决方案。事实证明,PostgreSQL 不喜欢 tables,甚至是临时 tables,它们缺少涉及复制的主键。因此,要么将一个添加到您的临时 table 中,要么在创建 table:
之后使用这样的语句
ALTER TABLE table_name REPLICA IDENTITY FULL;
REPLICA IDENTITY FULL 使用字段中的标准数据类型。
ALTER TABLE table_name REPLICA IDENTITY FULL;
但是,当出现 json 字段时,您会看到如下消息:
ERROR: could not identify an equality operator for type json
background worker logical replication worker exited with exit code 1
在这种情况下,您必须添加一个新的唯一索引,可能添加一个序列列或简单地跳过 json 字段或添加一个新的 PK 等。
告诉副本进程使用这个索引。
/* id is a new serial column */
create unique index concurrently idx_someid on tablename (id);
alter table tablename REPLICA IDENTITY USING INDEX concurrently;
我使用带复制功能的 Postgres 数据库。
我在 postgres 函数中使用了 temp table 。我无法在通过加入更新 Temp Table 时更新它。
下面是 Postgres 查询(tempallergyupdates
是临时 table):
drop table if exists tempallergyupdates;
create temp table tempallergyupdates(patientallergyid int,updateid int, newupdateid int);
update tempallergyupdates set patientallergyid = 1;
以上查询抛出以下异常:
cannot update table "tempallergyupdates" because it does not have a replica identity and publishes updates
我们刚刚遇到这个问题并找到了解决方案。事实证明,PostgreSQL 不喜欢 tables,甚至是临时 tables,它们缺少涉及复制的主键。因此,要么将一个添加到您的临时 table 中,要么在创建 table:
之后使用这样的语句ALTER TABLE table_name REPLICA IDENTITY FULL;
REPLICA IDENTITY FULL 使用字段中的标准数据类型。
ALTER TABLE table_name REPLICA IDENTITY FULL;
但是,当出现 json 字段时,您会看到如下消息:
ERROR: could not identify an equality operator for type json background worker logical replication worker exited with exit code 1
在这种情况下,您必须添加一个新的唯一索引,可能添加一个序列列或简单地跳过 json 字段或添加一个新的 PK 等。
告诉副本进程使用这个索引。
/* id is a new serial column */
create unique index concurrently idx_someid on tablename (id);
alter table tablename REPLICA IDENTITY USING INDEX concurrently;