full_page_writes

A database page (8KB) is larger than the unit the operating system or disk writes at once (usually 4KB or less). If power fails mid-write, a torn page can remain, with the new content in the front part and the old content in the back part. A WAL record is usually a delta such as "change this part of this page this way", so it cannot be applied on top of a broken page. When full_page_writes is on, the first modification of a page after a checkpoint puts a copy of the whole page (an FPI, Full Page Image) into the WAL. During recovery, PostgreSQL overwrites the page with this copy and then applies the later changes.

Key Specifications

ItemValue
Defaulton
How to changepostgresql.conf or ALTER SYSTEM, applied by reloading the configuration
When a copy is writtenThe first change to each page after a checkpoint
Copy compressionwal_compression: off (default), pglz, lz4, zstd (method selection from 15)
Tear detectionData checksums. Enabled with initdb --data-checksums (on by default from 18)
Changing checksums afterwardStop the server and run pg_checksums --enable
Related settingwal_log_hints (hint-bit changes also write a copy; required for pg_rewind)

How It Works

Figure. The first change after a checkpoint and the next change

flowchart LR
  C["Checkpoint"] --> U1["First change to page 17"]
  U1 --> F["WAL: full image of page 17, 8KB"]
  F --> U2["Second change to page 17"]
  U2 --> R["WAL: delta record only"]
  R --> X["Recovery after power loss"]
  X --> Y["Overwrite with the full image,<br/>then apply later deltas"]

Diagram description: After a Checkpoint, the First change to page 17 leaves a full image of page 17, 8KB in the WAL. From the Second change in the same checkpoint interval on, only a delta record only is written. Recovery starts at the checkpoint, so the first record for the page in that interval is always a full image. Even if the page in the data file was torn, recovery can Overwrite with the full image and continue applying changes.

Cost. Right after a checkpoint, 8KB goes into the WAL for every page that is modified, so the WAL volume surges. Lengthening the checkpoint interval (checkpoint_timeout, max_wal_size) reduces the number of copies, and wal_compression reduces the size of each copy. Widely scattered updates, such as an index on a random primary key, produce especially many copies.

Why you should not turn it off. Do not turn it off unless the storage device guarantees atomic 8KB writes (some file systems and storage systems). If a torn page occurs while it is off, there is no way to recover it.

Relation to checksums. full_page_writes is the means of repairing a torn page, and data checksums are the means of detecting that a page read from disk is corrupt. If a checksum does not match, PostgreSQL raises an invalid page in block error.

Configuration and Inspection

SHOW full_page_writes;
SHOW data_checksums;            -- on means checksums were enabled at initdb
SHOW wal_compression;
ALTER SYSTEM SET wal_compression = 'lz4';
SELECT pg_reload_conf();

-- Number of full page images (from 14)
SELECT wal_fpi, wal_records FROM pg_stat_wal;

Comparison with Other DBMSs

PostgreSQLInnoDBSQL ServerOracle
Tear detectionData checksumPage checksumPAGE_VERIFY CHECKSUMBlock checksum
Intact copyFull page image in the WALdoublewrite areaNone normallyNone normally
RecoveryOverwrite with the image, then RedoReplace with the copy, then RedoRestore the page from a backupRMAN block recovery

In the Articles

NOTE The checksum default and the compression methods can vary by version.

Related pages