agora inbox for pgsql-hackers@postgresql.org
help / color / mirror / Atom feedFrom: Álvaro Herrera <alvherre@kurilemu.de>
Subject: [PATCH] Revert replica identity to 'default' if the index is dropped
Date: Thu, 10 Sep 2026 12:21:16 +0200
---
contrib/test_decoding/expected/ddl.out | 6 +++---
src/backend/catalog/index.c | 12 ++++++++++++
src/backend/commands/tablecmds.c | 2 +-
src/include/commands/tablecmds.h | 4 ++++
4 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/contrib/test_decoding/expected/ddl.out b/contrib/test_decoding/expected/ddl.out
index a129c016d2b..b403d9e06cb 100644
--- a/contrib/test_decoding/expected/ddl.out
+++ b/contrib/test_decoding/expected/ddl.out
@@ -828,7 +828,7 @@ table public.table_dropped_index_with_pk: INSERT: a[integer]:2 b[integer]:2 c[in
table public.table_dropped_index_with_pk: INSERT: a[integer]:3 b[integer]:3 c[integer]:3
COMMIT
BEGIN
-table public.table_dropped_index_with_pk: UPDATE: a[integer]:4 b[integer]:1 c[integer]:1
+table public.table_dropped_index_with_pk: UPDATE: old-key: a[integer]:1 new-tuple: a[integer]:4 b[integer]:1 c[integer]:1
COMMIT
BEGIN
table public.table_dropped_index_with_pk: UPDATE: a[integer]:2 b[integer]:5 c[integer]:2
@@ -837,10 +837,10 @@ BEGIN
table public.table_dropped_index_with_pk: UPDATE: a[integer]:3 b[integer]:6 c[integer]:7
COMMIT
BEGIN
-table public.table_dropped_index_with_pk: DELETE: (no-tuple-data)
+table public.table_dropped_index_with_pk: DELETE: a[integer]:4
COMMIT
BEGIN
-table public.table_dropped_index_with_pk: DELETE: (no-tuple-data)
+table public.table_dropped_index_with_pk: DELETE: a[integer]:3
COMMIT
BEGIN
table public.table_dropped_index_no_pk: INSERT: a[integer]:1 b[integer]:1 c[integer]:1
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index ec21b83b6b8..144a7a6acc7 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -2352,6 +2352,18 @@ index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
TransferPredicateLocksToHeapRelation(userIndexRelation);
}
+ /*
+ * If this index is the replica identity of its table, mark the table as
+ * having default replica identity.
+ */
+ if (userHeapRelation->rd_rel->relreplident == REPLICA_IDENTITY_INDEX &&
+ RelationGetReplicaIndex(userHeapRelation) == indexId)
+ {
+ relation_mark_replica_identity(userHeapRelation, REPLICA_IDENTITY_DEFAULT,
+ InvalidOid, true);
+ CommandCounterIncrement();
+ }
+
/*
* Schedule physical removal of the files (if any)
*/
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8dc70bfa0f1..1040240f560 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -19065,7 +19065,7 @@ ATExecDropOf(Relation rel, LOCKMODE lockmode)
* Caller had better hold an exclusive lock on the relation, as the results
* of running two of these concurrently wouldn't be pretty.
*/
-static void
+void /* XXX removal of static not for commit */
relation_mark_replica_identity(Relation rel, char ri_type, Oid indexOid,
bool is_internal)
{
diff --git a/src/include/commands/tablecmds.h b/src/include/commands/tablecmds.h
index c3d8518cb62..22b5472d19c 100644
--- a/src/include/commands/tablecmds.h
+++ b/src/include/commands/tablecmds.h
@@ -45,6 +45,10 @@ extern void AlterTableInternal(Oid relid, List *cmds, bool recurse);
extern Oid AlterTableMoveAll(AlterTableMoveAllStmt *stmt);
+/* XXX not for commit */
+extern void relation_mark_replica_identity(Relation rel, char ri_type, Oid indexOid,
+ bool is_internal);
+
extern ObjectAddress AlterTableNamespace(AlterObjectSchemaStmt *stmt,
Oid *oldschema);
--
2.47.3
--csvqstbdygoam7e5--
Message-ID: <no-message-id-1745833@localhost>
Permalink: ../no-message-id-1745833@localhost/
Also on: postgresql.org/message-id/no-message-id-1745833@localhost
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: alvherre@kurilemu.de
Subject: Re: [PATCH] Revert replica identity to 'default' if the index is dropped
In-Reply-To: <no-message-id-1745833@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox