Subscription statistics are not dropped at DROP SUBSCRIPTION in some cases

Masahiko Sawada <sawada.mshk@gmail.com>

From: Masahiko Sawada <sawada.mshk@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-05-08T07:23:15Z
Lists: pgsql-hackers

Attachments

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

Commits

  1. Stabilize subscription stats test.

  2. pgstat: fix subscription stats entry leak.

  3. Create subscription stats entry at CREATE SUBSCRIPTION time

  4. pgstat: drop subscription stats without slot as well, fix comment