Note

Full-page writes and torn pages

A torn page is what you get when the operating system writes only part of an 8 KB PostgreSQL page before power is lost: the disk sector size is smaller than the page, so half the page can be new and half old. Replaying a normal WAL record against such a page would corrupt it further, because the record assumes the page looked exactly like it did before the change.

PostgreSQL’s answer is the full-page write (also called a full-page image, FPI): the first time a page is modified after a checkpoint, the WAL record carries the entire page, not just the delta. On recovery, that copy simply overwrites whatever is on disk, torn or not. Later changes to the same page before the next checkpoint carry only deltas, because the full copy in the log has already made the page’s starting state safe.

full_page_writes can be turned off on storage that guarantees atomic page writes. Most people should not.

Related: pd_lsn vs record LSN.

Comments

    Plain text; `backticks` for code, and at most 2 links. I read every comment before it appears.

    Your name shows as you type it. An email, given only for replies, is never shown or used for anything else, and is deleted after 180 days. Until I have read your comment, only this browser shows it to you; it keeps a key to withdraw it for 24 hours. More on what is kept.

    ↑↓ move · ↵ open · esc close