postgresql_16:9.6.25.1 General Functions
PostgreSQL 16 > Appendixes > Additional Supplied Modules and Extensions > pageinspect — low-level inspection of database pages > General Functions
get_raw_page(relname text, fork text, blkno bigint) returns bytea
get_raw_page reads the specified block of the named relation and returns a copy as a bytea value. This allows a single time-consistent copy of the block to be obtained. *fork* should be 'main' for the main data fork, 'fsm' for the free space map (see postgresql_16:8.22.3), 'vm' for the visibility map (see postgresql_16:8.22.4), or 'init' for the initialization fork.
get_raw_page(relname text, blkno bigint) returns bytea
A shorthand version of get_raw_page, for reading from the main fork. Equivalent to get_raw_page(relname, 'main', blkno)
page_header(page bytea) returns record
page_header shows fields that are common to all PostgreSQL heap and index pages.
A page image obtained with get_raw_page should be passed as argument. For example: test=# SELECT * FROM page_header(get_raw_page('pg_class', 0)); lsn | checksum | flags | lower | upper | special | pagesize | version | prune_xid -----------+----------+--------+-------+-------+---------+----------+---------+----------- 0/24A1B50 | 0 | 1 | 232 | 368 | 8192 | 8192 | 4 | 0 The returned columns correspond to the fields in the PageHeaderData struct. See src/include/storage/bufpage.h for details.
The checksum field is the checksum stored in the page, which might be incorrect if the page is somehow corrupted. If data checksums are not enabled for this instance, then the value stored is meaningless.
page_checksum(page bytea, blkno bigint) returns smallint
page_checksum computes the checksum for the page, as if it was located at the given block.
A page image obtained with get_raw_page should be passed as argument. For example: test=# SELECT page_checksum(get_raw_page('pg_class', 0), 0); page_checksum --------------- 13443 Note that the checksum depends on the block number, so matching block numbers should be passed (except when doing esoteric debugging).
The checksum computed with this function can be compared with the checksum result field of the function page_header. If data checksums are enabled for this instance, then the two values should be equal.
fsm_page_contents(page bytea) returns text
fsm_page_contents shows the internal node structure of an FSM page. For example: test=# SELECT fsm_page_contents(get_raw_page('pg_class', 'fsm', 0)); The output is a multiline string, with one line per node in the binary tree within the page. Only those nodes that are not zero are printed. The so-called "next" pointer, which points to the next slot to be returned from the page, is also printed.
See src/backend/storage/freespace/README for more information on the structure of an FSM page.