Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 68a59f9

Browse files
pgstat: fix subscription stats entry leak.
Commit 7b64e4b taught DropSubscription() to drop stats entry of subscription that is not associated with a replication slot for apply worker at DROP SUBSCRIPTION but missed covering the case where the subscription is not associated with replication slots for both apply worker and tablesync worker. Also add a test to verify that the stats for slot-less subscription is removed at DROP SUBSCRIPTION time. Backpatch down to 15. Author: Masahiko Sawada Reviewed-by: Nathan Bossart, Hayato Kuroda, Melih Mutlu, Amit Kapila Discussion: https://postgr.es/m/CAD21AoB71zkP7uPT7JDPsZcvp0749ExEQnOJxeNKPDFisHar+w@mail.gmail.com Backpatch-through: 15
1 parent cccdbc5 commit 68a59f9

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/backend/commands/subscriptioncmds.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,12 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
16461646
ReplicationOriginNameForLogicalRep(subid, InvalidOid, originname, sizeof(originname));
16471647
replorigin_drop_by_name(originname, true, false);
16481648

1649+
/*
1650+
* Tell the cumulative stats system that the subscription is getting
1651+
* dropped.
1652+
*/
1653+
pgstat_drop_subscription(subid);
1654+
16491655
/*
16501656
* If there is no slot associated with the subscription, we can finish
16511657
* here.
@@ -1734,12 +1740,6 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
17341740
}
17351741
PG_END_TRY();
17361742

1737-
/*
1738-
* Tell the cumulative stats system that the subscription is getting
1739-
* dropped.
1740-
*/
1741-
pgstat_drop_subscription(subid);
1742-
17431743
table_close(rel, NoLock);
17441744
}
17451745

src/test/subscription/t/026_stats.pl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,26 @@ sub create_sub_pub_w_errors
267267
qq(f),
268268
qq(Subscription stats for subscription '$sub1_name' should be removed.));
269269

270+
# Get subscription 2 oid
271+
my $sub2_oid = $node_subscriber->safe_psql($db,
272+
qq(SELECT oid FROM pg_subscription WHERE subname = '$sub2_name'));
273+
274+
# Diassociate the subscription 2 from its replication slot and drop it
275+
$node_subscriber->safe_psql(
276+
$db,
277+
qq(
278+
ALTER SUBSCRIPTION $sub2_name DISABLE;
279+
ALTER SUBSCRIPTION $sub2_name SET (slot_name = NONE);
280+
DROP SUBSCRIPTION $sub2_name;
281+
));
282+
283+
# Subscription stats for sub2 should be gone
284+
is( $node_subscriber->safe_psql(
285+
$db, qq(SELECT pg_stat_have_stats('subscription', 0, $sub2_oid))),
286+
qq(f),
287+
qq(Subscription stats for subscription '$sub2_name' should be removed.));
288+
$node_publisher->safe_psql($db,
289+
qq(SELECT pg_drop_replication_slot('$sub2_name')));
270290

271291
$node_subscriber->stop('fast');
272292
$node_publisher->stop('fast');

0 commit comments

Comments
 (0)