DEV Community

Raja Rakshak
Raja Rakshak

Posted on

Write Ahead Logging: PostgreSQL

In the event of system failures, the Write Ahead Logging(WAL) protocol assures durability and data recovery. These are the few topics discussed in WAL.

Insertion Operations: Data entered into the database is susceptible to loss in the event of system failures without WAL.

Database recovery and insertion operations: PostgreSQL uses the WAL method to write all modifications as historical information into a transaction log. When a transaction commits or aborts, XLOG records, or WAL data, are written to the in-memory WAL buffer and then flushed to the WAL segment file. Replaying XLOG records from the REDO point, or the location at the most recent checkpoint, is a step in the recovery process.

Full-Page Writes: PostgreSQL allows full-page writes to address failures where the page data on the storage is corrupted. Following a checkpoint, a backup block (full-page image) containing the whole page is written as an XLOG record during the first change of each page.

WAL, Backup, and Replication: While WAL protects against process or operating system failures, file-system or media failures require extra safeguards like online backups and synchronous replication.

WAL segment files, which are generally typically 16 MB in size, are used to separate the transaction log in PostgreSQL. A timelineId and LSN (Log Sequence Number) information are included in the naming convention for WAL segment files.

A WAL segment file is internally divided into pages, with the first page containing a header and all subsequent pages containing XLOG records in descending order.

Top comments (0)