DEV Community

Abhi-Kmr2046
Abhi-Kmr2046

Posted on

WAL buffer and WAL segment file

WAL stands for Write-Ahead Logging. It is a standard method for ensuring data integrity. WAL data is a description of changes made to the actual data, and is also known as metadata.

WAL’s central concept is that changes to data files (where tables and indexes reside) must be written only after those changes have been logged, that is, after log records describing the changes have been flushed to persistent storage. This ensures that in the event of any error, we will be able to recover the database using the log. Any changes that have not been applied to the data pages can be redone from the log records. This is roll-forward recovery, also known as REDO.
WAL buffers and WAL segment files are two components of the WAL system in PostgreSQL.

WAL buffers are in-memory buffers that temporarily hold transactions until they are written to disk. They are used to speed up write operations by allowing transactions to be written to disk in batches rather than one at a time. If the WAL buffer becomes full, the contents of the buffer are dumped into a WAL segment file.

WAL segment files are on-disk files that store the contents of the WAL buffer when it becomes full. They are used to ensure that all transactions are written to disk before being acknowledged as complete. When a new transaction is started, it is written to a new WAL segment file.

Top comments (0)