Re: Replication slot stats misgivings
Andres Freund <andres@anarazel.de>
From: Andres Freund <andres@anarazel.de>
To: Amit Kapila <amit.kapila16@gmail.com>
Cc: Masahiko Sawada <sawada.mshk@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>, Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>
Date: 2021-03-20T21:26:53Z
Lists: pgsql-hackers
Hi, On 2021-03-20 09:25:40 +0530, Amit Kapila wrote: > On Sat, Mar 20, 2021 at 12:22 AM Andres Freund <andres@anarazel.de> wrote: > > > > And then more generally about the feature: > > - If a slot was used to stream out a large amount of changes (say an > > initial data load), but then replication is interrupted before the > > transaction is committed/aborted, stream_bytes will not reflect the > > many gigabytes of data we may have sent. > > > > We can probably update the stats each time we spilled or streamed the > transaction data but it was not clear at that stage whether or how > much it will be useful. It seems like the obvious answer here is to sync stats when releasing the slot? > > - I seems weird that we went to the trouble of inventing replication > > slot stats, but then limit them to logical slots, and even there don't > > record the obvious things like the total amount of data sent. > > > > Won't spill_bytes and stream_bytes will give you the amount of data sent? I don't think either tracks changes that were neither spilled nor streamed? And if they are, they're terribly misnamed? > > > > I think the best way to address the more fundamental "pgstat related" > > complaints is to change how replication slot stats are > > "addressed". Instead of using the slots name, report stats using the > > index in ReplicationSlotCtl->replication_slots. > > > > That removes the risk of running out of "replication slot stat slots": > > If we loose a drop message, the index eventually will be reused and we > > likely can detect that the stats were for a different slot by comparing > > the slot name. > > > > This idea is worth exploring to address the complaints but what do we > do when we detect that the stats are from the different slot? I think it's pretty easy to make that bulletproof. Add a pgstat_report_replslot_create(), and use that in ReplicationSlotCreate(). That is called with ReplicationSlotAllocationLock held, so it can just safely zero out stats. I don't think: > It has mixed of stats from the old and new slot. Can happen in that scenario. > > It also makes it easy to handle the issue of max_replication_slots being > > lowered and there still being stats for a slot - we simply can skip > > restoring that slots data, because we know the relevant slot can't exist > > anymore. And we can make the initial pgstat_report_replslot() during > > slot creation use a > > > > Here, your last sentence seems to be incomplete. Oops, I was planning to suggest adding pgstat_report_replslot_create() that zeroes out the pre-existing stats (or a parameter to pgstat_report_replslot(), but I don't think that's better). > > I'm wondering if we should just remove the slot name entirely from the > > pgstat.c side of things, and have pg_stat_get_replication_slots() > > inquire about slots by index as well and get the list of slots to report > > stats for from slot.c infrastructure. > > > > But how will you detect in your idea that some of the stats from the > already dropped slot? I don't think that is possible with my sketch? Greetings, Andres Freund
Commits
-
Doc: Update logical decoding stats information.
- 0c6b92d9c6fb 14.0 landed
-
Fix tests for replication slots stats.
- fc69509131c3 14.0 landed
-
Update replication statistics after every stream/spill.
- 592f00f8dec6 14.0 landed
-
Fix the computation of slot stats for 'total_bytes'.
- 205f466282be 14.0 landed
-
Another try to fix the test case added by commit f5fc2f5b23.
- 51ef9173030c 14.0 landed
-
Use HTAB for replication slot statistics.
- 3fa17d37716f 14.0 landed
-
Fix test case added by commit f5fc2f5b23.
- c64dcc7fee5f 14.0 landed
-
Add information of total data processed to replication slot stats.
- f5fc2f5b23d1 14.0 landed
-
Use NameData datatype for slotname in stats.
- cca57c1d9bf7 14.0 landed