PATCH: pageinspect / add page_checksum and bt_page_items(bytea)

From: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: PATCH: pageinspect / add page_checksum and bt_page_items(bytea)
Date: 2017-02-20 16:13:54
Views: Raw Message | Whole Thread | Download mbox
Lists: pgsql-hackers


while investigating some checksum-related issues, I needed to perform
some forensics on a copy of a btree page (taken from another instance
using 'dd').

But I've ran into two pageinspect limitations, hopefully addressed by
this patch:

1) bt_page_items(bytea) not defined

We have heap_page_items(bytea) but not bt_page_items(bytea). I suspect
this is partially historical API inconsistence, and partially due to the
need to handle the btree metapage explicitly.

The original function simply threw an error with blkno=0, the new
function simply checks for BTP_META page.

I believe this is sufficient, assuming the instance without data
corruption (which pageinspect assumes anyway). With data corruption all
bets are off anyway - for example the metapage might be written to a
different block (essentially what I saw in the investigated issue).
Actually, the flag check is better in this case - it detects the
metapage, while the blkno=0 check fails to do that (leading to crash).

2) page_checksum()

When everything is fine, you can do page_header() which also includes
the checksum. When the checksum gets broken, you may still dump the page
using 'dd+pg_read_binary_file' to see the header, but clearly that
checksum is wrong - and it's interesting to see the correct one and
compare it to the checksum in the header.

This function makes it possible - it accepts the bytea image of the
page, and blkno (so it's possible to see how would the block look if it
was written somewhere else, for example).

BTW I've noticed the pageinspect version is 1.6, but we only have
pageinspect--1.5.sql (and upgrade script to 1.6). Not sure that's
entirely intentional?


Tomas Vondra
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachment Content-Type Size
0001-pageinspect-page_checksum-and-bt_page_items-bytea.patch text/x-diff 15.4 KB


Browse pgsql-hackers by date

  From Date Subject
Next Message Christoph Berg 2017-02-20 16:15:56 Re: powerpc(32) point/polygon regression failures on Debian Jessie
Previous Message Tom Lane 2017-02-20 16:12:23 Re: powerpc(32) point/polygon regression failures on Debian Jessie