DEV Community

Pawan Kukreja
Pawan Kukreja

Posted on • Updated on

[Summary] Chapter#09 "The Internals of PostgreSQL" Write Ahead Logging (WAL) (Part-01)

It is a rule to write both changes and actions into a transaction log, In PostgreSQL this term is used opposite of transaction log and used to refer to implement mechanism related to writing actions to transaction log.
following is introduction of some topics:

  • The logical and physical Structure
  • The internal layout of WAL data
  • Writing on WAL data
  • The checkpoint processing
  • The database recovery processing
  • Managing WAL segment files
  • Continuous archiving

Insertion Operation without WAL
To provide efficient access to the relation's pages, every dbms implements shared buffer pool.

Insertion Operation and Database Recovery
PostgreSQL writes all modifications as history data into a persistent storage, to prepare for failures, and history data are known as WAL Data.
Record written into in-memory WAL buffer by change operations such as insertion and deletion or commit action.
REDO point recover from the PostgreSQL database, it is the point that is location to write XLOG record at the moment when latest checkpoints is started.

Full-Page Writes
This system deals with failure of data, PostgreSQL writes a pair of the header-data and the entire page as XLOG record during the first change of each page after every checkpoint.

Transaction Log and WAL segment Files
Logically, PostgreSQL writes XLOG records into the transaction log which is a virtual file 8-byte long.
Transaction log in PostgreSQL is divided into files of 16-Mbyte by default, each of which knows as WAL segment.

Internal Layout of WAL Segment
WAL segment is a 16 MB file, by default and it is internally divided into pages of 8192 bytes.

Internal Layout of XLOG Record
XLOG record first subsection describes the header structure and remaining two describe structure of data portion.

Header Portion
All XLOG records have a general header portion defined by the structure of XLogRecord.

Data Portion of XLOG Record
This structure formate is to maintain the source code to implement new features.
It is comprise of Backup block or non backup block

Backup Log
It is composed of two data structures and one data object.

  • The Structure XLogRecord
  • The Structure BkpBlock
  • The entire page apart from its free-space

Non-Backup Block
This is also Comprised of two data structures an one data object.

  • The structure XogRecord
  • The structure xl_heap_insert
  • The inserted tuple-to be precise, a few bytes is removed from the tuple.

Reference

Top comments (0)