From 8154dca3ad4008d60cea9ce48afa52ba0c4b8b07 Mon Sep 17 00:00:00 2001 From: Vignesh C Date: Mon, 24 Aug 2026 10:52:05 +0530 Subject: [PATCH v3] Skip relations dropped concurrently in GetSubscriptionRelations() GetSubscriptionRelations() can see a pg_subscription_rel row for a relation whose pg_class row was removed by a concurrent DROP. In this case, get_rel_relkind() returns '\0'. Skip such relations since they no longer exist and do not need synchronization. Replace the assertion on relkind with an error. Once the dropped relation case is handled, any other unexpected relkind indicates a relation kind that cannot be part of a subscription and should be reported rather than ignored. Author: Vignesh C Reviewed-by: Amit Kapila Reviewed-by: Bharath Rupireddy Reviewed-by: Hayato Kuroda Reviewed-by: Kyotaro Horiguchi Discussion: https://www.postgresql.org/message-id/CALDaNm3eeKocRtQyUPdg2kaxJ-VAo5pwcNytDKNT1Yc0t2V_ug%40mail.gmail.com Backpatch-through: 19 --- src/backend/catalog/pg_subscription.c | 31 +++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/backend/catalog/pg_subscription.c b/src/backend/catalog/pg_subscription.c index f1e8b624d8e..60c15b22194 100644 --- a/src/backend/catalog/pg_subscription.c +++ b/src/backend/catalog/pg_subscription.c @@ -684,19 +684,32 @@ GetSubscriptionRelations(Oid subid, bool tables, bool sequences, subrel = (Form_pg_subscription_rel) GETSTRUCT(tup); - /* Relation is either a sequence or a table */ relkind = get_rel_relkind(subrel->srrelid); - Assert(relkind == RELKIND_SEQUENCE || relkind == RELKIND_RELATION || - relkind == RELKIND_PARTITIONED_TABLE); - /* Skip sequences if they were not requested */ - if ((relkind == RELKIND_SEQUENCE) && !sequences) + /* The relation may have been dropped concurrently. */ + if (relkind == '\0') continue; - /* Skip tables if they were not requested */ - if ((relkind == RELKIND_RELATION || - relkind == RELKIND_PARTITIONED_TABLE) && !tables) - continue; + /* + * The relation must be either a sequence or a table. Anything else + * indicates an unexpected relation kind for a subscription relation. + */ + if (relkind == RELKIND_SEQUENCE) + { + /* Skip sequences if they were not requested */ + if (!sequences) + continue; + } + else if (relkind == RELKIND_RELATION || + relkind == RELKIND_PARTITIONED_TABLE) + { + /* Skip tables if they were not requested */ + if (!tables) + continue; + } + else + elog(ERROR, "unexpected relkind \"%c\" for relation %u in subscription %u", + relkind, subrel->srrelid, subid); relstate = palloc_object(SubscriptionRelState); relstate->relid = subrel->srrelid; -- 2.55.0