Subject: Subscription statistics are not dropped at DROP SUBSCRIPTION in some cases

From: Masahiko Sawada <[email-masked]>
Date: Mon, 8 May 2023 16:23:15 +0900

Hi,

We call pgstat_drop_subscription() at the end of DropSubscription()
but we could leave from this function earlier e.g. when no slot is
associated with the subscription. In this case, the statistics entry
for the subscription remains. To fix it, I think we need to call it
earlier, just after removing the catalog tuple. There is a chance the
transaction dropping the subscription fails due to network error etc
but we don't need to worry about it as reporting the subscription drop
is transactional.

I've attached the patch. Feedback is very welcome.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

---

From: Nathan Bossart <[email-masked]>
Date: Mon, 8 May 2023 17:07:21 -0700

> but we don't need to worry about it as reporting the subscription drop

Looks reasonable to me.  IIUC calling pgstat_drop_subscription() earlier
makes no real difference (besides avoiding this bug) because it is uѕing
pgstat_drop_transactional() behind the scenes.

-- 
Nathan Bossart

---

From: Melih Mutlu <[email-masked]>
Date: Wed, 10 May 2023 14:58:26 +0300

Hi,

Masahiko Sawada <[email-masked]>, 8 May 2023 Pzt, 10:24 tarihinde

> I've attached the patch. Feedback is very welcome.

Thanks for the patch, nice catch.
I can confirm that the issue exists on HEAD and gets resolved by this
patch. Also it looks like stats are really not affected if transaction
fails for some reason, as you explained.
IMO, the patch will be OK after commit message is added.

Thanks,
-- 
Melih Mutlu
Microsoft