8
Non-Atomic Page Writes
Full page image
page might be partially written if a crash occurs
full page image (FPI) is written to the WAL
upon its first modification after a checkpoint
during recovery, WAL records are applied to the saved image
Settings
full_page_writes = on
wal_compression = off
increases
WAL size
Thirdly, there is an issue of atomicity of writing.
A data page is 8 KB in size (or larger: 16 KB, 32 KB), while at the low level,
writing is done in blocks that are typically smaller (512 bytes, 4 KB, etc.).
Therefore, in case of a power outage, a data page can be written partially.
It is clear that during recovery, it makes no sense to apply regular WAL
records to such a page.
To prevent this, PostgreSQL can write a full page image (FPI) to the WAL
the first time a page is modified after a checkpoint. This feature is turned
on/off by the full_page_writes parameter and should only be disabled if the
file system and hardware themselves guarantee atomic writing.
When we encounter an FPI in the WAL during recovery, we definitely write it
to disk (since it is more reliable, as it is protected by a checksum like all WAL
records). Then we apply regular WAL records to this restored page.
Although PostgreSQL excludes unused space from FPIs, they still
significantly increase WAL volume. If page checksums are enabled in the
cluster, an additional WAL record is generated when hint bits are modified,
reflecting the checksum change.
We can reduce WAL size by enabling FPI compression with the
wal_compression parameter. Supported compression methods are pglz, lz4,
and zstd. “On” selects the pglz method, “off” disables compression.