fix_drop_subscription_stats.patch
application/octet-stream
Filename: fix_drop_subscription_stats.patch
Type: application/octet-stream
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/backend/commands/subscriptioncmds.c | 6 | 6 |
| src/test/regress/expected/subscription.out | 10 | 0 |
| src/test/regress/sql/subscription.sql | 7 | 0 |
diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c index 8b3de032ee..09971ae45a 100644 --- a/src/backend/commands/subscriptioncmds.c +++ b/src/backend/commands/subscriptioncmds.c @@ -1644,6 +1644,12 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel) ReplicationOriginNameForLogicalRep(subid, InvalidOid, originname, sizeof(originname)); replorigin_drop_by_name(originname, true, false); + /* + * Tell the cumulative stats system that the subscription is getting + * dropped. + */ + pgstat_drop_subscription(subid); + /* * If there is no slot associated with the subscription, we can finish * here. @@ -1732,12 +1738,6 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel) } PG_END_TRY(); - /* - * Tell the cumulative stats system that the subscription is getting - * dropped. - */ - pgstat_drop_subscription(subid); - table_close(rel, NoLock); } diff --git a/src/test/regress/expected/subscription.out b/src/test/regress/expected/subscription.out index d736246259..e9d6166d27 100644 --- a/src/test/regress/expected/subscription.out +++ b/src/test/regress/expected/subscription.out @@ -73,6 +73,8 @@ SELECT :'prev_stats_reset' < stats_reset FROM pg_stat_subscription_stats WHERE s t (1 row) +-- Remember the subscription oid for checking later if the statistics gets removed. +SELECT oid as suboid FROM pg_subscription WHERE subname = 'regress_testsub' \gset -- fail - name already exists CREATE SUBSCRIPTION regress_testsub CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (connect = false); ERROR: subscription "regress_testsub" already exists @@ -240,6 +242,14 @@ ALTER SUBSCRIPTION regress_testsub SET (slot_name = NONE); BEGIN; DROP SUBSCRIPTION regress_testsub; COMMIT; +-- check if the statistics of the dropped subscription doesn't remain, by trying +-- directly fetching the stats. +SELECT stats_reset IS NULL stats_reset_is_null FROM pg_stat_get_subscription_stats(:'suboid'); + stats_reset_is_null +--------------------- + t +(1 row) + DROP SUBSCRIPTION IF EXISTS regress_testsub; NOTICE: subscription "regress_testsub" does not exist, skipping DROP SUBSCRIPTION regress_testsub; -- fail diff --git a/src/test/regress/sql/subscription.sql b/src/test/regress/sql/subscription.sql index 55d7dbc9ab..68be70dce5 100644 --- a/src/test/regress/sql/subscription.sql +++ b/src/test/regress/sql/subscription.sql @@ -42,6 +42,9 @@ SELECT stats_reset as prev_stats_reset FROM pg_stat_subscription_stats WHERE sub SELECT pg_stat_reset_subscription_stats(oid) FROM pg_subscription WHERE subname = 'regress_testsub'; SELECT :'prev_stats_reset' < stats_reset FROM pg_stat_subscription_stats WHERE subname = 'regress_testsub'; +-- Remember the subscription oid for checking later if the statistics gets removed. +SELECT oid as suboid FROM pg_subscription WHERE subname = 'regress_testsub' \gset + -- fail - name already exists CREATE SUBSCRIPTION regress_testsub CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (connect = false); @@ -158,6 +161,10 @@ BEGIN; DROP SUBSCRIPTION regress_testsub; COMMIT; +-- check if the statistics of the dropped subscription doesn't remain, by trying +-- directly fetching the stats. +SELECT stats_reset IS NULL stats_reset_is_null FROM pg_stat_get_subscription_stats(:'suboid'); + DROP SUBSCRIPTION IF EXISTS regress_testsub; DROP SUBSCRIPTION regress_testsub; -- fail