# F.23. pageinspect
F.23.1. General FunctionsF.23.2. Heap FunctionsF.23.3. B-Tree FunctionsF.23.4. BRIN FunctionsF.23.5. GIN FunctionsF.23.6. GiST FunctionsF.23.7. Hash Functions
The pageinspect
module provides functions that allow you to inspect the contents of database pages at a low level, which is useful for debugging purposes. All of these functions may be used only by superusers.
# F.23.1. 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, 'vm'
for the visibility map, 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
### F.23.2. Heap Functions
`heap_page_items(page bytea) returns setof record` []()
`heap_page_items` shows all line pointers on a heap page. For those line pointers that are in use, tuple headers as well as tuple raw data are also shown. All tuples are shown, whether or not the tuples were visible to an MVCC snapshot at the time the raw page was copied.
A heap page image obtained with `get_raw_page` should be passed as argument. For example:
test=# SELECT * FROM heap_page_items(get_raw_page('pg_class', 0));
See `src/include/storage/itemid.h` and `src/include/access/htup_details.h` for explanations of the fields returned.
The `heap_tuple_infomask_flags` function can be used to unpack the flag bits of `t_infomask` and `t_infomask2` for heap tuples.
`tuple_data_split(rel_oid oid, t_data bytea, t_infomask integer, t_infomask2 integer, t_bits text [, do_detoast bool]) returns bytea[]` []()
`tuple_data_split` splits tuple data into attributes in the same way as backend internals.
test=# SELECT tuple_data_split('pg_class'::regclass, t_data, t_infomask, t_infomask2, t_bits) FROM heap_page_items(get_raw_page('pg_class', 0));
This function should be called with the same arguments as the return attributes of `heap_page_items`.
If *`do_detoast`* is `true`, attributes will be detoasted as needed. Default value is `false`.
`heap_page_item_attrs(page bytea, rel_oid regclass [, do_detoast bool]) returns setof record` []()
`heap_page_item_attrs` is equivalent to `heap_page_items` except that it returns tuple raw data as an array of attributes that can optionally be detoasted by *`do_detoast`* which is `false` by default.
A heap page image obtained with `get_raw_page` should be passed as argument. For example:
test=# SELECT * FROM heap_page_item_attrs(get_raw_page('pg_class', 0), 'pg_class'::regclass);
`heap_tuple_infomask_flags(t_infomask integer, t_infomask2 integer) returns record` []()
`heap_tuple_infomask_flags` decodes the `t_infomask` and `t_infomask2` returned by `heap_page_items` into a human-readable set of arrays made of flag names, with one column for all the flags and one column for combined flags. For example:
test=# SELECT t_ctid, raw_flags, combined_flags FROM heap_page_items(get_raw_page('pg_class', 0)), LATERAL heap_tuple_infomask_flags(t_infomask, t_infomask2) WHERE t_infomask IS NOT NULL OR t_infomask2 IS NOT NULL;
This function should be called with the same arguments as the return attributes of `heap_page_items`.
Combined flags are displayed for source-level macros that take into account the value of more than one raw bit, such as `HEAP_XMIN_FROZEN`.
See `src/include/access/htup_details.h` for explanations of the flag names returned.
### F.23.3. B-Tree Functions
`bt_metap(relname text) returns record` []()
`bt_metap` returns information about a B-tree index's metapage. For example:
test=# SELECT * FROM bt_metap('pg_cast_oid_index'); -[ RECORD 1 ]-------------+------- magic | 340322 version | 4 root | 1 level | 0 fastroot | 1 fastlevel | 0 last_cleanup_num_delpages | 0 last_cleanup_num_tuples | 230 allequalimage | f
`bt_page_stats(relname text, blkno bigint) returns record` []()
`bt_page_stats` returns summary information about single pages of B-tree indexes. For example:
test=# SELECT * FROM bt_page_stats('pg_cast_oid_index', 1); -[ RECORD 1 ]-+----- blkno | 1 type | l live_items | 224 dead_items | 0 avg_item_size | 16 page_size | 8192 free_size | 3668 btpo_prev | 0 btpo_next | 0 btpo_level | 0 btpo_flags | 3
`bt_page_items(relname text, blkno bigint) returns setof record` []()
`bt_page_items` returns detailed information about all of the items on a B-tree index page. For example:
test=# SELECT itemoffset, ctid, itemlen, nulls, vars, data, dead, htid, tids[0:2] AS some_tids FROM bt_page_items('tenk2_hundred', 5); itemoffset | ctid | itemlen | nulls | vars | data | dead | htid | some_tids
# F.23.4. BRIN Functions
brin_page_type(page bytea) returns text
brin_page_type
returns the page type of the given BRIN index page, or throws an error if the page is not a valid BRIN page. For example:
test=# SELECT brin_page_type(get_raw_page('brinidx', 0));
brin_page_type
### F.23.5. GIN Functions
`gin_metapage_info(page bytea) returns record` []()
`gin_metapage_info` returns information about a GIN index metapage. For example:
test=# SELECT * FROM gin_metapage_info(get_raw_page('gin_index', 0)); -[ RECORD 1 ]----+----------- pending_head | 4294967295 pending_tail | 4294967295 tail_free_size | 0 n_pending_pages | 0 n_pending_tuples | 0 n_total_pages | 7 n_entry_pages | 6 n_data_pages | 0 n_entries | 693 version | 2
`gin_page_opaque_info(page bytea) returns record` []()
`gin_page_opaque_info` returns information about a GIN index opaque area, like the page type. For example:
test=# SELECT * FROM gin_page_opaque_info(get_raw_page('gin_index', 2)); rightlink | maxoff | flags
# F.23.6. GiST Functions
gist_page_opaque_info(page bytea) returns record
gist_page_opaque_info
returns information from a GiST index page's opaque area, such as the NSN, rightlink and page type. For example:
test=# SELECT * FROM gist_page_opaque_info(get_raw_page('test_gist_idx', 2));
lsn | nsn | rightlink | flags
### F.23.7. Hash Functions
`hash_page_type(page bytea) returns text` []()
`hash_page_type` returns page type of the given HASH index page. For example:
test=# SELECT hash_page_type(get_raw_page('con_hash_index', 0)); hash_page_type