My DBA career began with Oracle Database, where recovery is traditionally divided into two failure scenarios: instance failure and media failure.
- Instance recovery (called restart recovery in the ARIES paper) assumes database files remain physically valid. A server, operating system, or database instance stops unexpectedly, leaving pages at different points in time. Transaction logs contain the information needed to restore consistency.
- Media recovery assumes stored data is unusable: a datafile or block is lost or corrupted. Recovery requires another valid copy, usually from a backup, replica, or other redundant storage.
This distinction is fundamental and clearly defined in the ARIES paper. Instance recovery uses the current online files (nonvolatile database and log) that remain after a crash, while media recovery uses restored copies (image copy) when the original storage is damaged.
A torn page falls between these cases. The same failure that triggers crash recovery can also damage the persistent starting point that recovery expects to find. If power fails while an 8 KB page is being written, only part of the write may reach storage, leaving pieces of two versions.
WAL or redo may contain every intended change, but that may not be enough to rebuild the page. Recovery usually applies changes to a valid older page. With a torn page, that starting point may itself be damaged.
Oracle addresses a related issue, fractured blocks, during online backups: a backup tool may read different block sections at different times. The solution resembles the full page logging discussed here, but applies only to external-tool backups. It protects against fractured reads, not writes.
A partial write to an online Oracle data block is different. Oracle Database can detect physical corruption when the block is later read, using checksums, but does not routinely log full-page images to let instance recovery repair it.
The damaged block instead requires media recovery. Block media recovery, available only in Enterprise Edition, restores an individual corrupt block from a valid copy, backup, or standby, without restoring the whole datafile. Standard Edition must restore the entire datafile.
Oracle avoids continuously logging full block images to limit redo costs. It detects rare damage and restores blocks during media recovery, a reasonable trade-off given production databases should have backups or standby copies and run. However, even simple crashes may occasionally require media recovery.
PostgreSQL makes a different trade-off. It uses full-page images (FPIs) in crash recovery to protect against torn pages from partial writes. With full_page_writes enabled by default, the first WAL record modifying a page after a checkpoint normally includes the entire page. If a crash interrupts a data-page write, recovery can use that WAL image to continue.
full_page_writes turns certain crash-induced physical damage into a problem crash recovery can solve. Here, I'll explore them through lab experiments and answer three questions:
What does "protect" mean? It means recovery can restore a complete page from a full-page image (FPI) in WAL, overwriting any mix of old and new sectors left by an interrupted write. PostgreSQL does not scan pages for torn writes during recovery. Normally, a page’s first modification after a checkpoint generates an FPI, giving recovery a complete page before replaying later changes.
What failures are covered? Failures that interrupt a data-page write, such as an OS crash, power loss, or storage failure. A PostgreSQL process crash alone usually cannot tear an I/O operation already handed to the OS, which remains responsible for it. However, storage can tear a page after acknowledging the write. In that case, FPIs do not detect or repair the damage.
What if the WAL full-page image is torn? WAL records include integrity checks, so corruption is detected. If an incomplete record is simply the legitimate end of WAL after a crash, recovery stops there — the normal case. But a corrupt record mid-WAL looks identical: replay stops at the first invalid record, and the database starts at the last valid one, dropping any committed work beyond that point. The log shows the LSN where redo ended (
redo done at ...), but not whether valid WAL existed past it.
FPIs have a high cost: they increase WAL volume, local disk I/O, archiving, replication bandwidth, and WAL retention for physical backups. PostgreSQL pays this cost to repair certain crash-induced damage from WAL instead of needing another copy of the damaged page.
In the lab, I'll deliberately tear a page and demonstrate variations with data checksums and full_page_writes enabled and disabled.
--no-data-checksums and full_page_writes=on
The first example creates a database without checksums, which is still common because they’re enabled by default only for databases created after PG18 (or, more precisely, databases in a cluster created after PG18). Enabling them after upgrading to PG18 requires a long maintenance window. It also enables full-page images, the recommended default.
podman run -d --replace --name PG19 -e POSTGRES_PASSWORD=x \
-e POSTGRES_INITDB_ARGS="--no-data-checksums" \
docker.io/library/postgres \
-c full_page_writes=on
I'll install binutils to use Linux's strings command to inspect the file, and start psql:
podman exec -it PG19 bash -c 'apt update ; apt-get install -y binutils'
podman exec -it -e PGUSER=postgres PG19 psql -P pager=off
I create a table, insert fifty rows containing "Hello World!", and checkpoint to ensure the pages are written to disk:
drop table if exists corruptme
;
create table corruptme as
select generate_series(1,50), 'Hello World!' as value
;
checkpoint
;
I check the data file’s contents:
postgres=# select
current_setting('data_directory')
||
'/'
||
pg_relation_filepath('corruptme'::regclass) as file
;
file
--------------------------------------------
/var/lib/postgresql/19/docker/base/5/16390
(1 row)
postgres=# \gset
postgres=# \setenv file :file
postgres=# \! ls -l $file
-rw------- 1 postgres postgres 8192 Nov 28 23:29 /var/lib/postgresql/19/docker/base/5/16390
postgres=# \! strings $file | uniq -c
50 Hello World!
postgres=#
The file contains fifty "Hello World!".
To simulate a partial write, I’ll make the modifications and checkpoint, then restore the state with only half a page written.
I update all rows, changing "Hello World!" to "Thanks world":
update corruptme set value = 'Thanks world'
;
I save the half-page and checkpoint states for later restoration:
-- copy the second half of the first page
\! dd if="$file" of="$file.tmp" bs=4096 skip=1 count=1
-- copy the control file with the current checkpoint
\! cp /var/lib/postgresql/19/docker/global/pg_control /tmp/pg_control.tmp
I checkpoint and evict the pages from the shared buffers:
checkpoint
;
create extension if not exists pg_buffercache
;
select * from pg_buffercache_evict_all()
;
At this point, the file contains the new version of each row, along with the dead tuple that has not yet been vacuumed:
\! strings $file | uniq -c
postgres=# \! strings $file | uniq -c
50 Thanks world
50 Hello World!
To create a torn page, I replace the page’s second half with its pre-update version:
-- overwrite the last part of the page from the previous version
\! dd if="$file.tmp" of="$file" bs=4096 seek=1 count=1 conv=notrunc
The file contains only fourteen "Thanks world" entries. The others were probably written for the second half, but that part was lost.
postgres=# \! strings $file | uniq -c
14 Thanks world
50 Hello World!
The result may surprise you. PostgreSQL neither detects nor repairs the corruption. It sees the fifty earlier “Hello World!” entries, fourteen "Thanks world” entries, and a partial "Tha” (which we didn't see with strings, since it shows only strings longer than 4 characters by default):
postgres=# select count(*), value from corruptme group by value
;
count | value
-------+--------------
1 | Tha
14 | Thanks world
50 | Hello World!
(3 rows)
The block is corrupted, but without a checksum, PostgreSQL sees nothing wrong. An applicable clean full-page image remains in the WAL, but it wasn’t applied. The checkpoint completed before I corrupted the block, so recovery never started. Full-page logging repairs only torn pages caused by a crash that interrupts a write. If you care about your data, always enable checksums: undetected corruption can otherwise go unnoticed and produce incorrect results.
To simulate corruption occurring before the checkpoint completed—the partial-write scenario FPI protects against—I restore the control file from before the checkpoint and crash the instance:
\! cp /tmp/pg_control.tmp /var/lib/postgresql/19/docker/global/pg_control
\! pkill -9 postgres
The container restarted, and I lost the connection:
postgres=# select count(*), value from corruptme group by value;
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.
The instance recovered, and psql reconnected, so I ran the query again:
postgres=# select count(*), value from corruptme group by value
;
count | value
-------+--------------
50 | Thanks world
(1 row)
postgres=# \q
The state is clean, and the committed update is visible. A crash during checkpoint writing caused PostgreSQL to apply WAL, repair the torn page, and replay the update.
The recovery is visible from the logs (podman logs PG19):
2026-11-29 16:23:28.698 UTC [1] LOG: io worker (PID 64) was terminated by signal 9: Killed
2026-11-29 16:23:28.698 UTC [1] LOG: terminating any other active server processes
2026-11-29 16:23:28.698 UTC [1] LOG: all server processes terminated; reinitializing
2026-11-29 16:23:28.732 UTC [249] LOG: database system was interrupted; last known up at 2026-11-29 16:21:29 UTC
2026-11-29 16:23:29.041 UTC [249] LOG: database system was not properly shut down; automatic recovery in progress
2026-11-29 16:23:29.047 UTC [249] LOG: redo starts at 0/01516C10
2026-11-29 16:23:29.381 UTC [249] LOG: invalid record length at 0/015D9DA8: expected at least 24, got 0
2026-11-29 16:23:29.381 UTC [249] LOG: redo done at 0/015D9D70 system usage: CPU: user: 0.02 s, system: 0.30 s, elapsed: 0.33 s
2026-11-29 16:23:29.403 UTC [250] LOG: checkpoint starting: end-of-recovery fast wait
2026-11-29 16:23:29.440 UTC [250] LOG: checkpoint complete: end-of-recovery fast wait: wrote 101 buffers (0.6%), wrote 3 SLRU buffers; 0 WAL file(s) added, 0 removed, 0 recycled; write=0.014 s, sync=0.010 s, total=0.048 s; sync files=50, longest=0.002 s, average=0.001 s; distance=780 kB, estimate=780 kB; lsn=0/015D9DA8, redo lsn=0/015D9DA8
2026-11-29 16:23:29.453 UTC [1] LOG: database system is ready to accept connections
Restoring an old control file works in this lab because the WAL records remain and the redo point is valid. This simulates a crash before the checkpoint record is written. In a real crash, the control file isn't rolled back—it simply isn't written. Because the WAL checkpoint record is incomplete, recovery starts from the redo point of the previous checkpoint.
Lesson learned: During crash recovery, a full-page image repairs a torn page by replacing it entirely. Recovery can then continue from a clean, complete page and reach the last committed state in the WAL.
Checksums and full_page_writes=on
If checksums were enabled when you created your database or turned them on later, this kind of corruption can be detected—even if it didn’t result from a crash. I ran the same test with checksums enabled, which is the default for new databases in the current version:
podman run -d --replace --name PG19 -e POSTGRES_PASSWORD=x \
docker.io/library/postgres \
-c full_page_writes=on
I've run the same commands, and the difference now is that the corruption is detected:
...
postgres=# \! strings $file | uniq -c
50 Thanks world
50 Hello World!
postgres=# \! dd if="$file.tmp" of="$file" bs=4096 seek=1 count=1 conv=notrunc
1+0 records in
1+0 records out
4096 bytes (4.1 kB, 4.0 KiB) copied, 0.000101 s, 40.6 MB/s
postgres=# \! strings $file | uniq -c
14 Thanks world
50 Hello World!
postgres=# select count(*), value from corruptme group by value
;
ERROR: invalid page in block 0 of relation "base/5/16390"
Enabling checksums is strongly recommended because they can detect corruption even without a crash. Modern storage systems are increasingly complex, and no software is entirely bug-free. Checksums can detect corruption, but they can’t repair it. Repairing a corrupt block requires another copy: restoring a backup and replaying WAL, or fetching the block from a physical standby. Both are manual operations that involve downtime. There's no built-in equivalent of Oracle's block media recovery. As a last resort, setting zero_damaged_pages=on lets recovery continue by zeroing the corrupt page, but this causes data loss: the cluster comes up, while the page’s contents are silently lost.
When restoring a backup, a torn page inside the backup is not necessarily a problem. PostgreSQL forces full-page writes for the entire duration of an online backup (pg_backup_start/pg_backup_stop, pg_basebackup), even when full_page_writes=off, precisely because a file-level copy can read a page while it is being written. Replaying WAL from the backup's start point then repairs any such page — provided it was modified during the backup window, so an FPI exists for it.
The most dangerous case is a page that was already corrupt before the backup began and remained untouched, since no FPI covers it and the corruption may persist after the restore. However, most PostgreSQL backup tools verify checksums during backup:
postgres=# \! pg_basebackup -zFtar -D /var/backup
WARNING: checksum verification failed in file "./base/5/16390", block 0: calculated 56B2 but expected 6A01
WARNING: file "./base/5/16390" has a total of 1 checksum verification failure
WARNING: 1 total checksum verification failure
pg_basebackup: error: checksum error occurred
It's a WARNING: always look at backup warnings
full_page_writes=off
I hope you’re convinced that checksums and FPI are both needed to detect and repair torn pages. They’re complementary, not alternatives: checksums detect corruption during reads, while full_page_writes repair torn writes caused by crashes during recovery.
For a better understanding, here’s my lab’s latest test: disable FPI:
podman run -d --replace --name PG19 -e POSTGRES_PASSWORD=x \
docker.io/library/postgres \
-c full_page_writes=off
As checksums are enabled, the same scenario detected corruption:
...
postgres=# select count(*), value from corruptme group by value
;
ERROR: invalid page in block 0 of relation "base/5/16384"
As before, I restore the pre-checkpoint control file to force recovery, as if the corruption had occurred during a crash:
postgres=# \! cp /tmp/pg_control.tmp /var/lib/postgresql/19/docker/global/pg_control
postgres=# \! pkill -9 postgres
The difference is that I'm disconnected and cannot reconnect:
podman exec -it -e PGUSER=postgres PG19 psql -P pager=off
Error: can only create exec sessions on running containers: container state improper
The container didn't restart because PostgreSQL didn't recover. Here is the log:
2026-11-29 00:22:36.013 UTC [62] LOG: page verification failed, calculated checksum 47342 but expected 53001
2026-11-29 00:22:36.013 UTC [62] CONTEXT: I/O worker executing I/O on behalf of process 222
2026-11-29 00:22:36.013 UTC [62] LOG: invalid page in block 0 of relation "base/5/16384"
2026-11-29 00:22:36.013 UTC [62] CONTEXT: I/O worker executing I/O on behalf of process 222
2026-11-29 00:22:36.013 UTC [222] ERROR: invalid page in block 0 of relation "base/5/16384"
2026-11-29 00:22:36.013 UTC [222] STATEMENT: select count(*), value from corruptme group by value
;
2026-11-29 00:22:48.268 UTC [1] LOG: io worker (PID 62) was terminated by signal 9: Killed
2026-11-29 00:22:48.268 UTC [1] LOG: terminating any other active server processes
2026-11-29 00:22:48.268 UTC [1] LOG: all server processes terminated; reinitializing
2026-11-29 00:22:48.306 UTC [247] LOG: database system was interrupted; last known up at 2026-11-29 00:20:49 UTC
2026-11-29 00:22:48.534 UTC [247] LOG: database system was not properly shut down; automatic recovery in progress
2026-11-29 00:22:48.540 UTC [247] LOG: redo starts at 0/017630A8
2026-11-29 00:22:48.544 UTC [247] LOG: page verification failed, calculated checksum 47342 but expected 53001
2026-11-29 00:22:48.544 UTC [247] CONTEXT: WAL redo at 0/0177C208 for Heap/HOT_UPDATE: old_xmax: 675, old_off: 1, old_infobits: [], flags: 0x20, new_xmax: 0, new_off: 51; blkref #0: rel 1663/5/16384, blk 0
2026-11-29 00:22:48.545 UTC [247] LOG: invalid page in block 0 of relation "base/5/16384"
2026-11-29 00:22:48.545 UTC [247] CONTEXT: WAL redo at 0/0177C208 for Heap/HOT_UPDATE: old_xmax: 675, old_off: 1, old_infobits: [], flags: 0x20, new_xmax: 0, new_off: 51; blkref #0: rel 1663/5/16384, blk 0
2026-11-29 00:22:48.545 UTC [247] FATAL: invalid page in block 0 of relation "base/5/16384"
2026-11-29 00:22:48.545 UTC [247] CONTEXT: WAL redo at 0/0177C208 for Heap/HOT_UPDATE: old_xmax: 675, old_off: 1, old_infobits: [], flags: 0x20, new_xmax: 0, new_off: 51; blkref #0: rel 1663/5/16384, blk 0
2026-11-29 00:22:48.556 UTC [1] LOG: startup process (PID 247) exited with exit code 1
2026-11-29 00:22:48.556 UTC [1] LOG: terminating any other active server processes
2026-11-29 00:22:48.557 UTC [1] LOG: shutting down due to startup process failure
2026-11-29 00:22:48.564 UTC [1] LOG: database system is shut down
A regular redo record — not a full image — must apply its change to the page as found on disk. Redo read the torn page, the checksum failed, and recovery aborted. This requires media recovery (a backup, a standby copy, or zero_damaged_pages accepting data loss), not crash recovery — even though a crash is what triggered recovery.
Trade-off: the cost of FPI
Write-ahead logging (WAL) supports crash recovery by replaying logged changes onto usable database pages. PostgreSQL’s full-page images can also replace torn or otherwise unusable on-disk pages during recovery. This sound design reflects the distinction made in the ARIES paper: crash recovery alone can restore the database after a crash, but it comes at a cost. No database implementation is inherently better; each involves trade-offs.
I've run the same scenario with EXPLAIN (ANALYZE, WAL) for the update. With FPI explicitly disabled (not the default, and not a recommendation unless your storage guarantees protection from torn pages), the UPDATE's WAL records are on average 80 bytes per update row:
postgres=# explain (analyze, buffers, wal, IO, costs off)
update corruptme
set value = 'Thanks world'
;
QUERY PLAN
---------------------------------------------------------------------------
Update on corruptme (actual time=0.209..0.212 rows=0.00 loops=1)
Buffers: shared hit=101 dirtied=1
WAL: records=51 bytes=4044
-> Seq Scan on corruptme (actual time=0.031..0.072 rows=50.00 loops=1)
Prefetch: avg=1.00 max=1 capacity=94
Buffers: shared hit=1 dirtied=1
WAL: records=1 bytes=44
Planning:
Buffers: shared hit=9
Planning Time: 0.405 ms
Execution Time: 0.708 ms
(11 rows)
All 50 rows fit on one page, so only one buffer was dirtied (dirtied=1). This occurred during the Seq Scan, which generated one WAL record—likely a transaction- or visibility-related record—of bytes=44. The update logged 50 additional records, one per updated row, averaging 80 bytes each (new tuple data plus header metadata such as xmax, offsets, and flags).
With FPI enabled, more WAL bytes were generated, and the FPI part is detailed:
postgres=# explain (analyze, buffers, wal, IO, costs off)
update corruptme set value = 'Thanks world'
;
QUERY PLAN
---------------------------------------------------------------------------
Update on corruptme (actual time=0.180..0.182 rows=0.00 loops=1)
Buffers: shared hit=101 dirtied=1
WAL: records=51 fpi=1 bytes=6673 fpi bytes=2624
-> Seq Scan on corruptme (actual time=0.036..0.075 rows=50.00 loops=1)
Prefetch: avg=1.00 max=1 capacity=94
Buffers: shared hit=1 dirtied=1
WAL: records=1 fpi=1 bytes=2673 fpi bytes=2624
Planning:
Buffers: shared hit=9
Planning Time: 0.294 ms
Execution Time: 0.536 ms
(11 rows)
Exactly one full-page image (fpi=1) was emitted for the first post-checkpoint record to touch the page- the WAL-logged Seq Scan modification. The total bytes=6673 is 2629 bytes more, roughly the FPI itself (fpi bytes=2624) plus record overhead. WAL compression is enabled by default, and my page of 50 near-identical short tuples and free space compresses well, making it smaller than the 8k page size.
Conclusion
Write-ahead logging (WAL) addresses a basic crash-recovery problem: memory is volatile, while storage is persistent. A crash can erase in-memory changes, and disk datafiles may contain pages from different points in time. WAL records changes before data pages are written, allowing recovery to replay missing changes. PostgreSQL checkpoints mark how far datafiles are known to be durable and where recovery should begin.
Ordinary WAL recovery assumes disk pages may be old but remain structurally valid. A torn write violates that assumption: a page can combine parts of different versions. Even if WAL contains every change, redo cannot proceed without a valid starting page.
PostgreSQL uses two complementary mechanisms:
- Checksums detect damage. Without them, as the first experiment showed, PostgreSQL may read a torn page and interpret corrupted contents as data. Detection matters because replaying WAL against an unknown or malformed page is unsafe.
-
Full-page images (FPIs) repair damage. With
full_page_writesenabled, the first WAL record modifying a page after a checkpoint normally includes its complete image. If recovery finds a page torn by an interrupted write, PostgreSQL can restore that image before applying later WAL records.
Checksums identify an untrustworthy page but cannot reconstruct it. An FPI supplies a complete page from which redo can continue. Together, they can keep a failure that might otherwise require media recovery within instance recovery.
The full_page_writes=off experiment shows the limit. WAL survived and contained the updates, but recovery found a corrupt data page. The checksum detected the damage, but ordinary redo could not repair it, so recovery stopped. A valid copy—from backup, standby, or another source—is then needed for media recovery. The crash caused the failure, but crash recovery alone could not fix it.
Database systems preserve recoverable state differently. PostgreSQL records repair information in WAL as FPIs. InnoDB (MySQL) writes pages to a doublewrite buffer before their datafile locations, allowing recovery to restore an intact copy after an interrupted write and apply redo. WiredTiger (MongoDB) checkpoints modified B-tree pages as new versions, preserving the previous checkpoint. YugabyteDB's DocDB uses a RocksDB-based LSM-tree, flushing memtable writes into immutable SST files instead of updating B-tree pages in place. Each approach gives redo a valid persistent state from which to recover.
What if WAL itself is torn?
This differs from a torn data page. WAL is a sequential stream, and its records include integrity information that detects corruption. However, WAL has no second full copy of each record like a data-page FPI. If recovery needs a genuinely corrupt record, it cannot reconstruct it from neighboring records. It needs another valid copy, such as an archive or another server.
WAL’s sequential order distinguishes it from random data-page corruption. A torn page may sit among valid newer pages and transactions, creating a gap ordinary redo cannot cross. WAL provides an ordered recovery frontier: recovery advances only through the valid log prefix. An incomplete record at the legitimate end marks where crash recovery stops.
The three questions have complementary answers:
-
What does
full_page_writesprotect? It gives recovery a complete page image instead of relying on redo against a potentially torn page. - Which failures does it cover? Torn data-page writes when recovery replays an applicable FPI. Checksums complement this by detecting corruption outside that recovery path.
- What if the FPI in WAL is torn? Record integrity checks detect the corruption, but WAL contains no extra copy to reconstruct it.
WAL primarily protects against the loss of volatile state. Checksums prevent reliance on damaged persistent state, while FPIs restore a valid data-page state for WAL to operate on.
In short: WAL records what happened, checksums determine whether a page is trustworthy, and FPIs can restore a trustworthy page during recovery.
Beyond full page images (FPI)
Torn-write protection can move below PostgreSQL, eliminating the need to log full-page images when the storage stack provides another guarantee that an 8 KB page cannot be partially overwritten.
Some storage provides this guarantee directly. Azure Managed Disks, for example, support atomic aligned 8 KiB and 16 KiB writes on supported Linux/NVMe configurations: the entire block is persisted, or none of it is. However, the guarantee requires large atomic writes to reach the device through a supported direct-I/O path, whereas PostgreSQL normally uses buffered I/O.
ZFS achieves a similar goal differently, through copy-on-write. Modified blocks are written to new locations rather than overwriting the existing blocks in place. The previous version therefore remains available while the new version is being made durable. The important principle is the same: don't leave recovery with a page containing a mixture of two versions.
Azure HorizonDB takes this further by separating PostgreSQL compute from relation-page persistence. The writer makes transactions durable through a zone-resilient WAL service, while a shared-storage fleet of page servers maintains relation data and applies WAL independently of the compute nodes.
HorizonDB page servers don't update PostgreSQL pages in place. They persist data into immutable, append-only layer files rather than overwriting an existing 8 KB page. An interrupted write of a new layer cannot turn the previously valid PostgreSQL page into a half-old, half-new page. The previous version remains available, and the required page state can be reconstructed from stored versions and WAL.
This doesn't make integrity checking unnecessary. HorizonDB's storage architecture uses checksums and LSN/sequence validation, maintains redundant data and WAL copies, and has mechanisms to reconstruct data from an earlier consistent state and WAL.
The distinction is important: full_page_writes=off doesn't mean torn-write protection has been sacrificed. The responsibility has moved. HorizonDB offloads page persistence, torn-page protection, checkpointing, and dirty-page writing from PostgreSQL compute to its distributed storage architecture, allowing the compute nodes to run with full_page_writes=off.
That eases pressure on PostgreSQL’s write path: fewer WAL bytes from FPIs, no compute-side writes of checkpoint data pages, and less storage I/O competing with application workloads. The safety guarantee remains, but the scale-out storage architecture provides it instead of the PostgreSQL compute node, which can scale only vertically.
Top comments (0)