public inbox for [email protected]  
help / color / mirror / Atom feed
From: Zhijie Hou (Fujitsu) <[email protected]>
To: Chao Li <[email protected]>
To: PostgreSQL-development <[email protected]>
Subject: RE: repack: fix a bug to reject deferrable primary key fallback for concurrent mode
Date: Fri, 17 Apr 2026 03:46:31 +0000
Message-ID: <TYRPR01MB14195C23394DC17ABBD321B9694202@TYRPR01MB14195.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

On Friday, April 17, 2026 11:35 AM Chao Li <[email protected]> wrote:
> I am continuing to test REPACK, and I found another issue.
> 
> In check_concurrent_repack_requirements(), if a table has no replica identity
> index, the code falls back to using the primary key if one exists. The problem is
> that a deferrable primary key cannot be used for this purpose. WAL
> generation does not consider a deferrable primary key to be a replica identity,
> so concurrent mode may not receive enough old tuple information to replay
> concurrent changes.
> 
> I tested this with the following procedure.
> 
...
> With this patch, repack will quickly for the test:
> ```
> evantest=# repack (concurrently) t;
> ERROR:  cannot process relation "t"
> HINT:  Relation "t" has a deferrable primary key.
> ```

Good catch!

I think we can use the existing API to identify the index, for example:

diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.c
index 67364cc60e3..cc30236f493 100644
--- a/src/backend/commands/repack.c
+++ b/src/backend/commands/repack.c
@@ -62,6 +62,7 @@
 #include "miscadmin.h"
 #include "optimizer/optimizer.h"
 #include "pgstat.h"
+#include "replication/logicalrelation.h"
 #include "storage/bufmgr.h"
 #include "storage/lmgr.h"
 #include "storage/predicate.h"
@@ -924,9 +925,7 @@ check_concurrent_repack_requirements(Relation rel, Oid *ident_idx_p)
 	 * repack work with a FULL replica identity; however that requires more
 	 * work and is not implemented yet.
 	 */
-	ident_idx = RelationGetReplicaIndex(rel);
-	if (!OidIsValid(ident_idx) && OidIsValid(rel->rd_pkindex))
-		ident_idx = rel->rd_pkindex;
+	ident_idx = GetRelationIdentityOrPK();
 	if (!OidIsValid(ident_idx))
 		ereport(ERROR,
 				errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),

And it would be better to add a test for this.

Best Regards,
Hou zj





view thread (10+ messages)  latest in thread

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: [email protected]
  Cc: [email protected], [email protected]
  Subject: RE: repack: fix a bug to reject deferrable primary key fallback for concurrent mode
  In-Reply-To: <TYRPR01MB14195C23394DC17ABBD321B9694202@TYRPR01MB14195.jpnprd01.prod.outlook.com>

* 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