liveBook · Manning

Transaction log

As explained in PostgreSQL Mistakes and How to Avoid Them

The write-ahead log is PostgreSQL's sequential log of changes that must be recorded before corresponding data pages are written.

PostgreSQL’s Write-Ahead Log (WAL) is its transaction log: a sequential record of changes written before the corresponding data pages. It preserves data integrity, but it is also a hard operational dependency. If the volume holding WAL fills, PostgreSQL can no longer journal and commit changes; it may panic and shut down. section 5.5 section 7.1

Treat WAL capacity as part of the database’s write capacity, not as spare space for emergencies. A tempting response to a full data volume is to delete old rows, yet DELETE and TRUNCATE themselves generate WAL. MVCC can also leave dead rows requiring VACUUM, which marks reusable table space rather than necessarily returning it to the operating system. VACUUM FULL can release space, but rewrites the table under an ACCESS EXCLUSIVE lock. section 7.1

Avoid two costly WAL mistakes:

  • Do not manually remove WAL files. The former pg_xlog directory, now pg_wal, contains essential transaction-log data; deleting it can make the installation unusable and require rebuilding the cluster from backup. section 7.1.1
  • Do not allow replicated transactions to circulate unchecked. Logical replication streams WAL between nodes; bidirectional subscriptions without origin filtering can send transactions back and forth until extraneous WAL fills disks. section 5.5
  • Do not monitor only table and index size. Track both disk usage and the number and total size of WAL files so retention or replication problems are visible before writes stop. section 7.4

Replication loop that consumes WAL

Two hosts can publish and subscribe to each other, but a transaction received from one host must not be republished back to its origin. Configure origin filtering, such as origin=NONE for native logical replication or forward_origins='{}' for pglogical, to prevent WAL messages from ping-ponging across the cluster. section 5.5

ERROR:  could not extend file "base/12609/16048": No space left on device
HINT:  Check free disk space.

A “could not extend file” error identifies immediate data-volume exhaustion. Check WAL placement too: exhaustion on its volume blocks journaling and commits, making the incident more severe. section 7.1

How PostgreSQL Mistakes and How to Avoid Them covers it

How deep it goes
Explains operational consequences through disk exhaustion, deletion hazards, replication loops, and monitoring metrics; defers WAL record internals.
Examples
Uses bidirectional alpha–beta logical replication and a no-space-left-on-device error to expose WAL risks.
What it assumes
Assumes PostgreSQL administration and SQL familiarity while explaining WAL’s operational role through concrete failures.
What you can do after
Operate/configure it by monitoring WAL size, preserving pg_wal, and filtering replication origins to avoid disk-filling loops.
How it connects
Connects WAL to logical replication, replication origins, MVCC, VACUUM, backups, and disk monitoring.

Also explained in

Compare how 6 books explain transaction log →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of PostgreSQL Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.