Re: Restore replication settings when modifying a field type
Quan Zongliang <quanzongliang@gmail.com>
From: Quan Zongliang <quanzongliang@gmail.com>
To: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: pgsql-hackers@postgresql.org
Date: 2019-11-05T00:37:17Z
Lists: pgsql-hackers
Attachments
- replidfieldtype.patch (text/plain) patch
On 2019/10/28 12:39, Kyotaro Horiguchi wrote: > Hello. > > # The patch no longer applies on the current master. Needs a rebasing. > New patch, rebased on master branch. > At Sat, 26 Oct 2019 16:50:48 +0800, Quan Zongliang <quanzongliang@gmail.com> wrote in >> In fact, the replication property of the table has not been modified, >> and it is still 'i'(REPLICA_IDENTITY_INDEX). But the previously >> specified index property 'indisreplident' is set to false because of >> the rebuild. > > I suppose that the behavior is intended. Change of column types on the > publisher side can break the agreement on replica identity with > subscribers. Thus replica identity setting cannot be restored > unconditionally. For (somewhat artifitial :p) example: > > P=# create table t (c1 integer, c2 text unique not null); > P=# alter table t replica identity using index t_c2_key; > P=# create publication p1 for table t; > P=# insert into t values (0, '00'), (1, '01'); > S=# create table t (c1 integer, c2 text unique not null); > S=# alter table t replica identity using index t_c2_key; > S=# create subscription s1 connection '...' publication p1; > > Your patch allows change of the type of c2 into integer. > > P=# alter table t alter column c2 type integer using c2::integer; > P=# update t set c1 = c1 + 1 where c2 = '01'; > > This change doesn't affect perhaps as expected. > > S=# select * from t; > c1 | c2 > ----+---- > 0 | 00 > 1 | 01 > (2 rows) > > >> So I developed a patch. If the user modifies the field type. The >> associated index is REPLICA IDENTITY. Rebuild and restore replication >> settings. > > Explicit setting of replica identity premises that they are sure that > the setting works correctly. Implicit rebuilding after a type change > can silently break it. > > At least we need to guarantee that the restored replica identity > setting is truly compatible with all existing subscribers. I'm not > sure about potential subscribers.. > > Anyway I think it is a problem that replica identity setting is > dropped silently. Perhaps a message something like "REPLICA IDENTITY > setting is lost, please redefine after confirmation of compatibility > with subscribers." is needed. > > regards. >
Commits
-
Preserve replica identity index across ALTER TABLE rewrite
- c15d35041206 9.5.22 landed
- 2f0dd9d93efe 9.6.18 landed
- 02530da73f04 10.13 landed
- 15cbbf81a58f 11.8 landed
- c9ef507e82eb 12.3 landed
- 1cc9c2412cc9 13.0 landed
-
Prevent reindex of invalid indexes on TOAST tables
- 61d7c7bce368 13.0 cited