Re: min_safe_lsn column in pg_replication_slots view
Kyotaro Horiguchi <horikyota.ntt@gmail.com>
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
To: masao.fujii@oss.nttdata.com
Cc: amit.kapila16@gmail.com, alvherre@2ndquadrant.com, michael@paquier.xyz,
pgsql-hackers@postgresql.org
Date: 2020-07-01T01:32:59Z
Lists: pgsql-hackers
Attachments
At Tue, 30 Jun 2020 23:23:30 +0900, Fujii Masao <masao.fujii@oss.nttdata.com> wrote in
> >> Can we consider an option to "Remove min_safe_lsn; document how a user
> >> can monitor the distance"? We have a function to get current WAL
> >> insert location and other things required are available either via
> >> view or as guc variable values. The reason I am thinking of this
> >> option is that it might be better to get some more feedback on what is
> >> the most appropriate value to display. However, I am okay if we can
> >> reach a consensus on one of the above options.
> > Yes, that's an idea. But it might not be easy to calculate that
> > distance
> > manually by subtracting max_slot_wal_keep_size from the current LSN.
> > Because we've not supported -(pg_lsn, numeric) operator yet. I'm
> > proposing that operator, but it's for v14.
>
> Sorry this is not true. That distance can be calculated without those
> operators.
> For example,
>
> SELECT restart_lsn - pg_current_wal_lsn() + (SELECT setting::numeric *
> 1024 * 1024 FROM pg_settings WHERE name = 'max_slot_wal_keep_size')
> distance FROM pg_replication_slots;
It's an approximation with accuracy of segment size. The calculation
would be not that simple because of the unit of the calculation. The
formula for the exact calculateion (ignoring wal_keep_segments) is:
distance = (seg_floor(restart_lsn) +
seg_floor(max_slot_wal_keep_size) + 1) * wal_segment_size -
current_lsn
where seg_floor is floor() by wal_segment_size.
regards.
> If the calculated distance is small or negative value, which means
> that
> we may lose some required WAL files. So in this case it's worth
> considering
> to increase max_slot_wal_keep_size.
>
> I still think it's better and more helpful to display something like
> that distance in pg_replication_slots rather than making each user
> calculate it...
Agreed. The attached replaces min_safe_lsn with "distance".
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
Commits
-
Fix uninitialized value in segno calculation
- b5b4c0fef9fb 14.0 landed
- 794e8e32bb5a 13.0 landed
-
Morph pg_replication_slots.min_safe_lsn to safe_wal_size
- c54b5891f415 13.0 landed
- a8aaa0c786b3 14.0 landed