Re: max_slot_wal_keep_size unit is not specified

2021-11-25 Thread Alvaro Herrera
On 2021-Nov-24, Kyotaro Horiguchi wrote:

> At Tue, 23 Nov 2021 11:21:05 -0300, Alvaro Herrera  
> wrote in 

> > I wonder why did we make it round down rather than up.  Does this mean
> > that if you have max_slot_wal_keep_size=8MB and wal segments of 16 MB,
> > the slot gets invalidated with more than zero reserved segments?
> 
> That rounding behavior is the way we are generally doing on similar
> variables. It is based on the behavior of ConvertToXSegs(). So
> max_wal_size for example is rounded-up the same way.

After thinking on it some more, I think rounding down is correct.  If
somebody sets max_slot_wal_keep_size=40MB, then by keeping the limit at
32 MB (round down) we're honoring that request better than if we made it
48 MB (round up).  But in any case, I think it doesn't matter much:
users need a *rough* size limit, not a super-precise one.  After all,
this is only verified at checkpoint time.  We're probably dealing with a
few hundreds of megabytes at least, so 16 MB one way or the other don't
change things much.

Here's a proposed patch.

-- 
Álvaro Herrera   39°49'30"S 73°17'W  —  https://www.EnterpriseDB.com/
"Las mujeres son como hondas:  mientras más resistencia tienen,
 más lejos puedes llegar con ellas"  (Jonas Nightingale, Leap of Faith)
>From bfbc099a1ea5a4eec57d5d25c0dbb616e8724182 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera 
Date: Thu, 25 Nov 2021 11:29:41 -0300
Subject: [PATCH] Document units for max_slot_wal_keep_size

---
 doc/src/sgml/config.sgml | 5 +
 1 file changed, 5 insertions(+)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 3f806740d5..918d7ebd01 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -4175,6 +4175,11 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"'  # Windows
 to continue replication due to removal of required WAL files. You
 can see the WAL availability of replication slots
 in pg_replication_slots.
+The value is rounded down to an integer number of WAL files
+according to wal_segment_size.
+If this value is specified without units, it is taken as megabytes.
+This parameter can only be set in the
+postgresql.conf file or on the server command line.


   
-- 
2.30.2



Re: max_slot_wal_keep_size unit is not specified

2021-11-25 Thread Kyotaro Horiguchi
At Thu, 25 Nov 2021 11:37:37 -0300, Alvaro Herrera  
wrote in 
> On 2021-Nov-24, Kyotaro Horiguchi wrote:
> 
> > At Tue, 23 Nov 2021 11:21:05 -0300, Alvaro Herrera 
> >  wrote in 
> 
> > > I wonder why did we make it round down rather than up.  Does this mean
> > > that if you have max_slot_wal_keep_size=8MB and wal segments of 16 MB,
> > > the slot gets invalidated with more than zero reserved segments?
> > 
> > That rounding behavior is the way we are generally doing on similar
> > variables. It is based on the behavior of ConvertToXSegs(). So
> > max_wal_size for example is rounded-up the same way.

(no.. rounded-down X)

> After thinking on it some more, I think rounding down is correct.  If
> somebody sets max_slot_wal_keep_size=40MB, then by keeping the limit at
> 32 MB (round down) we're honoring that request better than if we made it
> 48 MB (round up).  But in any case, I think it doesn't matter much:
> users need a *rough* size limit, not a super-precise one.  After all,
> this is only verified at checkpoint time.  We're probably dealing with a
> few hundreds of megabytes at least, so 16 MB one way or the other don't
> change things much.

I thought exactly on that line at development.

Regarding the proposed description, we have never explained how the
same kind of values specified in megabytes is converted into internal
units.  If we add that explanation there, we might want the same for
max_wal_size, min_wal_size and wal_keep_size.

> Here's a proposed patch.

+The value is rounded down to an integer number of WAL files
+according to wal_segment_size.

The same section starts with the following sentences.

>Specify the maximum size of WAL files
>that replication
>slots are allowed to retain in the pg_wal
>directory at checkpoint time.

FWIW I thought (or intended) that "the maximum size of WAL files that
slots are *allowed to retain*" connotes the same to the sentences
cited above.

Premising "16 MB one way or the other don't change things much", I'm
not sure we really need to be particular about a few megabites
difference especially only for this specific variable.

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center