index 54895ba929a98ad7c5951375d214b351df83c75f..d4e798baeb14c18757fe64931faa31786ff57015 100644 (file)
@@ -1646,6 +1646,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.
@@ -1734,12 +1740,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);
}
index 45e51c5a52c6c4899ba77b78f6bf6477b5707660..0bcda006cd7ed44384751d7f04dee6590937f7c3 100644 (file)
qq(f),
qq(Subscription stats for subscription '$sub1_name' should be removed.));
+# Get subscription 2 oid
+my $sub2_oid = $node_subscriber->safe_psql($db,
+ qq(SELECT oid FROM pg_subscription WHERE subname = '$sub2_name'));
+
+# Diassociate the subscription 2 from its replication slot and drop it
+$node_subscriber->safe_psql(
+ $db,
+ qq(
+ALTER SUBSCRIPTION $sub2_name DISABLE;
+ALTER SUBSCRIPTION $sub2_name SET (slot_name = NONE);
+DROP SUBSCRIPTION $sub2_name;
+ ));
+
+# Subscription stats for sub2 should be gone
+is( $node_subscriber->safe_psql(
+ $db, qq(SELECT pg_stat_have_stats('subscription', 0, $sub2_oid))),
+ qq(f),
+ qq(Subscription stats for subscription '$sub2_name' should be removed.));
+$node_publisher->safe_psql($db,
+ qq(SELECT pg_drop_replication_slot('$sub2_name')));
$node_subscriber->stop('fast');
$node_publisher->stop('fast');