Commit e472ce96 authored by Robert Haas's avatar Robert Haas

Add integrity-checking functions to pg_visibility.

The new pg_check_visible() and pg_check_frozen() functions can be used to
verify that the visibility map bits for a relation's data pages match the
actual state of the tuples on those pages.

Amit Kapila and Robert Haas, reviewed (in earlier versions) by Andres
Freund.  Additional testing help by Thomas Munro.
parent 38e9f90a
......@@ -4,7 +4,7 @@ MODULE_big = pg_visibility
OBJS = pg_visibility.o $(WIN32RES)
EXTENSION = pg_visibility
DATA = pg_visibility--1.0.sql
DATA = pg_visibility--1.1.sql pg_visibility--1.0--1.1.sql
PGFILEDESC = "pg_visibility - page visibility information"
ifdef USE_PGXS
......
/* contrib/pg_visibility/pg_visibility--1.0--1.1.sql */
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pg_visibility UPDATE TO '1.1'" to load this file. \quit
CREATE FUNCTION pg_check_frozen(regclass, t_ctid OUT tid)
RETURNS SETOF tid
AS 'MODULE_PATHNAME', 'pg_check_frozen'
LANGUAGE C STRICT;
CREATE FUNCTION pg_check_visible(regclass, t_ctid OUT tid)
RETURNS SETOF tid
AS 'MODULE_PATHNAME', 'pg_check_visible'
LANGUAGE C STRICT;
REVOKE ALL ON FUNCTION pg_check_frozen(regclass) FROM PUBLIC;
REVOKE ALL ON FUNCTION pg_check_visible(regclass) FROM PUBLIC;
/* contrib/pg_visibility/pg_visibility--1.0.sql */
/* contrib/pg_visibility/pg_visibility--1.1.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pg_visibility" to load this file. \quit
......@@ -44,9 +44,24 @@ RETURNS record
AS 'MODULE_PATHNAME', 'pg_visibility_map_summary'
LANGUAGE C STRICT;
-- Show tupleids of non-frozen tuples if any in all_frozen pages
-- for a relation.
CREATE FUNCTION pg_check_frozen(regclass, t_ctid OUT tid)
RETURNS SETOF tid
AS 'MODULE_PATHNAME', 'pg_check_frozen'
LANGUAGE C STRICT;
-- Show tupleids of dead tuples if any in all_visible pages for a relation.
CREATE FUNCTION pg_check_visible(regclass, t_ctid OUT tid)
RETURNS SETOF tid
AS 'MODULE_PATHNAME', 'pg_check_visible'
LANGUAGE C STRICT;
-- Don't want these to be available to public.
REVOKE ALL ON FUNCTION pg_visibility_map(regclass, bigint) FROM PUBLIC;
REVOKE ALL ON FUNCTION pg_visibility(regclass, bigint) FROM PUBLIC;
REVOKE ALL ON FUNCTION pg_visibility_map(regclass) FROM PUBLIC;
REVOKE ALL ON FUNCTION pg_visibility(regclass) FROM PUBLIC;
REVOKE ALL ON FUNCTION pg_visibility_map_summary(regclass) FROM PUBLIC;
REVOKE ALL ON FUNCTION pg_check_frozen(regclass) FROM PUBLIC;
REVOKE ALL ON FUNCTION pg_check_visible(regclass) FROM PUBLIC;
This diff is collapsed.
# pg_visibility extension
comment = 'examine the visibility map (VM) and page-level visibility info'
default_version = '1.0'
default_version = '1.1'
module_pathname = '$libdir/pg_visibility'
relocatable = true
......@@ -32,7 +32,8 @@
Functions which display information about <literal>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.
(much smaller) visibility map. Functions that check the relation's
data blocks are similarly expensive.
</para>
<sect2>
......@@ -92,6 +93,31 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><function>pg_check_frozen(regclass, t_ctid OUT tid) returns setof tid</function></term>
<listitem>
<para>
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.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><function>pg_check_visible(regclass, t_ctid OUT tid) returns setof tid</function></term>
<listitem>
<para>
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.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
......
......@@ -2372,6 +2372,7 @@ convert_testexpr_context
core_YYSTYPE
core_yy_extra_type
core_yyscan_t
corrupt_items
cost_qual_eval_context
count_agg_clauses_context
create_upper_paths_hook_type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment