Starting with PostgreSQL 13 there is a name and value change of one of the parameters used for the streaming replication of a replica server. Some may already know which parameter I am talking about. Until Postgres 12 it was called “wal_keep_segments” but with PostgreSQL 13 it will become “wal_keep_size”.
In this small post I will explain, what changed and which nice new feature Patroni 2.0 offers us to not get in trouble using old configuration files.
If you have ever setup a replica server with PostgreSQL you may have met wal_keep_segments. An integer parameter that defines the minimum number of log files segments that should be kept in the pg_wal directory. In case this parameter is zero (default) or too small, it is possible that there are not enough wal files kept in pg_wal in case of an disconnection of the standby server.
Each segment normally has a size of 16 MB.
If you want to go a bit deeper into that topic, you can also have a look at the PostgreSQL documentation.
wal_keep_size and what changed
With PostgreSQL 13 things will look a bit different. wal_keep_segments is replaced by wal_keep_size. The parameter has still the same purpose. Define the kept log files segments, but now we define the size of the log files segments instead of the number. If you don’t specify a unit, MB will be taken as the default. There is a simple formular, that helps you to calculate the value of the wal_keep_size:
wal_keep_size = wal_keep_segments * wal_segment_size (typically 16MB)
New Patroni 2.0 feature
As this change is quite essential for a Patroni cluster and its setup, the developers of Patroni implemented a really nice feature in the new Patroni 2.0 version. In case you use an old patroni.yml, as I did in my last blog post, Patroni will automatically recognize the old parameter and reset it with the new one and the new value as well.
[email protected]:/home/postgres/ [PG1] cat /u01/app/postgres/local/dmk/etc/patroni.yml | grep wal_keep wal_keep_segments: 8 [email protected]:/home/postgres/ [PG1] patronictl edit-config | grep wal_keep Vim: Warning: Output is not to a terminal wal_keep_segments: 8 [email protected]:/home/postgres/ [PG1] sq psql (13beta3 dbi services build) Type "help" for help. postgres=# show wal_keep_size; wal_keep_size --------------- 128MB (1 row) postgres=# show wal_keep_segments; ERROR: unrecognized configuration parameter "wal_keep_segments"
Compare that values with the above formular, we see that it work. 8 * 16MB = 128MB. It executes the change in the background
I think this is a quite small new feature, but it’s very helpful. Of course, there will be many people not thinking about that change in the beginning. So Patroni helps to minimize a human error here.