From e22fc4cb778024ce23e538e41966dc3ed2543e01 Mon Sep 17 00:00:00 2001 From: Matthias van de Meent Date: Thu, 27 Aug 2026 21:26:21 +0200 Subject: [PATCH v1] Repack: Fix replica identity index check We can't fall back to the PK index, because replica identity systems elsewhere don't do that either when they determine which data to log. --- src/backend/commands/repack.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.c index 477c86b2ba6..5a05bb41a68 100644 --- a/src/backend/commands/repack.c +++ b/src/backend/commands/repack.c @@ -924,26 +924,13 @@ check_concurrent_repack_requirements(Relation rel, Oid *ident_idx_p) "REPLICA IDENTITY NOTHING" : "REPLICA IDENTITY FULL")); /* - * Obtain the replica identity index -- either one that has been set - * explicitly, or a non-deferrable primary key. If none of these cases - * apply, the table cannot be repacked concurrently. It might be possible - * to have repack work with a FULL replica identity; however that requires - * more work and is not implemented yet. + * Obtain the replica identity index. We require the actual index + * responsible for being the logical identity; because AMs use that + * same index to determine which identity to include in WAL. */ - ident_idx = GetRelationIdentityOrPK(rel); + ident_idx = RelationGetReplicaIndex(rel); if (!OidIsValid(ident_idx)) { - /* This special case warrants its own error message */ - if (OidIsValid(rel->rd_pkindex) && rel->rd_ispkdeferrable) - ereport(ERROR, - errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("cannot execute %s on relation \"%s\"", - "REPACK (CONCURRENTLY)", - RelationGetRelationName(rel)), - errdetail("%s does not support deferrable primary keys.", - "REPACK (CONCURRENTLY)"), - errhint("Use ALTER TABLE ... REPLICA IDENTITY USING INDEX to designate another index as replica identity.")); - ereport(ERROR, errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("cannot execute %s on relation \"%s\"", @@ -952,6 +939,19 @@ check_concurrent_repack_requirements(Relation rel, Oid *ident_idx_p) RelationGetRelationName(rel))); } + /* This special case warrants its own error message */ + if (!OidIsValid(RelationGetPrimaryKeyIndex(rel, false))) + { + ereport(ERROR, + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot execute %s on relation \"%s\"", + "REPACK (CONCURRENTLY)", + RelationGetRelationName(rel)), + errdetail("%s does not support deferrable primary keys.", + "REPACK (CONCURRENTLY)"), + errhint("Use ALTER TABLE ... REPLICA IDENTITY USING INDEX to designate another index as replica identity.")); + } + *ident_idx_p = ident_idx; } -- 2.50.1 (Apple Git-155)