pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedAssertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
16+ messages / 6 participants
[nested] [flat]
Commits from this thread:
2026-08-26 4680f32d33 05f37b2b5e Skip relations dropped concurrently in GetSubscriptionRelations().
* Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
@ 2026-08-24 12:01 vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
0 siblings, 1 reply; 16+ messages in thread
From: vignesh C @ 2026-08-24 12:01 UTC (permalink / raw)
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; +Cc: Amit Kapila <amit.kapila16@gmail.com>
Hi,
I found an issue in GetSubscriptionRelations() when a REFRESH
PUBLICATION is executed while a subscribed relation is dropped
concurrently.
GetSubscriptionRelations() scans pg_subscription_rel using the catalog
snapshot taken when the scan starts, and then looks up the relation's
relkind through the syscache. If the relation is dropped and the drop
commits, the pg_subscription_rel row can still be visible while the
corresponding pg_class row is already gone. In this case,
get_rel_relkind() returns '\0'.
This can be reproduced with the following steps:
I have reproduced it through debugger:
step 1: Prepare logical replication setup for table tbl1,
step 2: session 1: ALTER SUBSCRIPTION sub1 REFRESH PUBLICATION; -->
Hold this statement through debugger at GetSubscriptionRelations
function just before get_rel_relkind function call
step 3: session 2: DROP TABLE tbl1; --> Drop the table concurrently
while the session 1 is stopped at GetSubscriptionRelations
step 4: continue the execution to see the Assertion failure.
get_rel_relkind will return '\0' which causes the assertion failure at:
....
relkind = get_rel_relkind(subrel->srrelid);
Assert(relkind == RELKIND_SEQUENCE || relkind == RELKIND_RELATION ||
relkind == RELKIND_PARTITIONED_TABLE);
....
This caused the following assertion to fail in an assert-enabled build:
TRAP: failed Assert("relkind == RELKIND_SEQUENCE || relkind ==
RELKIND_RELATION || relkind == RELKIND_PARTITIONED_TABLE"), File:
"pg_subscription.c", Line: 699, PID: 32422
0 postgres 0x0000000102a47728
ExceptionalCondition + 216
1 postgres 0x00000001022ab850
GetSubscriptionRelations + 484
2 postgres 0x00000001023e52a8
AlterSubscription_refresh + 620
Attached is 0001-Test-to-reproduce-assertion-failure-in.patch, which
adds an injection-point test to reproduce the issue.
The fix is to skip the relation when get_rel_relkind() returns '\0',
since the relation has already been dropped and there is nothing left
to synchronise. The attached
v1-0001-Skip-relations-dropped-concurrently-in-GetSubscri.patch patch
has the fix for the same. This also needs to be fixed in the v19
branch, where get_rel_relkind() was introduced by commit
f0b3573c3aac6c0ea4cbc278f98178516579d370.
Regards,
Vignesh
Attachments: download all (2 files, .tar.gz)
v1-0001-Skip-relations-dropped-concurrently-in-GetSubscri.patch (application/octet-stream, 1.4K) download
From f9e60f948297a75af9bb8cfbdc9b67a3427e3c05 Mon Sep 17 00:00:00 2001
From: Vignesh C <c_vigneshwaran@apple.com>
Date: Mon, 24 Aug 2026 10:52:05 +0530
Subject: [PATCH v1] 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 instead of asserting or returning them to the
caller, since the relation no longer exists and needs no synchronization.
---
src/backend/catalog/pg_subscription.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/backend/catalog/pg_subscription.c b/src/backend/catalog/pg_subscription.c
index f1e8b624d8e..ae97a0a0db6 100644
--- a/src/backend/catalog/pg_subscription.c
+++ b/src/backend/catalog/pg_subscription.c
@@ -684,8 +684,13 @@ 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);
+
+ /* The relation may have been dropped concurrently. */
+ if (relkind == '\0')
+ continue;
+
+ /* Relation is either a sequence or a table */
Assert(relkind == RELKIND_SEQUENCE || relkind == RELKIND_RELATION ||
relkind == RELKIND_PARTITIONED_TABLE);
--
2.55.0
0001-Test-to-reproduce-assertion-failure-in.patch (application/octet-stream, 7.7K) download
From 606e7d785f6179e54883ecfe67d8017f0b19d8f5 Mon Sep 17 00:00:00 2001
From: Vignesh C <c_vigneshwaran@apple.com>
Date: Mon, 24 Aug 2026 16:30:34 +0530
Subject: [PATCH] Test to reproduce assertion failure in
GetSubscriptionRelations because of concurrent drop table.
Test to reproduce assertion failure in GetSubscriptionRelations because
of concurrent drop table.
---
src/backend/catalog/pg_subscription.c | 3 +
src/test/subscription/meson.build | 1 +
.../t/059_subscription_rel_dropped.pl | 155 ++++++++++++++++++
3 files changed, 159 insertions(+)
create mode 100644 src/test/subscription/t/059_subscription_rel_dropped.pl
diff --git a/src/backend/catalog/pg_subscription.c b/src/backend/catalog/pg_subscription.c
index f1e8b624d8e..36870aa9419 100644
--- a/src/backend/catalog/pg_subscription.c
+++ b/src/backend/catalog/pg_subscription.c
@@ -31,6 +31,7 @@
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
+#include "utils/injection_point.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/pg_lsn.h"
@@ -684,6 +685,8 @@ GetSubscriptionRelations(Oid subid, bool tables, bool sequences,
subrel = (Form_pg_subscription_rel) GETSTRUCT(tup);
+ INJECTION_POINT("subscription-relations-fetch", NULL);
+
/* Relation is either a sequence or a table */
relkind = get_rel_relkind(subrel->srrelid);
Assert(relkind == RELKIND_SEQUENCE || relkind == RELKIND_RELATION ||
diff --git a/src/test/subscription/meson.build b/src/test/subscription/meson.build
index e71e95c6297..a9e3076b63b 100644
--- a/src/test/subscription/meson.build
+++ b/src/test/subscription/meson.build
@@ -48,6 +48,7 @@ tests += {
't/036_sequences.pl',
't/037_except.pl',
't/038_walsnd_shutdown_timeout.pl',
+ 't/059_subscription_rel_dropped.pl',
't/100_bugs.pl',
],
},
diff --git a/src/test/subscription/t/059_subscription_rel_dropped.pl b/src/test/subscription/t/059_subscription_rel_dropped.pl
new file mode 100644
index 00000000000..de71088152e
--- /dev/null
+++ b/src/test/subscription/t/059_subscription_rel_dropped.pl
@@ -0,0 +1,155 @@
+# Copyright (c) 2026, PostgreSQL Global Development Group
+
+# Test GetSubscriptionRelations() against a relation dropped while it runs.
+#
+# GetSubscriptionRelations() scans pg_subscription_rel with the catalog snapshot
+# taken when the scan started, and then looks up each relation's relkind through
+# the syscache, which takes a newer snapshot. A relation whose drop commits in
+# between is therefore still visible as a pg_subscription_rel row while its
+# pg_class row is already gone, and get_rel_relkind() returns '\0' for it.
+#
+# That trips
+#
+# Assert(relkind == RELKIND_SEQUENCE || relkind == RELKIND_RELATION ||
+# relkind == RELKIND_PARTITIONED_TABLE);
+#
+# in an assert-enabled build.
+
+use strict;
+use warnings FATAL => 'all';
+use PostgreSQL::Test::Cluster;
+use PostgreSQL::Test::Utils;
+use Test::More;
+
+if ($ENV{enable_injection_points} ne 'yes')
+{
+ plan skip_all => 'Injection points not supported by this build';
+}
+
+my $node_publisher = PostgreSQL::Test::Cluster->new('publisher');
+$node_publisher->init(allows_streaming => 'logical');
+$node_publisher->start;
+
+my $node_subscriber = PostgreSQL::Test::Cluster->new('subscriber');
+$node_subscriber->init(allows_streaming => 'logical');
+$node_subscriber->start;
+
+if (!$node_subscriber->check_extension('injection_points'))
+{
+ plan skip_all => 'Extension injection_points not installed';
+}
+
+# tab_keep stays in the subscription; tab_drop is the one dropped mid-scan.
+for my $node ($node_publisher, $node_subscriber)
+{
+ $node->safe_psql(
+ 'postgres', qq{
+ CREATE TABLE tab_keep (a int PRIMARY KEY);
+ CREATE TABLE tab_drop (a int PRIMARY KEY);
+ });
+}
+
+$node_publisher->safe_psql(
+ 'postgres', qq{
+ CREATE PUBLICATION pub FOR TABLE tab_keep, tab_drop;
+ INSERT INTO tab_keep VALUES (1);
+});
+
+my $connstr = $node_publisher->connstr . ' dbname=postgres';
+
+$node_subscriber->safe_psql(
+ 'postgres', "
+ CREATE SUBSCRIPTION sub
+ CONNECTION '$connstr application_name=sub'
+ PUBLICATION pub");
+
+$node_subscriber->wait_for_subscription_sync($node_publisher, 'sub');
+
+is($node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_keep"),
+ '1', 'initial data replicated');
+
+$node_subscriber->safe_psql('postgres', 'CREATE EXTENSION injection_points');
+
+###############################################################################
+# Park the scan of pg_subscription_rel.
+###############################################################################
+
+my $log_offset = -s $node_subscriber->logfile;
+
+my $refresh = $node_subscriber->background_psql('postgres');
+$refresh->set_query_timer_restart();
+
+# Attach the injection point from the session that will run the REFRESH, and
+# restrict it to that session, so that the apply worker cannot park at it too.
+$refresh->query_safe("SELECT injection_points_set_local()");
+$refresh->query_safe(
+ "SELECT injection_points_attach('subscription-relations-fetch', 'wait')");
+
+# Issue the REFRESH without waiting for it: the \echo marker comes back as soon
+# as psql has read the input, while the command itself blocks in the scan.
+$refresh->query_until(
+ qr/^issued$/m, qq[
+ \\echo issued
+ ALTER SUBSCRIPTION sub REFRESH PUBLICATION;
+]);
+
+$node_subscriber->poll_query_until('postgres',
+ "SELECT count(*) > 0 FROM pg_stat_activity WHERE wait_event = 'subscription-relations-fetch'"
+) or die "timed out waiting for the REFRESH to reach the injection point";
+
+pass('REFRESH is inside the pg_subscription_rel scan');
+
+###############################################################################
+# Drop the table while the scan is parked. This commits, removing both the
+# pg_class row and the pg_subscription_rel row that the parked scan can still
+# see.
+###############################################################################
+
+$node_subscriber->safe_psql('postgres', "DROP TABLE tab_drop");
+
+is( $node_subscriber->safe_psql(
+ 'postgres', qq{
+ SELECT count(*) FROM pg_subscription_rel r
+ JOIN pg_class c ON c.oid = r.srrelid
+ WHERE c.relname = 'tab_drop'}),
+ '0',
+ 'dropped table is gone from pg_subscription_rel');
+
+# Detach before waking up. The injection point sits inside the scan loop, so
+# leaving it attached would park the next iteration again, and the wakeup below
+# would have nothing left to release.
+$node_subscriber->safe_psql('postgres',
+ "SELECT injection_points_detach('subscription-relations-fetch')");
+
+$node_subscriber->safe_psql('postgres',
+ "SELECT injection_points_wakeup('subscription-relations-fetch')");
+
+###############################################################################
+# The relkind lookup for the dropped relation now returns '\0'. The scan must
+# skip that row and let the REFRESH complete.
+#
+# Where the row is not skipped, the assertion in GetSubscriptionRelations()
+# fails, which takes the backend down and makes the postmaster restart the
+# cluster.
+###############################################################################
+
+my $refresh_result;
+
+eval {
+ # Sending another query on the same session waits for the REFRESH to
+ # finish.
+ $refresh_result = $refresh->query_safe("SELECT 'refresh completed'");
+};
+my $refresh_error = $@;
+
+eval { $refresh->quit; };
+
+# The headline check: the scan must not have failed an assertion.
+my $trapped = $node_subscriber->log_contains(qr/TRAP: failed Assert/, $log_offset);
+
+ok(!$trapped, 'no assertion failure during the scan')
+ or diag(
+ "the scan reported a relation that is neither a table nor a sequence; "
+ . "GetSubscriptionRelations() needs to skip concurrently dropped relations");
+
+done_testing();
--
2.55.0
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
@ 2026-08-24 18:05 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 16+ messages in thread
From: Bharath Rupireddy @ 2026-08-24 18:05 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Amit Kapila <amit.kapila16@gmail.com>
Hi,
On Mon, Aug 24, 2026 at 5:01 AM vignesh C <vignesh21@gmail.com> wrote:
>
> I found an issue in GetSubscriptionRelations() when a REFRESH
> PUBLICATION is executed while a subscribed relation is dropped
> concurrently.
Thanks for reporting and sending the patch.
> GetSubscriptionRelations() scans pg_subscription_rel using the catalog
> snapshot taken when the scan starts, and then looks up the relation's
> relkind through the syscache. If the relation is dropped and the drop
> commits, the pg_subscription_rel row can still be visible while the
> corresponding pg_class row is already gone. In this case,
> get_rel_relkind() returns '\0'.
>
> This can be reproduced with the following steps:
> I have reproduced it through debugger:
>
> get_rel_relkind will return '\0' which causes the assertion failure at:
> ....
> relkind = get_rel_relkind(subrel->srrelid);
>
> Assert(relkind == RELKIND_SEQUENCE || relkind == RELKIND_RELATION ||
> relkind == RELKIND_PARTITIONED_TABLE);
How easy is it to hit this with direct SQL without a debugger or
injection point? In production builds (no assertions), what happens
when the relation is concurrently dropped? Does the logical
replication worker error or crash, and if it exits, does it recover in
the next cycle since the relation won't be in the list anymore?
If it's not easily reproducible with direct SQL, I don't think we need
to fix this at all, because none of the other places (for example,
getOwnedSequences_internal() or GetPubPartitionOptionRelations())
handle a null relkind either. Even if we were to fix, I would just
remove the assertion and continue in the loop if the relation is not
what we expect. Would that work?
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
@ 2026-08-25 04:52 ` Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 05:33 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
0 siblings, 1 reply; 16+ messages in thread
From: Amit Kapila @ 2026-08-25 04:52 UTC (permalink / raw)
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>; +Cc: vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Mon, Aug 24, 2026 at 11:35 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:
>
> If it's not easily reproducible with direct SQL, I don't think we need
> to fix this at all, because none of the other places (for example,
> getOwnedSequences_internal() or GetPubPartitionOptionRelations())
> handle a null relkind either.
>
But they will work (as they are if checks) and as far as I can see
they will do the right thing which means they will tolerate concurrent
drops but if not I feel it is better to fix those as well.
> Even if we were to fix, I would just
> remove the assertion and continue in the loop if the relation is not
> what we expect. Would that work?
>
As we are scanning pg_susbcription_rel unexpected relkind here (not
'\0', something else entirely) would probably indicate a real bug
worth surfacing, not silently swallowing. So, I suggest we can remove
assert after Vignesh's fix and have an elog(ERROR, "unexpected
relkind: %d", (int) relkind);. We use such an elog at other places as
well.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
@ 2026-08-25 05:33 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 08:04 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
0 siblings, 1 reply; 16+ messages in thread
From: Bharath Rupireddy @ 2026-08-25 05:33 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Hi,
On Mon, Aug 24, 2026 at 9:52 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Mon, Aug 24, 2026 at 11:35 PM Bharath Rupireddy
> <bharath.rupireddyforpostgres@gmail.com> wrote:
> >
> > If it's not easily reproducible with direct SQL, I don't think we need
> > to fix this at all, because none of the other places (for example,
> > getOwnedSequences_internal() or GetPubPartitionOptionRelations())
> > handle a null relkind either.
>
> But they will work (as they are if checks) and as far as I can see
> they will do the right thing which means they will tolerate concurrent
> drops but if not I feel it is better to fix those as well.
Yes, it's worth exploring all of these in the logical replication code
(maybe separately though).
> > Even if we were to fix, I would just
> > remove the assertion and continue in the loop if the relation is not
> > what we expect. Would that work?
>
> As we are scanning pg_susbcription_rel unexpected relkind here (not
> '\0', something else entirely) would probably indicate a real bug
> worth surfacing, not silently swallowing. So, I suggest we can remove
> assert after Vignesh's fix and have an elog(ERROR, "unexpected
> relkind: %d", (int) relkind);. We use such an elog at other places as
> well.
Works for me, and I think both can go in one patch. After the relkind
fix, replacing the assertion with an error means that in the rare
scenario where the OID of the dropped table gets reused to create a
relation that's not expected, we catch it. I'm all in favor of
tightening this anyway.
On backpatching this fix, I think HEAD and PG19 (still in beta) are
enough, because it's not easily reproducible with direct SQL. For the
same reason, I'm fine with not having an injection point and a TAP
test for this.
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 05:33 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
@ 2026-08-25 08:04 ` vignesh C <vignesh21@gmail.com>
2026-08-25 12:09 ` RE: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
0 siblings, 1 reply; 16+ messages in thread
From: vignesh C @ 2026-08-25 08:04 UTC (permalink / raw)
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Tue, 25 Aug 2026 at 11:03, Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:
>
> Yes, it's worth exploring all of these in the logical replication code
> (maybe separately though).
I Agree, if there is any issue, it can be handled separately.
> > > Even if we were to fix, I would just
> > > remove the assertion and continue in the loop if the relation is not
> > > what we expect. Would that work?
> >
> > As we are scanning pg_susbcription_rel unexpected relkind here (not
> > '\0', something else entirely) would probably indicate a real bug
> > worth surfacing, not silently swallowing. So, I suggest we can remove
> > assert after Vignesh's fix and have an elog(ERROR, "unexpected
> > relkind: %d", (int) relkind);. We use such an elog at other places as
> > well.
>
> Works for me, and I think both can go in one patch.
Updated
>After the relkind
> fix, replacing the assertion with an error means that in the rare
> scenario where the OID of the dropped table gets reused to create a
> relation that's not expected, we catch it. I'm all in favor of
> tightening this anyway.
The other ways this could happen are: (a) if logical replication is
extended in the future to support additional relation types, or (b) if
the system catalog is corrupted, for example by directly updating
relkind in pg_class using an UPDATE statement.
> On backpatching this fix, I think HEAD and PG19 (still in beta) are
> enough, because it's not easily reproducible with direct SQL. For the
> same reason, I'm fine with not having an injection point and a TAP
> test for this.
Yes, the injection-point test does not need to be committed. I shared
it only to make the issue easier to reproduce.
The attached v2 version patch has the changes for the same.
Regards,
Vignesh
Attachments:
v2-0001-Skip-relations-dropped-concurrently-in-GetSubscri.patch (application/octet-stream, 2.7K) download
From c9e593534b1af6accfc97835fc5649d25b4f7439 Mon Sep 17 00:00:00 2001
From: Vignesh C <c_vigneshwaran@apple.com>
Date: Mon, 24 Aug 2026 10:52:05 +0530
Subject: [PATCH v2] 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>
Discussion: https://www.postgresql.org/message-id/CALDaNm3eeKocRtQyUPdg2kaxJ-VAo5pwcNytDKNT1Yc0t2V_ug%40mail.gmail.com
Backpatch-through: 19
---
src/backend/catalog/pg_subscription.c | 30 +++++++++++++++++++--------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/src/backend/catalog/pg_subscription.c b/src/backend/catalog/pg_subscription.c
index f1e8b624d8e..360a31c74eb 100644
--- a/src/backend/catalog/pg_subscription.c
+++ b/src/backend/catalog/pg_subscription.c
@@ -684,19 +684,31 @@ 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: %d", (int) relkind);
relstate = palloc_object(SubscriptionRelState);
relstate->relid = subrel->srrelid;
--
2.55.0
^ permalink raw reply [nested|flat] 16+ messages in thread
* RE: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 05:33 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 08:04 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
@ 2026-08-25 12:09 ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-08-25 13:41 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 16+ messages in thread
From: Hayato Kuroda (Fujitsu) @ 2026-08-25 12:09 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Dear Vignesh,
Thanks for updating the patch. I confirmed it could fix the issue.
```
+ else
+ elog(ERROR, "unexpected relkind: %d", (int) relkind);
```
I feel \"%c\" might be better than %d, like what ProcessUtilitySlow() does,
because the relkind is defined as char.
Best regards,
Hayato Kuroda
FUJITSU LIMITED
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 05:33 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 08:04 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-25 12:09 ` RE: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
@ 2026-08-25 13:41 ` Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 19:53 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Nathan Bossart <nathandbossart@gmail.com>
2026-08-26 02:02 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-08-26 05:53 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
0 siblings, 3 replies; 16+ messages in thread
From: Amit Kapila @ 2026-08-25 13:41 UTC (permalink / raw)
To: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; +Cc: vignesh C <vignesh21@gmail.com>; Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Tue, Aug 25, 2026 at 5:39 PM Hayato Kuroda (Fujitsu)
<kuroda.hayato@fujitsu.com> wrote:
>
> Thanks for updating the patch. I confirmed it could fix the issue.
>
>
> ```
> + else
> + elog(ERROR, "unexpected relkind: %d", (int) relkind);
> ```
>
>
> I feel \"%c\" might be better than %d, like what ProcessUtilitySlow() does,
> because the relkind is defined as char.
>
Agreed, though %d is used for the same purpose at one place in code
but other uses %c for relkind. How about a slightly more informative
message like: elog(ERROR, "unexpected relkind \"%c\" for relation %u
in subscription %u", relkind, subrel->srrelid, subid)?
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 05:33 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 08:04 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-25 12:09 ` RE: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-08-25 13:41 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
@ 2026-08-25 19:53 ` Nathan Bossart <nathandbossart@gmail.com>
2026-08-25 22:24 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2 siblings, 1 reply; 16+ messages in thread
From: Nathan Bossart @ 2026-08-25 19:53 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; vignesh C <vignesh21@gmail.com>; Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Does this one deserve a mention on the open items wiki [0]?
[0] https://wiki.postgresql.org/wiki/PostgreSQL_19_Open_Items
--
nathan
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 05:33 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 08:04 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-25 12:09 ` RE: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-08-25 13:41 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 19:53 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Nathan Bossart <nathandbossart@gmail.com>
@ 2026-08-25 22:24 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-26 10:21 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 16+ messages in thread
From: Bharath Rupireddy @ 2026-08-25 22:24 UTC (permalink / raw)
To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Hi,
On Tue, Aug 25, 2026 at 12:53 PM Nathan Bossart
<nathandbossart@gmail.com> wrote:
>
> Does this one deserve a mention on the open items wiki [0]?
>
> [0] https://wiki.postgresql.org/wiki/PostgreSQL_19_Open_Items
I don't think so TBH. Given that it's not easily reproducible with
direct SQL and we seem to have agreement on the fix. However, I will
wait for Amit/Vignesh or others here.
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 05:33 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 08:04 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-25 12:09 ` RE: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-08-25 13:41 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 19:53 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Nathan Bossart <nathandbossart@gmail.com>
2026-08-25 22:24 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
@ 2026-08-26 10:21 ` Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 0 replies; 16+ messages in thread
From: Amit Kapila @ 2026-08-26 10:21 UTC (permalink / raw)
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Wed, Aug 26, 2026 at 3:55 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:
>
> Hi,
>
> On Tue, Aug 25, 2026 at 12:53 PM Nathan Bossart
> <nathandbossart@gmail.com> wrote:
> >
> > Does this one deserve a mention on the open items wiki [0]?
> >
> > [0] https://wiki.postgresql.org/wiki/PostgreSQL_19_Open_Items
>
> I don't think so TBH. Given that it's not easily reproducible with
> direct SQL and we seem to have agreement on the fix. However, I will
> wait for Amit/Vignesh or others here.
>
I have pushed the fix. The reason to not add it to open items was that
the fix was simple and we have an agreement. Thanks for the review.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 05:33 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 08:04 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-25 12:09 ` RE: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-08-25 13:41 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
@ 2026-08-26 02:02 ` Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-08-26 04:18 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-26 04:53 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2 siblings, 2 replies; 16+ messages in thread
From: Kyotaro Horiguchi @ 2026-08-26 02:02 UTC (permalink / raw)
To: amit.kapila16@gmail.com; +Cc: kuroda.hayato@fujitsu.com; vignesh21@gmail.com; bharath.rupireddyforpostgres@gmail.com; pgsql-hackers@lists.postgresql.org
Hello,
Both changes in the current patch look good to me.
At Tue, 25 Aug 2026 19:11:27 +0530, Amit Kapila <amit.kapila16@gmail.com> wrote in
> > I feel \"%c\" might be better than %d, like what ProcessUtilitySlow() does,
> > because the relkind is defined as char.
> >
>
> Agreed, though %d is used for the same purpose at one place in code
> but other uses %c for relkind. How about a slightly more informative
> message like: elog(ERROR, "unexpected relkind \"%c\" for relation %u
> in subscription %u", relkind, subrel->srrelid, subid)?
I may be being overly cautious, but I'm a little hesitant to use %c
here. For example, if the value happened to be the first byte of a
UTF-8 sequence, it could result in an invalidly encoded log line.
Since this error is unlikely to be seen in practice and readability is
not particularly important here, I think %d is safer. It might even be
better to change the existing uses of %c for relkind to %d for the
same reason.
Regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 05:33 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 08:04 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-25 12:09 ` RE: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-08-25 13:41 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-26 02:02 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Kyotaro Horiguchi <horikyota.ntt@gmail.com>
@ 2026-08-26 04:18 ` vignesh C <vignesh21@gmail.com>
1 sibling, 0 replies; 16+ messages in thread
From: vignesh C @ 2026-08-26 04:18 UTC (permalink / raw)
To: Kyotaro Horiguchi <horikyota.ntt@gmail.com>; +Cc: amit.kapila16@gmail.com; kuroda.hayato@fujitsu.com; bharath.rupireddyforpostgres@gmail.com; pgsql-hackers@lists.postgresql.org
On Wed, 26 Aug 2026 at 07:32, Kyotaro Horiguchi <horikyota.ntt@gmail.com> wrote:
>
> Hello,
>
> Both changes in the current patch look good to me.
>
> At Tue, 25 Aug 2026 19:11:27 +0530, Amit Kapila <amit.kapila16@gmail.com> wrote in
> > > I feel \"%c\" might be better than %d, like what ProcessUtilitySlow() does,
> > > because the relkind is defined as char.
> > >
> >
> > Agreed, though %d is used for the same purpose at one place in code
> > but other uses %c for relkind. How about a slightly more informative
> > message like: elog(ERROR, "unexpected relkind \"%c\" for relation %u
> > in subscription %u", relkind, subrel->srrelid, subid)?
>
> I may be being overly cautious, but I'm a little hesitant to use %c
> here. For example, if the value happened to be the first byte of a
> UTF-8 sequence, it could result in an invalidly encoded log line.
>
> Since this error is unlikely to be seen in practice and readability is
> not particularly important here, I think %d is safer. It might even be
> better to change the existing uses of %c for relkind to %d for the
> same reason.
I checked how relkind is formatted elsewhere in the codebase.
%c is used more commonly like in the following places:
heapam.c — "missing lock for relation \"%s\" (OID %u, relkind %c) @ TID (%u,%u)"
utility.c — "unexpected relkind \"%c\" on partition \"%s\""
postgres_fdw.c — "remote table \"%s.%s\" is of relkind \"%c\" which
cannot have statistics"
pg_dump.c — "cannot dump statistics for relation kind \"%c\""
pg_class.c — "unrecognized relkind: '%c'"
%d is used in only one place:
tablecmds.c — "unexpected relkind: %d"
So %c is clearly the more common convention for relkind. I think we
should follow the existing convention and use %c in this patch. If we
decide that %d is preferable, it would be better to change all of the
%c uses in a separate patch.
Thoughts?
Regards,
Vignesh
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 05:33 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 08:04 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-25 12:09 ` RE: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-08-25 13:41 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-26 02:02 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Kyotaro Horiguchi <horikyota.ntt@gmail.com>
@ 2026-08-26 04:53 ` Amit Kapila <amit.kapila16@gmail.com>
2026-08-26 05:19 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
1 sibling, 1 reply; 16+ messages in thread
From: Amit Kapila @ 2026-08-26 04:53 UTC (permalink / raw)
To: Kyotaro Horiguchi <horikyota.ntt@gmail.com>; +Cc: kuroda.hayato@fujitsu.com; vignesh21@gmail.com; bharath.rupireddyforpostgres@gmail.com; pgsql-hackers@lists.postgresql.org
On Wed, Aug 26, 2026 at 7:32 AM Kyotaro Horiguchi
<horikyota.ntt@gmail.com> wrote:
>
> Both changes in the current patch look good to me.
>
> At Tue, 25 Aug 2026 19:11:27 +0530, Amit Kapila <amit.kapila16@gmail.com> wrote in
> > > I feel \"%c\" might be better than %d, like what ProcessUtilitySlow() does,
> > > because the relkind is defined as char.
> > >
> >
> > Agreed, though %d is used for the same purpose at one place in code
> > but other uses %c for relkind. How about a slightly more informative
> > message like: elog(ERROR, "unexpected relkind \"%c\" for relation %u
> > in subscription %u", relkind, subrel->srrelid, subid)?
>
> I may be being overly cautious, but I'm a little hesitant to use %c
> here. For example, if the value happened to be the first byte of a
> UTF-8 sequence, it could result in an invalidly encoded log line.
>
I think the UTF-8 concern would apply only if relkind contained a
value outside the currently defined RELKIND_* values. All the valid
relkind values defined in pg_class.h are ASCII characters (r, i, S,
t,etc.), so %c is safe for the values that relkind is expected to
contain.
That said, I agree that %d would be safer if we want to make the error
handling robust against an arbitrary/invalid byte say due to catalog
corruption. As Vignesh pointed out, though, %c is currently the common
convention for printing relkind, whereas %d is used only in one place.
So perhaps we should keep %c in this patch and, if we want to adopt %d
for unexpected relkind values, let's handle the existing %c usages
consistently in a separate patch.
Thoughts?
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 05:33 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 08:04 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-25 12:09 ` RE: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-08-25 13:41 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-26 02:02 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-08-26 04:53 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
@ 2026-08-26 05:19 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-26 07:01 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Kyotaro Horiguchi <horikyota.ntt@gmail.com>
0 siblings, 1 reply; 16+ messages in thread
From: Bharath Rupireddy @ 2026-08-26 05:19 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>; kuroda.hayato@fujitsu.com; vignesh21@gmail.com; pgsql-hackers@lists.postgresql.org
Hi,
On Tue, Aug 25, 2026 at 9:53 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> That said, I agree that %d would be safer if we want to make the error
> handling robust against an arbitrary/invalid byte say due to catalog
> corruption. As Vignesh pointed out, though, %c is currently the common
> convention for printing relkind, whereas %d is used only in one place.
>
> So perhaps we should keep %c in this patch and, if we want to adopt %d
> for unexpected relkind values, let's handle the existing %c usages
> consistently in a separate patch.
>
> Thoughts?
I looked at the most common and widely used path, which is
errdetail_relkind_not_supported(). It uses %c (some of these might be
user-visible errors). I prefer to go with that, so +1 to use %c in
this patch and discuss the use of %d separately if that's a concern.
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 05:33 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 08:04 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-25 12:09 ` RE: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-08-25 13:41 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-26 02:02 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-08-26 04:53 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-26 05:19 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
@ 2026-08-26 07:01 ` Kyotaro Horiguchi <horikyota.ntt@gmail.com>
0 siblings, 0 replies; 16+ messages in thread
From: Kyotaro Horiguchi @ 2026-08-26 07:01 UTC (permalink / raw)
To: bharath.rupireddyforpostgres@gmail.com; +Cc: amit.kapila16@gmail.com; kuroda.hayato@fujitsu.com; vignesh21@gmail.com; pgsql-hackers@lists.postgresql.org
Hello,
At Tue, 25 Aug 2026 22:19:30 -0700, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> wrote in
> Hi,
>
> On Tue, Aug 25, 2026 at 9:53 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> > That said, I agree that %d would be safer if we want to make the error
> > handling robust against an arbitrary/invalid byte say due to catalog
> > corruption. As Vignesh pointed out, though, %c is currently the common
> > convention for printing relkind, whereas %d is used only in one place.
> >
> > So perhaps we should keep %c in this patch and, if we want to adopt %d
> > for unexpected relkind values, let's handle the existing %c usages
> > consistently in a separate patch.
> >
> > Thoughts?
>
> I looked at the most common and widely used path, which is
> errdetail_relkind_not_supported(). It uses %c (some of these might be
> user-visible errors). I prefer to go with that, so +1 to use %c in
> this patch and discuss the use of %d separately if that's a concern.
If this case has been considered and the choice of %c is intentional,
I have no objection to it.
Regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 05:33 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 08:04 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-25 12:09 ` RE: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-08-25 13:41 ` Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE Amit Kapila <amit.kapila16@gmail.com>
@ 2026-08-26 05:53 ` vignesh C <vignesh21@gmail.com>
2 siblings, 0 replies; 16+ messages in thread
From: vignesh C @ 2026-08-26 05:53 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Tue, 25 Aug 2026 at 19:11, Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Tue, Aug 25, 2026 at 5:39 PM Hayato Kuroda (Fujitsu)
> <kuroda.hayato@fujitsu.com> wrote:
> >
> > Thanks for updating the patch. I confirmed it could fix the issue.
> >
> >
> > ```
> > + else
> > + elog(ERROR, "unexpected relkind: %d", (int) relkind);
> > ```
> >
> >
> > I feel \"%c\" might be better than %d, like what ProcessUtilitySlow() does,
> > because the relkind is defined as char.
> >
>
> Agreed, though %d is used for the same purpose at one place in code
> but other uses %c for relkind. How about a slightly more informative
> message like: elog(ERROR, "unexpected relkind \"%c\" for relation %u
> in subscription %u", relkind, subrel->srrelid, subid)?
Here is an updated version with the message updated accordingly.
Regards,
Vignesh
Attachments:
v3-0001-Skip-relations-dropped-concurrently-in-GetSubscri.patch (application/octet-stream, 2.8K) download
From 8154dca3ad4008d60cea9ce48afa52ba0c4b8b07 Mon Sep 17 00:00:00 2001
From: Vignesh C <c_vigneshwaran@apple.com>
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 <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>
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
^ permalink raw reply [nested|flat] 16+ messages in thread
end of thread, other threads:[~2026-08-26 10:21 UTC | newest]
Thread overview: 16+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-24 12:01 Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE vignesh C <vignesh21@gmail.com>
2026-08-24 18:05 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 04:52 ` Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 05:33 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-25 08:04 ` vignesh C <vignesh21@gmail.com>
2026-08-25 12:09 ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-08-25 13:41 ` Amit Kapila <amit.kapila16@gmail.com>
2026-08-25 19:53 ` Nathan Bossart <nathandbossart@gmail.com>
2026-08-25 22:24 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-26 10:21 ` Amit Kapila <amit.kapila16@gmail.com>
2026-08-26 02:02 ` Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-08-26 04:18 ` vignesh C <vignesh21@gmail.com>
2026-08-26 04:53 ` Amit Kapila <amit.kapila16@gmail.com>
2026-08-26 05:19 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-26 07:01 ` Kyotaro Horiguchi <horikyota.ntt@gmail.com>
2026-08-26 05:53 ` vignesh C <vignesh21@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox