postgres.git / summary / log / commit / refs
commit 05f37b2b5eac5feab774a990a64ad16e2d03f5f5
Author: Amit Kapila <akapila@postgresql.org>
Date: Wed Aug 26 09:16:49 2026 +0000
First released in: 19.0
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 <vignesh21@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Backpatch-through: 19
Discussion: https://postgr.es/m/CALDaNm3eeKocRtQyUPdg2kaxJ-VAo5pwcNytDKNT1Yc0t2V_ug%40mail.gmail.com
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;