Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
F.22. pageinspect
Prev UpAppendix F. Additional Supplied ModulesHome Next

F.22. 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.22.1. General Functions

get_raw_page(relname text, fork text, blkno int) returns bytea

get_raw_page reads the specified block of the named relation and returns a copy as abytea 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 int) returns bytea

A shorthand version ofget_raw_page, for reading from the main fork. Equivalent toget_raw_page(relname, 'main', blkno)

page_header(page bytea) returns record

page_header shows fields that are common to allPostgreSQL heap and index pages.

A page image obtained withget_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 thePageHeaderData struct. Seesrc/include/storage/bufpage.h for details.

Thechecksum 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 int4) returns smallint

page_checksum computes the checksum for the page, as if it was located at the given block.

A page image obtained withget_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 thechecksum result 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 text

fsm_page_contents shows the internal node structure of a 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.

Seesrc/backend/storage/freespace/README for more information on the structure of an FSM page.

F.22.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 withget_raw_page should be passed as argument. For example:

test=# SELECT * FROM heap_page_items(get_raw_page('pg_class', 0));

Seesrc/include/storage/itemid.h andsrc/include/access/htup_details.h for explanations of the fields returned.

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 ofheap_page_items.

Ifdo_detoast istrue, attributes will be detoasted as needed. Default value isfalse.

heap_page_item_attrs(page bytea, rel_oid regclass [, do_detoast bool]) returns setof record

heap_page_item_attrs is equivalent toheap_page_items except that it returns tuple raw data as an array of attributes that can optionally be detoasted bydo_detoast which isfalse by default.

A heap page image obtained withget_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);

F.22.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                   | 340322version                 | 3root                    | 1level                   | 0fastroot                | 1fastlevel               | 0oldest_xact             | 582last_cleanup_num_tuples | 1000

bt_page_stats(relname text, blkno int) 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         | 1type          | llive_items    | 256dead_items    | 0avg_item_size | 12page_size     | 8192free_size     | 4056btpo_prev     | 0btpo_next     | 0btpo          | 0btpo_flags    | 3

bt_page_items(relname text, blkno int) returns setof record

bt_page_items returns detailed information about all of the items on a B-tree index page. For example:

test=# SELECT * FROM bt_page_items('pg_cast_oid_index', 1); itemoffset |  ctid   | itemlen | nulls | vars |    data------------+---------+---------+-------+------+-------------          1 | (0,1)   |      12 | f     | f    | 23 27 00 00          2 | (0,2)   |      12 | f     | f    | 24 27 00 00          3 | (0,3)   |      12 | f     | f    | 25 27 00 00          4 | (0,4)   |      12 | f     | f    | 26 27 00 00          5 | (0,5)   |      12 | f     | f    | 27 27 00 00          6 | (0,6)   |      12 | f     | f    | 28 27 00 00          7 | (0,7)   |      12 | f     | f    | 29 27 00 00          8 | (0,8)   |      12 | f     | f    | 2a 27 00 00

In a B-tree leaf page,ctid points to a heap tuple. In an internal page, the block number part ofctid points to another page in the index itself, while the offset part (the second number) is ignored and is usually 1.

Note that the first item on any non-rightmost page (any page with a non-zero value in thebtpo_next field) is the page'shigh key, meaning itsdata serves as an upper bound on all items appearing on the page, while itsctid field is meaningless. Also, on non-leaf pages, the first real data item (the first item that is not a high key) is aminus infinity item, with no actual value in itsdata field. Such an item does have a valid downlink in itsctid field, however.

bt_page_items(page bytea) returns setof record

It is also possible to pass a page tobt_page_items as abytea value. A page image obtained withget_raw_page should be passed as argument. So the last example could also be rewritten like this:

test=# SELECT * FROM bt_page_items(get_raw_page('pg_cast_oid_index', 1)); itemoffset |  ctid   | itemlen | nulls | vars |    data------------+---------+---------+-------+------+-------------          1 | (0,1)   |      12 | f     | f    | 23 27 00 00          2 | (0,2)   |      12 | f     | f    | 24 27 00 00          3 | (0,3)   |      12 | f     | f    | 25 27 00 00          4 | (0,4)   |      12 | f     | f    | 26 27 00 00          5 | (0,5)   |      12 | f     | f    | 27 27 00 00          6 | (0,6)   |      12 | f     | f    | 28 27 00 00          7 | (0,7)   |      12 | f     | f    | 29 27 00 00          8 | (0,8)   |      12 | f     | f    | 2a 27 00 00

