Re: tablecmds: fix bug where index rebuild loses replica identity on partitions

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: tablecmds: fix bug where index rebuild loses replica identity on partitions
Date: 2026-01-27 08:30:10
Message-ID: F42E6546-E46B-46FE-9C21-30BD289259AE@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Jan 27, 2026, at 15:59, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>
>
>
>> On Jan 27, 2026, at 15:39, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>>
>> On Tue, Jan 27, 2026 at 01:13:32PM +0800, Chao Li wrote:
>>> I found this bug while working on a related patch [1].
>>>
>>> When ALTER TABLE ... ALTER COLUMN TYPE causes an index rebuild, and
>>> that index is used as REPLICA IDENTITY on a partitioned table, the
>>> replica identity marking on partitions can be silently lost after the
>>> rebuild.
>>
>> I am slightly confused by the tests included in the proposed patch.
>> On HEAD, if I undo the proposed changes of tablecmds.c, the tests
>> pass. If I run the tests of the patch with the changes of
>> tablecmds.c, the tests also pass.
>
> Oops, that isn’t supposed to be so. I’ll check the test.
>

Okay, I see the problem is here:
```
+CREATE UNIQUE INDEX test_replica_identity_partitioned_pkey ON test_replica_identity_partitioned (id);
```

I missed to add column “val” into the index, so that alter type of val didn’t cause index rebuild.

Ideally, it’s better to also verify that index OIDs should have changed before and after alter column type, but I haven’t figured out how to do so. Do you have an idea?

Please see v2, the test should fail on master now.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachment Content-Type Size
v2-0001-tablecmds-fix-bug-where-index-rebuild-loses-repli.patch application/octet-stream 20.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Jones 2026-01-27 08:36:54 Re: display hot standby state in psql prompt
Previous Message jian he 2026-01-27 08:27:03 could not find replacement targetlist entry for attno -6