Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x4cLA-007HL6-2a for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Sep 2026 10:49:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x4cL9-004W3w-2f for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Sep 2026 10:49:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x4cJi-004G6v-1L for pgsql-hackers@lists.postgresql.org; Thu, 10 Sep 2026 10:47:42 +0000 Received: from flow-b2-smtp.messagingengine.com ([202.12.124.137]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x4bvl-00000004w0z-2SWi for pgsql-hackers@postgresql.org; Thu, 10 Sep 2026 10:22:58 +0000 Received: from phl-compute-08.internal (phl-compute-08.internal [10.202.2.48]) by mailflow.stl.internal (Postfix) with ESMTP id 6E4251300DE7; Thu, 10 Sep 2026 06:22:56 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Thu, 10 Sep 2026 06:22:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kurilemu.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to; s=fm2; t=1789035776; x= 1789042976; bh=tFSgH+ocXEuqgk6E79FlSDggwWAS9tqnTyPyh5pZjxw=; b=B DQB25fk2E+TH0Y8vqVOiaZiZzAJrLkF4BCyfVruRsZfklLJ34bu82qE8m1GDJdd2 U4STAA1GbzzIJvFq7rG7hFtuNRbjCaX72JABKevmCJaORBYbO/WTUunpAKtHDV7w OT4Afggj8q/iIo3fyPbotPsL812JojKUgdGDiZffhwovI2cUki+qiKLbP+297mvw 62dWvTrlQwywINmHmrYLDWL/LEeW6bSmP12MsmaGVbJL5IyxnyUYQ5Z08hMdwsFO 8QXxJiwWfwD95x3/pudERuCK/yQyjvelzpsKi43BEbTEPjLZiXXEX7AQ/4rsg0oc 07zYS1Cka2VIU+CjaUC0Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1789035776; x=1789042976; bh=t FSgH+ocXEuqgk6E79FlSDggwWAS9tqnTyPyh5pZjxw=; b=ccWQ4vm6v9+ohGR2r N87hpbC5vKfRkWQy4z07hdii4TjceJk2SnfcOiOfZ1thhh0vzaUaU0OlAR1JRtTj joRvXmVj+Rr7Ax0ftYb/XDfBop8+lMI7vWxNX0GftUS7FwN235mxG5ltXWizC1KT /zmznSYnx1ubgLRSao99xdLAtBPBycogNcsbs7uv51vfre9By4dyXUu2cbXIqyIB jBftXK3TRYOtz2AvupDY1q6AmCfAvNUATCe25fJ9CoeGl855CXdOb7taojjisMCN QbtYvi7nFm3u+qdLiLeKkF1ll9Ssx9DEW6CSlyT0Tk04eqrOhTZxf0WKyxRbp8cS 54WRQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGuDpYjvGzKXVf8VoR0xqsS5uBoidAvsb+HbPuvFRM0w3UHB5UIYFlAaAUAkWuGC8 Mqpsb1PVMyM2RNAjfRW4MI9aP1eSTZ8UzaSm8tK0WTDONrEriVEU9I3zaZjm0t067PyS/s wqA1aSTw6ztgMssWrS2JyJd0px2jfy8j3iByeenjoR0JufgGgLV5C2dzVERnPd4hTEH2Za CZiy+pLYmQ4SNaS6hsS//amX+kW82tb64Bfia5IPnlMX9OdjwES5URWBUbuE4FcB+lJomj KxTwzto0aAOLZ1RHh/CKjU4IIYuC+ZL94YJiEMj+UnhLyhp0R8GdKV2ieu0+6rJVBEJrVv r/lXK1Gsp81NW6zVYM3C1gUcek+1NFWFuYu2fLho1E5Wy3cXigQ0euJcovLpxjnKKWpL9I jaYWgoQTXC7BqSotLVZdZtIB+1UuoeFg1Shg1Vrx13+yROiLO2s7FAfceYEwmQOTn0P4Tn ZDa/ZG660LKKY45oX9aVGaCURh7EGCbRnyHIhvWMDs1amNJ/V2diJTMrF+48X0xfP6vXYs u7+CGjqIqaS7FsFeUgT8sLg1O2CigYMO9fNPRqc8vU7+M/gNRnBpjMI2KFGaLXm0LRQtt1 y2xbZfZCmUXQmw07BpPidm/CsFB4f3Npw/v3mNi8v9+0wyKY1yFr01ZIlQXQ X-ME-Proxy: Feedback-ID: ie3de48e3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 10 Sep 2026 06:22:55 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurilemu.de; s=schmee; t=1789035772; bh=5r3zhujsOtQKSBtsbHM6vwW8tw0zvD9+fN8uRCB6uhA=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=fWYIIlaD23h5UmNvDYqr/WbTUhyGG5prPRY/Ucr8cF15BZX1CZHoTRsyVKqUvPX46 wYyOJNFbV9Y6pv9ONoT224tX4SodPAsno98MnqbE+66Qbkr+rQqMQCpsEjlgParYdd qAbNwMwFS/S/466u/02/pQpLKjn/xwtdrAw4fHjwXKq9v6IpHvWwMc8BtztEBRiWkD 3UEEkmCLivONTwbW2FJTBLel+utMA+N7fwYLaiNpH0PN2wWrYj4MbIc2wyvUUPGyeH N2iyAfy8ghF3P8Rdw2DK3RuczzbZ7RvCtLN1lNVgCME7Yt06Ep8OuZnEr4r6coO7K7 eboh5zE85vHdQ== Received: by ida.kurilemu.internal (Postfix, from userid 1000) id 1FD1DB009D2; Thu, 10 Sep 2026 12:22:52 +0200 (CEST) Date: Thu, 10 Sep 2026 12:22:52 +0200 From: Alvaro Herrera To: Antonin Houska Cc: Chao Li , Matthias van de Meent , Nathan Bossart , pgsql-hackers@postgresql.org Subject: Re: REPACK (CONCURRENTLY) fails when replica identity index is dropped Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="csvqstbdygoam7e5" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --csvqstbdygoam7e5 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2026-Sep-01, Alvaro Herrera wrote: > On 2026-Sep-01, Antonin Houska wrote: > > > I agree that the core issue is that we allow dropping an index that is being > > used as replica identity. > > > > Regarding catalog entries already broken this way, it appears that pg_upgrade > > fixes them because pg_dump does not issue "ALTER TABLE ... REPLICA IDENTITY > > USING INDEX ..." if there is not identity index. Thus after pg_restore, > > pg_class(relreplident) becomes REPLICA_IDENTITY_DEFAULT. > > I agree that disallowing the drop is a sensible thing to do. Actually, wouldn't it make more sense to reset the replica identity back to 'd' when the index is dropped, as in the attached patch? -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "After a quick R of TFM, all I can say is HOLY CR** THAT IS COOL! PostgreSQL was amazing when I first started using it at 7.2, and I'm continually astounded by learning new features and techniques made available by the continuing work of the development team." Berend Tober, http://archives.postgresql.org/pgsql-hackers/2007-08/msg01009.php --csvqstbdygoam7e5 Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=0001-Revert-replica-identity-to-default-if-the-index-is-d.patch From 52d58f63db9e0e6cde0729470f41d1f25d972544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Herrera?= Date: Thu, 10 Sep 2026 12:21:16 +0200 Subject: [PATCH] Revert replica identity to 'default' if the index is dropped --- 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--