All the other details are the same as explained in the previous item.

F.22.4. BRIN Functions

brin_page_type(page bytea) returns text

brin_page_type returns 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 ---------------- meta

brin_metapage_info(page bytea) returns record

brin_metapage_info returns 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 |              2

brin_revmap_data(page bytea) returns setof tid

brin_revmap_data returns 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

brin_page_items returns the data stored in theBRIN data page. For example:

test=# SELECT * FROM brin_page_items(get_raw_page('brinidx', 5),                                     'brinidx')       ORDER BY blknum, attnum LIMIT 6; itemoffset | blknum | attnum | allnulls | hasnulls | placeholder |    value     ------------+--------+--------+----------+----------+-------------+--------------        137 |      0 |      1 | t        | f        | f           |         137 |      0 |      2 | f        | f        | f           | {1 .. 88}        138 |      4 |      1 | t        | f        | f           |         138 |      4 |      2 | f        | f        | f           | {89 .. 176}        139 |      8 |      1 | t        | f        | f           |         139 |      8 |      2 | f        | f        | f           | {177 .. 264}

The returned columns correspond to the fields in theBrinMemTuple andBrinValues structs. Seesrc/include/access/brin_tuple.h for details.

gin_metapage_info(page bytea) returns record

gin_metapage_info returns 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          | 2

gin_page_opaque_info(page bytea) returns record

gin_page_opaque_info returns 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

gin_leafpage_items returns information about the data stored in aGIN leaf page. For example:

test=# SELECT first_tid, nbytes, tids[0:5] AS some_tids        FROM gin_leafpage_items(get_raw_page('gin_test_idx', 2)); first_tid | nbytes |                        some_tids-----------+--------+---------------------------------------------------------- (8,41)    |    244 | {"(8,41)","(8,43)","(8,44)","(8,45)","(8,46)"} (10,45)   |    248 | {"(10,45)","(10,46)","(10,47)","(10,48)","(10,49)"} (12,52)   |    248 | {"(12,52)","(12,53)","(12,54)","(12,55)","(12,56)"} (14,59)   |    320 | {"(14,59)","(14,60)","(14,61)","(14,62)","(14,63)"} (167,16)  |    376 | {"(167,16)","(167,17)","(167,18)","(167,19)","(167,20)"} (170,30)  |    376 | {"(170,30)","(170,31)","(170,32)","(170,33)","(170,34)"} (173,44)  |    197 | {"(173,44)","(173,45)","(173,46)","(173,47)","(173,48)"}(7 rows)

hash_page_type(page bytea) returns text

hash_page_type returns page type of the givenHASH index page. For example:

test=# SELECT hash_page_type(get_raw_page('con_hash_index', 0)); hash_page_type ---------------- metapage

hash_page_stats(page bytea) returns setof record

hash_page_stats returns 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   | 65408

hash_page_items(page bytea) returns setof record

hash_page_items returns 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) | 1053474816

hash_bitmap_info(index oid, blkno int) returns record

hash_bitmap_info shows 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 | t

hash_metapage_info(page bytea) returns record

hash_metapage_info returns information stored in meta page of aHASH index. For example:

test=# SELECT magic, version, ntuples, ffactor, bsize, bmsize, bmshift,test-#     maxbucket, highmask, lowmask, ovflpoint, firstfree, nmaps, procid,test-#     regexp_replace(spares::text, '(,0)*}', '}') as spares,test-#     regexp_replace(mapp::text, '(,0)*}', '}') as mapptest-# FROM hash_metapage_info(get_raw_page('con_hash_index', 0));-[ RECORD 1 ]-------------------------------------------------------------------------------magic     | 105121344version   | 4ntuples   | 500500ffactor   | 40bsize     | 8152bmsize    | 4096bmshift   | 15maxbucket | 12512highmask  | 16383lowmask   | 8191ovflpoint | 28firstfree | 1204nmaps     | 1procid    | 450spares    | {0,0,0,0,0,0,1,1,1,1,1,1,1,1,3,4,4,4,45,55,58,59,508,567,628,704,1193,1202,1204}mapp      | {65}


Prev Up Next
F.21. ltree Home F.23. passwordcheck
epubpdf
Go to PostgreSQL 11
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp