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

From: Sami Imseih <samimseih(at)gmail(dot)com>
To: Alberto Piai <alberto(dot)piai(at)gmail(dot)com>
Cc: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Xuneng Zhou <xunengzhou(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Robert Treat <rob(at)xzilla(dot)net>
Subject: Re: tablecmds: fix bug where index rebuild loses replica identity on partitions
Date: 2026-07-27 23:11:23
Message-ID: CAA5RZ0tq2Oj6Vkjt06phsDWpywsS=VkBSV7n6LC++pR5LLNU-A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Also, this issue is not limited to replica identity. CLUSTER ON does
> not copy/restore indisclustered on partition indexes at all, and this
> should be addressed as well, right?

Robert (cc'd) reminded me offline that REPACK ... USING INDEX ==
CLUSTER ON.

Here is a repro, and CLUSTER ON also shows the same behavior.

```
postgres=# CREATE TABLE test_cluster_multi (a int NOT NULL, b int NOT
NULL) PARTITION BY RANGE (a);
CREATE TABLE
postgres=# CREATE TABLE test_cluster_multi_p1 PARTITION OF test_cluster_multi
postgres-# FOR VALUES FROM (0) TO (100);
CREATE TABLE
postgres=# CREATE INDEX test_cluster_multi_idx ON test_cluster_multi (a, b);
CREATE INDEX
postgres=# CREATE INDEX test_cluster_multi_other ON test_cluster_multi (b);
CREATE INDEX
postgres=# --CLUSTER test_cluster_multi_p1 USING test_cluster_multi_p1_a_b_idx;
postgres=# REPACK test_cluster_multi_p1 USING INDEX
test_cluster_multi_p1_a_b_idx;
REPACK
postgres=# SELECT tc.relname AS table_name, ic.relname AS index_name,
i.indisclustered
postgres-# FROM pg_index i
postgres-# JOIN pg_class tc ON i.indrelid = tc.oid
postgres-# JOIN pg_class ic ON i.indexrelid = ic.oid
postgres-# WHERE tc.relname = 'test_cluster_multi_p1'
postgres-# ORDER BY ic.relname;
table_name | index_name | indisclustered
-----------------------+-------------------------------+----------------
test_cluster_multi_p1 | test_cluster_multi_p1_a_b_idx | t
test_cluster_multi_p1 | test_cluster_multi_p1_b_idx | f
(2 rows)

postgres=# ALTER TABLE test_cluster_multi ALTER COLUMN b TYPE bigint;
ALTER TABLE
postgres=# SELECT tc.relname AS table_name, ic.relname AS index_name,
i.indisclustered
postgres-# FROM pg_index i
postgres-# JOIN pg_class tc ON i.indrelid = tc.oid
postgres-# JOIN pg_class ic ON i.indexrelid = ic.oid
postgres-# WHERE tc.relname = 'test_cluster_multi_p1'
postgres-# ORDER BY ic.relname;
table_name | index_name | indisclustered
-----------------------+-------------------------------+----------------
test_cluster_multi_p1 | test_cluster_multi_p1_a_b_idx | f
test_cluster_multi_p1 | test_cluster_multi_p1_b_idx | f
(2 rows)

postgres=# DROP TABLE test_cluster_multi;
DROP TABLE
```

--
Sami Imseih
Amazon Web Services (AWS)

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Bharath Rupireddy 2026-07-27 23:00:00 Re: Fix race condition in pg_get_publication_tables with concurrent DROP TABLE