@jonatasdp, thank you for your answer. I have looked at the code, not being much of a programmer myself, but it looks to me this part of the code is for max_wal_size
parameter. Not really documented clearly in source code to be sure. What I am asking is about wal_segment_size
parameter.
I may not be clear enough. If we look into pg_wal
directory we can see WAL files (or “WAL segments” as officially named). Total amount of all WAL files together is controlled by max_wal_size
(this is actually soft limit, PosgreSQL can decide to use little bit more). The source code you are referring to is most probably about this parameter, the size of total amount of WAL files.
If we look into pg_wal
directory for individual file, we can see one individual file is the size of 16 MB. This is default size of one individual WAL file. To check the size we can execute show wal_segment_size
. Parameter is set only at the cluster creation initdb --wal-segsize=X
or later with pg_resetwal --wal-segsize=X
(this command should be run only if cluster is properly shut-down and should never be run on running server or crashed server). The “X” must be power of two, so 2, 4, 8, 16 (the default), 32 or 64.
Like I understand in heavy load (like time series environment) transactions can easily fill individual 16 MB WAL file. When this happens PostgreSQL must create a new file (usually renames and uses old WAL file that is not required by database anymore, because deleting and creating new files is expensive from performance point of view). But on heavy load systems even this “switching” to new WAL log file can get expensive. For example I see in our production environment in pg_wal directory that in every single minute more then 60 files are filled (time from ls -l
command).
That is why I am asking if someone has changed this parameter (with initdb or pg_resetwal). Any experience on this parameter?
Also in source code you are referring to, there is comment:
// WAL segments are 16MB, so it doesn’t make sense not to round up to the nearest 16MB boundary.
WAL segments are 16 MB by default, but it can be changed (with initdb or pg_resetwal command). The source code assumption is wrong.
This parameter wal_segment_size
is probably not known as good as other parameters and I am wondering if source code comments are like this, assuming 16 MB fixed WAL segment size, if changing this parameter is smart move at all, not to fall into some trap programmers expecting 16 MB fixed size.