pg_visibility

The pg_visibility module provides a means for examining the visibility map (VM) and page-level visibility information. It also provides functions to check the integrity of the visibility map and to force it to be rebuilt.

Three different bits are used to store information about page-level visibility. The all-visible bit in the visibility map indicates that every tuple on a given page of a relation is visible to every current transaction. The all-frozen bit in the visibility map indicates that every tuple on the page is frozen; that is, no future vacuum will need to modify the page until such time as a tuple is inserted, updated, deleted, or locked on that page. The page-level PD_ALL_VISIBLE bit has the same meaning as the all-visible bit in the visibility map, but is stored within the data page itself rather than a separate data structure. These will normally agree, but the page-level bit can sometimes be set while the visibility map bit is clear after a crash recovery; or they can disagree because of a change which occurs after pg_visibility examines the visibility map and before it examines the data page. Any event which causes data corruption can also cause these bits to disagree.

Functions which display information about PD_ALL_VISIBLE are much more costly than those which only consult the visibility map, because they must read the relation's data blocks rather than only the (much smaller) visibility map. Functions that check the relation's data blocks are similarly expensive.

F.32.1. Functions

pg_visibility_map(regclass, blkno bigint, all_visible OUT boolean, all_frozen OUT boolean) returns record

Returns the all-visible and all-frozen bits in the visibility map for the given block of the given relation.

pg_visibility(regclass, blkno bigint, all_visible OUT boolean, all_frozen OUT boolean, pd_all_visible OUT boolean) returns record

Returns the all-visible and all-frozen bits in the visibility map for the given block of the given relation, plus the PD_ALL_VISIBLE bit for that block.

pg_visibility_map(regclass, blkno OUT bigint, all_visible OUT boolean, all_frozen OUT boolean) returns setof record

Returns the all-visible and all-frozen bits in the visibility map for each block the given relation.

pg_visibility(regclass, blkno OUT bigint, all_visible OUT boolean, all_frozen OUT boolean, pd_all_visible OUT boolean) returns setof record

Returns the all-visible and all-frozen bits in the visibility map for each block the given relation, plus the PD_ALL_VISIBLE bit for each block.

pg_visibility_map_summary(regclass, all_visible OUT bigint, all_frozen OUT bigint) returns record

Returns the number of all-visible pages and the number of all-frozen pages in the relation according to the visibility map.

pg_check_frozen(regclass, t_ctid OUT tid) returns setof tid

Returns the TIDs of non-frozen tuples present in pages marked all-frozen in the visibility map. If this function returns a non-empty set of TIDs, the database is corrupt.

pg_check_visible(regclass, t_ctid OUT tid) returns setof tid

Returns the TIDs of tuples which are not all-visible despite the fact that the pages which contain them are marked as all-visible in the visibility map. If this function returns a non-empty set of TIDs, the database is corrupt.

pg_truncate_visibility_map(regclass) returns void

Truncates the visibility map for the given relation. This function is only expected to be useful if you suspect that the visibility map for the indicated relation is corrupt and wish to rebuild it. The first VACUUM executed on the given relation after this function is executed will scan every page in the relation and rebuild the visibility map.

By default, these functions are not publicly executable.

F.32.2. Author

Robert Haas

doc_PostgreSQL
2016-10-12 11:33:55
Comments
Leave a Comment

Please login to continue.