| F.35. pageinspect | ||||
|---|---|---|---|---|
| Prev | Up | Appendix F. Additional Supplied Modules and Extensions Shipped inpostgrespro-std-15-contrib | Home | Next |
F.35. pageinspect
Thepageinspect 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.35.1. General Functions
get_raw_page(relname text, fork text, blkno bigint) returns byteaget_raw_pagereads the specified block of the named relation and returns a copy as abyteavalue. This allows a single time-consistent copy of the block to be obtained.forkshould be'main'for the main data fork,'fsm'for thefree space map,'vm'for thevisibility map, or'init'for the initialization fork.get_raw_page(relname text, blkno bigint) returns byteaA shorthand version of
get_raw_page, for reading from the main fork. Equivalent toget_raw_page(relname, 'main', blkno)page_header(page bytea) returns recordpage_headershows fields that are common to allPostgres Pro heap and index pages.A page image obtained with
get_raw_pageshould 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 | 0The returned columns correspond to the fields in the
PageHeaderDatastruct.The
checksumfield 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 smallintpage_checksumcomputes the checksum for the page, as if it was located at the given block.A page image obtained with
get_raw_pageshould be passed as argument. For example:test=# SELECT page_checksum(get_raw_page('pg_class', 0), 0); page_checksum--------------- 13443Note 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
checksumresult field of the functionpage_header. If data checksums are enabled for this instance, then the two values should be equal.fsm_page_contents(page bytea) returns textfsm_page_contentsshows the internal node structure of anFSM 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.
F.35.2. Heap Functions
heap_page_items(page bytea) returns setof recordheap_page_itemsshows 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_pageshould be passed as argument. For example:test=# SELECT * FROM heap_page_items(get_raw_page('pg_class', 0));The
heap_tuple_infomask_flagsfunction can be used to unpack the flag bits oft_infomaskandt_infomask2for 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_splitsplits 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_detoastistrue, attributes will be detoasted as needed. Default value isfalse.heap_page_item_attrs(page bytea, rel_oid regclass [, do_detoast bool]) returns setof recordheap_page_item_attrsis equivalent toheap_page_itemsexcept that it returns tuple raw data as an array of attributes that can optionally be detoasted bydo_detoastwhich isfalseby default.A heap page image obtained with
get_raw_pageshould 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 recordheap_tuple_infomask_flagsdecodes thet_infomaskandt_infomask2returned byheap_page_itemsinto 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.
F.35.3. B-Tree Functions
bt_metap(relname text) returns recordbt_metapreturns information about a B-tree index's metapage. For example:test=# SELECT * FROM bt_metap('pg_cast_oid_index');-[ RECORD 1 ]-------------+-------magic | 340322version | 4root | 1level | 0fastroot | 1fastlevel | 0last_cleanup_num_delpages | 0last_cleanup_num_tuples | 230allequalimage | fbt_page_stats(relname text, blkno bigint) returns recordbt_page_statsreturns 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 | 1type | llive_items | 224dead_items | 0avg_item_size | 16page_size | 8192free_size | 3668btpo_prev | 0btpo_next | 0btpo_level | 0btpo_flags | 3bt_page_items(relname text, blkno bigint) returns setof recordbt_page_itemsreturns 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------------+-----------+---------+-------+------+-------------------------+------+--------+--------------------- 1 | (16,1) | 16 | f | f | 30 00 00 00 00 00 00 00 | | | 2 | (16,8292) | 616 | f | f | 24 00 00 00 00 00 00 00 | f | (1,6) | {"(1,6)","(10,22)"} 3 | (16,8292) | 616 | f | f | 25 00 00 00 00 00 00 00 | f | (1,18) | {"(1,18)","(4,22)"} 4 | (16,8292) | 616 | f | f | 26 00 00 00 00 00 00 00 | f | (4,18) | {"(4,18)","(6,17)"} 5 | (16,8292) | 616 | f | f | 27 00 00 00 00 00 00 00 | f | (1,2) | {"(1,2)","(1,19)"} 6 | (16,8292) | 616 | f | f | 28 00 00 00 00 00 00 00 | f | (2,24) | {"(2,24)","(4,11)"} 7 | (16,8292) | 616 | f | f | 29 00 00 00 00 00 00 00 | f | (2,17) | {"(2,17)","(11,2)"} 8 | (16,8292) | 616 | f | f | 2a 00 00 00 00 00 00 00 | f | (0,25) | {"(0,25)","(3,20)"} 9 | (16,8292) | 616 | f | f | 2b 00 00 00 00 00 00 00 | f | (0,10) | {"(0,10)","(0,14)"} 10 | (16,8292) | 616 | f | f | 2c 00 00 00 00 00 00 00 | f | (1,3) | {"(1,3)","(3,9)"} 11 | (16,8292) | 616 | f | f | 2d 00 00 00 00 00 00 00 | f | (6,28) | {"(6,28)","(11,1)"} 12 | (16,8292) | 616 | f | f | 2e 00 00 00 00 00 00 00 | f | (0,27) | {"(0,27)","(1,13)"} 13 | (16,8292) | 616 | f | f | 2f 00 00 00 00 00 00 00 | f | (4,17) | {"(4,17)","(4,21)"}(13 rows)This is a B-tree leaf page. All tuples that point to the table happen to be posting list tuples (all of which store a total of 100 6 byte TIDs). There is also a“high key” tuple at
itemoffsetnumber 1.ctidis used to store encoded information about each tuple in this example, though leaf page tuples often store a heap TID directly in thectidfield instead.tidsis the list of TIDs stored as a posting list.In an internal page (not shown), the block number part of
ctidis a“downlink”, which is a block number of another page in the index itself. The offset part (the second number) ofctidstores encoded information about the tuple, such as the number of columns present (suffix truncation may have removed unneeded suffix columns). Truncated columns are treated as having the value“minus infinity”.htidshows a heap TID for the tuple, regardless of the underlying tuple representation. This value may matchctid, or may be decoded from the alternative representations used by posting list tuples and tuples from internal pages. Tuples in internal pages usually have the implementation level heap TID column truncated away, which is represented as a NULLhtidvalue.Note that the first item on any non-rightmost page (any page with a non-zero value in the
btpo_nextfield) is the page's“high key”, meaning itsdataserves as an upper bound on all items appearing on the page, while itsctidfield does not point to another block. Also, on internal pages, the first real data item (the first item that is not a high key) reliably has every column truncated away, leaving no actual value in itsdatafield. Such an item does have a valid downlink in itsctidfield, however.For more details about the structure of B-tree indexes, seeSection 64.4.1. For more details about deduplication and posting lists, seeSection 64.4.3.
bt_page_items(page bytea) returns setof recordIt is also possible to pass a page to
bt_page_itemsas abyteavalue. A page image obtained withget_raw_pageshould be passed as argument. So the last example could also be rewritten like this:test=# SELECT itemoffset, ctid, itemlen, nulls, vars, data, dead, htid, tids[0:2] AS some_tids FROM bt_page_items(get_raw_page('tenk2_hundred', 5)); itemoffset | ctid | itemlen | nulls | vars | data | dead | htid | some_tids------------+-----------+---------+-------+------+-------------------------+------+--------+--------------------- 1 | (16,1) | 16 | f | f | 30 00 00 00 00 00 00 00 | | | 2 | (16,8292) | 616 | f | f | 24 00 00 00 00 00 00 00 | f | (1,6) | {"(1,6)","(10,22)"} 3 | (16,8292) | 616 | f | f | 25 00 00 00 00 00 00 00 | f | (1,18) | {"(1,18)","(4,22)"} 4 | (16,8292) | 616 | f | f | 26 00 00 00 00 00 00 00 | f | (4,18) | {"(4,18)","(6,17)"} 5 | (16,8292) | 616 | f | f | 27 00 00 00 00 00 00 00 | f | (1,2) | {"(1,2)","(1,19)"} 6 | (16,8292) | 616 | f | f | 28 00 00 00 00 00 00 00 | f | (2,24) | {"(2,24)","(4,11)"} 7 | (16,8292) | 616 | f | f | 29 00 00 00 00 00 00 00 | f | (2,17) | {"(2,17)","(11,2)"} 8 | (16,8292) | 616 | f | f | 2a 00 00 00 00 00 00 00 | f | (0,25) | {"(0,25)","(3,20)"} 9 | (16,8292) | 616 | f | f | 2b 00 00 00 00 00 00 00 | f | (0,10) | {"(0,10)","(0,14)"} 10 | (16,8292) | 616 | f | f | 2c 00 00 00 00 00 00 00 | f | (1,3) | {"(1,3)","(3,9)"} 11 | (16,8292) | 616 | f | f | 2d 00 00 00 00 00 00 00 | f | (6,28) | {"(6,28)","(11,1)"} 12 | (16,8292) | 616 | f | f | 2e 00 00 00 00 00 00 00 | f | (0,27) | {"(0,27)","(1,13)"} 13 | (16,8292) | 616 | f | f | 2f 00 00 00 00 00 00 00 | f | (4,17) | {"(4,17)","(4,21)"}(13 rows)All the other details are the same as explained in the previous item.
F.35.4. BRIN Functions
brin_page_type(page bytea) returns textbrin_page_typereturns the page type of the givenBRIN index page, or throws an error if the page is not a validBRIN page. For example:test=# SELECT brin_page_type(get_raw_page('brinidx', 0)); brin_page_type---------------- metabrin_metapage_info(page bytea) returns recordbrin_metapage_inforeturns assorted information about aBRIN index metapage. For example:test=# SELECT * FROM brin_metapage_info(get_raw_page('brinidx', 0)); magic | version | pagesperrange | lastrevmappage------------+---------+---------------+---------------- 0xA8109CFA | 1 | 4 | 2brin_revmap_data(page bytea) returns setof tidbrin_revmap_datareturns the list of tuple identifiers in aBRIN index range map page. For example:test=# SELECT * FROM brin_revmap_data(get_raw_page('brinidx', 2)) LIMIT 5; pages--------- (6,137) (6,138) (6,139) (6,140) (6,141)brin_page_items(page bytea, index oid) returns setof record
F.35.5. GIN Functions
gin_metapage_info(page bytea) returns recordgin_metapage_inforeturns information about aGIN index metapage. For example:test=# SELECT * FROM gin_metapage_info(get_raw_page('gin_index', 0));-[ RECORD 1 ]----+-----------pending_head | 4294967295pending_tail | 4294967295tail_free_size | 0n_pending_pages | 0n_pending_tuples | 0n_total_pages | 7n_entry_pages | 6n_data_pages | 0n_entries | 693version | 2gin_page_opaque_info(page bytea) returns recordgin_page_opaque_inforeturns information about aGIN 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-----------+--------+------------------------ 5 | 0 | {data,leaf,compressed}(1 row)gin_leafpage_items(page bytea) returns setof record
F.35.6. GiST Functions
gist_page_opaque_info(page bytea) returns recordgist_page_opaque_inforeturns information from aGiST 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-----+-----+-----------+-------- 0/1 | 0/0 | 1 | {leaf}(1 row)gist_page_items(page bytea, index_oid regclass) returns setof recordgist_page_itemsreturns information about the data stored in a page of aGiST index. For example:test=# SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 0), 'test_gist_idx'); itemoffset | ctid | itemlen | dead | keys------------+-----------+---------+------+------------------------------- 1 | (1,65535) | 40 | f | (p)=("(185,185),(1,1)") 2 | (2,65535) | 40 | f | (p)=("(370,370),(186,186)") 3 | (3,65535) | 40 | f | (p)=("(555,555),(371,371)") 4 | (4,65535) | 40 | f | (p)=("(740,740),(556,556)") 5 | (5,65535) | 40 | f | (p)=("(870,870),(741,741)") 6 | (6,65535) | 40 | f | (p)=("(1000,1000),(871,871)")(6 rows)gist_page_items_bytea(page bytea) returns setof recordSame as
gist_page_items, but returns the key data as a rawbyteablob. Since it does not attempt to decode the key, it does not need to know which index is involved. For example:test=# SELECT * FROM gist_page_items_bytea(get_raw_page('test_gist_idx', 0)); itemoffset | ctid | itemlen | dead | key_data------------+-----------+---------+------+------------------------------------------------------------------------------------ 1 | (1,65535) | 40 | f | \x00000100ffff28000000000000c064400000000000c06440000000000000f03f000000000000f03f 2 | (2,65535) | 40 | f | \x00000200ffff28000000000000c074400000000000c074400000000000e064400000000000e06440 3 | (3,65535) | 40 | f | \x00000300ffff28000000000000207f400000000000207f400000000000d074400000000000d07440 4 | (4,65535) | 40 | f | \x00000400ffff28000000000000c084400000000000c084400000000000307f400000000000307f40 5 | (5,65535) | 40 | f | \x00000500ffff28000000000000f089400000000000f089400000000000c884400000000000c88440 6 | (6,65535) | 40 | f | \x00000600ffff28000000000000208f400000000000208f400000000000f889400000000000f88940 7 | (7,65535) | 40 | f | \x00000700ffff28000000000000408f400000000000408f400000000000288f400000000000288f40(7 rows)
F.35.7. Hash Functions
hash_page_type(page bytea) returns texthash_page_typereturns page type of the givenHASH index page. For example:test=# SELECT hash_page_type(get_raw_page('con_hash_index', 0)); hash_page_type---------------- metapagehash_page_stats(page bytea) returns setof recordhash_page_statsreturns information about a bucket or overflow page of aHASH index. For example:test=# SELECT * FROM hash_page_stats(get_raw_page('con_hash_index', 1));-[ RECORD 1 ]---+-----------live_items | 407dead_items | 0page_size | 8192free_size | 8hasho_prevblkno | 4096hasho_nextblkno | 8474hasho_bucket | 0hasho_flag | 66hasho_page_id | 65408hash_page_items(page bytea) returns setof recordhash_page_itemsreturns information about the data stored in a bucket or overflow page of aHASH index page. For example:test=# SELECT * FROM hash_page_items(get_raw_page('con_hash_index', 1)) LIMIT 5; itemoffset | ctid | data------------+-----------+------------ 1 | (899,77) | 1053474816 2 | (897,29) | 1053474816 3 | (894,207) | 1053474816 4 | (892,159) | 1053474816 5 | (890,111) | 1053474816hash_bitmap_info(index oid, blkno bigint) returns recordhash_bitmap_infoshows the status of a bit in the bitmap page for a particular overflow page ofHASH index. For example:test=# SELECT * FROM hash_bitmap_info('con_hash_index', 2052); bitmapblkno | bitmapbit | bitstatus-------------+-----------+----------- 65 | 3 | thash_metapage_info(page bytea) returns record