Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
<!-- doc/src/sgml/amcheck.sgml -->
|
|
|
|
|
|
|
|
<sect1 id="amcheck" xreflabel="amcheck">
|
2023-01-20 20:01:59 +01:00
|
|
|
<title>amcheck — tools to verify table and index consistency</title>
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
|
|
|
|
<indexterm zone="amcheck">
|
|
|
|
<primary>amcheck</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The <filename>amcheck</filename> module provides functions that allow you to
|
2020-10-22 14:44:18 +02:00
|
|
|
verify the logical consistency of the structure of relations.
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2020-10-22 14:44:18 +02:00
|
|
|
The B-Tree checking functions verify various <emphasis>invariants</emphasis> in the
|
2018-04-01 04:52:01 +02:00
|
|
|
structure of the representation of particular relations. The
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
correctness of the access method functions behind index scans and
|
|
|
|
other important operations relies on these invariants always
|
|
|
|
holding. For example, certain functions verify, among other things,
|
2017-10-09 03:44:17 +02:00
|
|
|
that all B-Tree pages have items in <quote>logical</quote> order (e.g.,
|
|
|
|
for B-Tree indexes on <type>text</type>, index tuples should be in
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
collated lexical order). If that particular invariant somehow fails
|
|
|
|
to hold, we can expect binary searches on the affected page to
|
|
|
|
incorrectly guide index scans, resulting in wrong answers to SQL
|
2020-10-22 14:44:18 +02:00
|
|
|
queries. If the structure appears to be valid, no error is raised.
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Verification is performed using the same procedures as those used by
|
|
|
|
index scans themselves, which may be user-defined operator class
|
|
|
|
code. For example, B-Tree index verification relies on comparisons
|
|
|
|
made with one or more B-Tree support function 1 routines. See <xref
|
2017-11-23 15:39:47 +01:00
|
|
|
linkend="xindex-support"/> for details of operator class support
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
functions.
|
|
|
|
</para>
|
|
|
|
<para>
|
2020-10-22 14:44:18 +02:00
|
|
|
Unlike the B-Tree checking functions which report corruption by raising
|
|
|
|
errors, the heap checking function <function>verify_heapam</function> checks
|
|
|
|
a table and attempts to return a set of rows, one row per corruption
|
|
|
|
detected. Despite this, if facilities that
|
|
|
|
<function>verify_heapam</function> relies upon are themselves corrupted, the
|
|
|
|
function may be unable to continue and may instead raise an error.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Permission to execute <filename>amcheck</filename> functions may be granted
|
|
|
|
to non-superusers, but before granting such permissions careful consideration
|
|
|
|
should be given to data security and privacy concerns. Although the
|
|
|
|
corruption reports generated by these functions do not focus on the contents
|
|
|
|
of the corrupted data so much as on the structure of that data and the nature
|
|
|
|
of the corruptions found, an attacker who gains permission to execute these
|
|
|
|
functions, particularly if the attacker can also induce corruption, might be
|
|
|
|
able to infer something of the data itself from such messages.
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
</para>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<sect2 id="amcheck-functions">
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
<title>Functions</title>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>
|
2018-04-01 04:52:01 +02:00
|
|
|
<function>bt_index_check(index regclass, heapallindexed boolean) returns void</function>
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
<indexterm>
|
|
|
|
<primary>bt_index_check</primary>
|
|
|
|
</indexterm>
|
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<function>bt_index_check</function> tests that its target, a
|
|
|
|
B-Tree index, respects a variety of invariants. Example usage:
|
|
|
|
<screen>
|
2018-04-25 17:02:55 +02:00
|
|
|
test=# SELECT bt_index_check(index => c.oid, heapallindexed => i.indisunique),
|
2018-04-01 04:52:01 +02:00
|
|
|
c.relname,
|
|
|
|
c.relpages
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
FROM pg_index i
|
|
|
|
JOIN pg_opclass op ON i.indclass[0] = op.oid
|
|
|
|
JOIN pg_am am ON op.opcmethod = am.oid
|
|
|
|
JOIN pg_class c ON i.indexrelid = c.oid
|
|
|
|
JOIN pg_namespace n ON c.relnamespace = n.oid
|
|
|
|
WHERE am.amname = 'btree' AND n.nspname = 'pg_catalog'
|
|
|
|
-- Don't check temp tables, which may be from another session:
|
|
|
|
AND c.relpersistence != 't'
|
|
|
|
-- Function may throw an error when this is omitted:
|
2018-04-25 17:02:55 +02:00
|
|
|
AND c.relkind = 'i' AND i.indisready AND i.indisvalid
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
ORDER BY c.relpages DESC LIMIT 10;
|
2020-10-28 21:31:40 +01:00
|
|
|
bt_index_check | relname | relpages
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
----------------+---------------------------------+----------
|
|
|
|
| pg_depend_reference_index | 43
|
|
|
|
| pg_depend_depender_index | 40
|
|
|
|
| pg_proc_proname_args_nsp_index | 31
|
|
|
|
| pg_description_o_c_o_index | 21
|
|
|
|
| pg_attribute_relid_attnam_index | 14
|
|
|
|
| pg_proc_oid_index | 10
|
|
|
|
| pg_attribute_relid_attnum_index | 9
|
|
|
|
| pg_amproc_fam_proc_index | 5
|
|
|
|
| pg_amop_opr_fam_index | 5
|
|
|
|
| pg_amop_fam_strat_index | 5
|
|
|
|
(10 rows)
|
|
|
|
</screen>
|
2018-08-08 21:56:11 +02:00
|
|
|
This example shows a session that performs verification of the
|
|
|
|
10 largest catalog indexes in the database <quote>test</quote>.
|
|
|
|
Verification of the presence of heap tuples as index tuples is
|
|
|
|
requested for the subset that are unique indexes. Since no
|
|
|
|
error is raised, all indexes tested appear to be logically
|
|
|
|
consistent. Naturally, this query could easily be changed to
|
|
|
|
call <function>bt_index_check</function> for every index in the
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
database where verification is supported.
|
|
|
|
</para>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<function>bt_index_check</function> acquires an <literal>AccessShareLock</literal>
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
on the target index and the heap relation it belongs to. This lock mode
|
|
|
|
is the same lock mode acquired on relations by simple
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>SELECT</literal> statements.
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
<function>bt_index_check</function> does not verify invariants
|
2018-04-01 04:52:01 +02:00
|
|
|
that span child/parent relationships, but will verify the
|
|
|
|
presence of all heap tuples as index tuples within the index
|
|
|
|
when <parameter>heapallindexed</parameter> is
|
|
|
|
<literal>true</literal>. When a routine, lightweight test for
|
|
|
|
corruption is required in a live production environment, using
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
<function>bt_index_check</function> often provides the best
|
|
|
|
trade-off between thoroughness of verification and limiting the
|
|
|
|
impact on application performance and availability.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>
|
2019-03-20 18:41:36 +01:00
|
|
|
<function>bt_index_parent_check(index regclass, heapallindexed boolean, rootdescend boolean) returns void</function>
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
<indexterm>
|
|
|
|
<primary>bt_index_parent_check</primary>
|
|
|
|
</indexterm>
|
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<function>bt_index_parent_check</function> tests that its
|
2018-04-01 04:52:01 +02:00
|
|
|
target, a B-Tree index, respects a variety of invariants.
|
|
|
|
Optionally, when the <parameter>heapallindexed</parameter>
|
|
|
|
argument is <literal>true</literal>, the function verifies the
|
|
|
|
presence of all heap tuples that should be found within the
|
2020-03-11 10:00:31 +01:00
|
|
|
index. When the optional <parameter>rootdescend</parameter>
|
2019-03-20 18:41:36 +01:00
|
|
|
argument is <literal>true</literal>, verification re-finds
|
|
|
|
tuples on the leaf level by performing a new search from the
|
|
|
|
root page for each tuple. The checks that can be performed by
|
2018-04-01 04:52:01 +02:00
|
|
|
<function>bt_index_parent_check</function> are a superset of the
|
|
|
|
checks that can be performed by <function>bt_index_check</function>.
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
<function>bt_index_parent_check</function> can be thought of as
|
|
|
|
a more thorough variant of <function>bt_index_check</function>:
|
|
|
|
unlike <function>bt_index_check</function>,
|
|
|
|
<function>bt_index_parent_check</function> also checks
|
2020-03-11 10:00:31 +01:00
|
|
|
invariants that span parent/child relationships, including checking
|
|
|
|
that there are no missing downlinks in the index structure.
|
2018-04-01 04:52:01 +02:00
|
|
|
<function>bt_index_parent_check</function> follows the general
|
|
|
|
convention of raising an error if it finds a logical
|
|
|
|
inconsistency or other problem.
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
A <literal>ShareLock</literal> is required on the target index by
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
<function>bt_index_parent_check</function> (a
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>ShareLock</literal> is also acquired on the heap relation).
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
These locks prevent concurrent data modification from
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>INSERT</command>, <command>UPDATE</command>, and <command>DELETE</command>
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
commands. The locks also prevent the underlying relation from
|
2017-10-09 03:44:17 +02:00
|
|
|
being concurrently processed by <command>VACUUM</command>, as well as
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
all other utility commands. Note that the function holds locks
|
|
|
|
only while running, not for the entire transaction.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<function>bt_index_parent_check</function>'s additional
|
|
|
|
verification is more likely to detect various pathological
|
|
|
|
cases. These cases may involve an incorrectly implemented
|
|
|
|
B-Tree operator class used by the index that is checked, or,
|
|
|
|
hypothetically, undiscovered bugs in the underlying B-Tree index
|
|
|
|
access method code. Note that
|
|
|
|
<function>bt_index_parent_check</function> cannot be used when
|
2022-03-11 07:16:21 +01:00
|
|
|
hot standby mode is enabled (i.e., on read-only physical
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
replicas), unlike <function>bt_index_check</function>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2020-04-11 02:44:08 +02:00
|
|
|
<tip>
|
|
|
|
<para>
|
2020-04-12 06:07:20 +02:00
|
|
|
<function>bt_index_check</function> and
|
2020-04-11 02:44:08 +02:00
|
|
|
<function>bt_index_parent_check</function> both output log
|
|
|
|
messages about the verification process at
|
|
|
|
<literal>DEBUG1</literal> and <literal>DEBUG2</literal> severity
|
|
|
|
levels. These messages provide detailed information about the
|
|
|
|
verification process that may be of interest to
|
|
|
|
<productname>PostgreSQL</productname> developers. Advanced users
|
|
|
|
may also find this information helpful, since it provides
|
|
|
|
additional context should verification actually detect an
|
|
|
|
inconsistency. Running:
|
|
|
|
<programlisting>
|
|
|
|
SET client_min_messages = DEBUG1;
|
|
|
|
</programlisting>
|
|
|
|
in an interactive <application>psql</application> session before
|
|
|
|
running a verification query will display messages about the
|
|
|
|
progress of verification with a manageable level of detail.
|
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
|
2020-10-22 14:44:18 +02:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>
|
|
|
|
<function>
|
|
|
|
verify_heapam(relation regclass,
|
|
|
|
on_error_stop boolean,
|
|
|
|
check_toast boolean,
|
2020-10-28 21:31:40 +01:00
|
|
|
skip text,
|
2020-10-22 14:44:18 +02:00
|
|
|
startblock bigint,
|
|
|
|
endblock bigint,
|
|
|
|
blkno OUT bigint,
|
|
|
|
offnum OUT integer,
|
|
|
|
attnum OUT integer,
|
|
|
|
msg OUT text)
|
2020-10-28 21:31:40 +01:00
|
|
|
returns setof record
|
2020-10-22 14:44:18 +02:00
|
|
|
</function>
|
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2021-09-28 15:26:25 +02:00
|
|
|
Checks a table, sequence, or materialized view for structural corruption,
|
|
|
|
where pages in the relation contain data that is invalidly formatted, and
|
|
|
|
for logical corruption, where pages are structurally valid but
|
|
|
|
inconsistent with the rest of the database cluster.
|
2020-10-22 14:44:18 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
The following optional arguments are recognized:
|
|
|
|
</para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2020-10-28 21:31:40 +01:00
|
|
|
<term><literal>on_error_stop</literal></term>
|
2020-10-22 14:44:18 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-10-28 21:31:40 +01:00
|
|
|
If true, corruption checking stops at the end of the first block in
|
2020-10-22 14:44:18 +02:00
|
|
|
which any corruptions are found.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Defaults to false.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2020-10-28 21:31:40 +01:00
|
|
|
<term><literal>check_toast</literal></term>
|
2020-10-22 14:44:18 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-10-28 21:31:40 +01:00
|
|
|
If true, toasted values are checked against the target relation's
|
2020-10-22 14:44:18 +02:00
|
|
|
TOAST table.
|
|
|
|
</para>
|
2020-10-28 21:31:40 +01:00
|
|
|
<para>
|
|
|
|
This option is known to be slow. Also, if the toast table or its
|
|
|
|
index is corrupt, checking it against toast values could conceivably
|
|
|
|
crash the server, although in many cases this would just produce an
|
|
|
|
error.
|
|
|
|
</para>
|
2020-10-22 14:44:18 +02:00
|
|
|
<para>
|
|
|
|
Defaults to false.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2020-10-28 21:31:40 +01:00
|
|
|
<term><literal>skip</literal></term>
|
2020-10-22 14:44:18 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If not <literal>none</literal>, corruption checking skips blocks that
|
2020-10-28 21:31:40 +01:00
|
|
|
are marked as all-visible or all-frozen, as specified.
|
2020-10-22 14:44:18 +02:00
|
|
|
Valid options are <literal>all-visible</literal>,
|
|
|
|
<literal>all-frozen</literal> and <literal>none</literal>.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Defaults to <literal>none</literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2020-10-28 21:31:40 +01:00
|
|
|
<term><literal>startblock</literal></term>
|
2020-10-22 14:44:18 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If specified, corruption checking begins at the specified block,
|
|
|
|
skipping all previous blocks. It is an error to specify a
|
2021-07-15 23:22:58 +02:00
|
|
|
<parameter>startblock</parameter> outside the range of blocks in the
|
2020-10-22 14:44:18 +02:00
|
|
|
target table.
|
|
|
|
</para>
|
|
|
|
<para>
|
2020-10-28 21:31:40 +01:00
|
|
|
By default, checking begins at the first block.
|
2020-10-22 14:44:18 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2020-10-28 21:31:40 +01:00
|
|
|
<term><literal>endblock</literal></term>
|
2020-10-22 14:44:18 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If specified, corruption checking ends at the specified block,
|
|
|
|
skipping all remaining blocks. It is an error to specify an
|
2021-07-15 23:22:58 +02:00
|
|
|
<parameter>endblock</parameter> outside the range of blocks in the target
|
2020-10-22 14:44:18 +02:00
|
|
|
table.
|
|
|
|
</para>
|
|
|
|
<para>
|
2020-10-28 21:31:40 +01:00
|
|
|
By default, all blocks are checked.
|
2020-10-22 14:44:18 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
<para>
|
|
|
|
For each corruption detected, <function>verify_heapam</function> returns
|
|
|
|
a row with the following columns:
|
|
|
|
</para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2020-10-28 21:31:40 +01:00
|
|
|
<term><literal>blkno</literal></term>
|
2020-10-22 14:44:18 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The number of the block containing the corrupt page.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2020-10-28 21:31:40 +01:00
|
|
|
<term><literal>offnum</literal></term>
|
2020-10-22 14:44:18 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The OffsetNumber of the corrupt tuple.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2020-10-28 21:31:40 +01:00
|
|
|
<term><literal>attnum</literal></term>
|
2020-10-22 14:44:18 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The attribute number of the corrupt column in the tuple, if the
|
|
|
|
corruption is specific to a column and not the tuple as a whole.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2020-10-28 21:31:40 +01:00
|
|
|
<term><literal>msg</literal></term>
|
2020-10-22 14:44:18 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-10-28 21:31:40 +01:00
|
|
|
A message describing the problem detected.
|
2020-10-22 14:44:18 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
</sect2>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<sect2 id="amcheck-optional-heapallindexed-verification">
|
2019-09-08 10:26:35 +02:00
|
|
|
<title>Optional <parameter>heapallindexed</parameter> Verification</title>
|
2018-04-01 04:52:01 +02:00
|
|
|
<para>
|
2020-10-22 14:44:18 +02:00
|
|
|
When the <parameter>heapallindexed</parameter> argument to B-Tree
|
2018-04-01 04:52:01 +02:00
|
|
|
verification functions is <literal>true</literal>, an additional
|
|
|
|
phase of verification is performed against the table associated with
|
|
|
|
the target index relation. This consists of a <quote>dummy</quote>
|
|
|
|
<command>CREATE INDEX</command> operation, which checks for the
|
|
|
|
presence of all hypothetical new index tuples against a temporary,
|
|
|
|
in-memory summarizing structure (this is built when needed during
|
|
|
|
the basic first phase of verification). The summarizing structure
|
|
|
|
<quote>fingerprints</quote> every tuple found within the target
|
|
|
|
index. The high level principle behind
|
|
|
|
<parameter>heapallindexed</parameter> verification is that a new
|
|
|
|
index that is equivalent to the existing, target index must only
|
|
|
|
have entries that can be found in the existing structure.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
The additional <parameter>heapallindexed</parameter> phase adds
|
|
|
|
significant overhead: verification will typically take several times
|
|
|
|
longer. However, there is no change to the relation-level locks
|
|
|
|
acquired when <parameter>heapallindexed</parameter> verification is
|
|
|
|
performed.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
The summarizing structure is bound in size by
|
|
|
|
<varname>maintenance_work_mem</varname>. In order to ensure that
|
|
|
|
there is no more than a 2% probability of failure to detect an
|
|
|
|
inconsistency for each heap tuple that should be represented in the
|
|
|
|
index, approximately 2 bytes of memory are needed per tuple. As
|
|
|
|
less memory is made available per tuple, the probability of missing
|
|
|
|
an inconsistency slowly increases. This approach limits the
|
|
|
|
overhead of verification significantly, while only slightly reducing
|
|
|
|
the probability of detecting a problem, especially for installations
|
|
|
|
where verification is treated as a routine maintenance task. Any
|
|
|
|
single absent or malformed tuple has a new opportunity to be
|
|
|
|
detected with each new verification attempt.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</sect2>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<sect2 id="amcheck-using-amcheck-effectively">
|
2019-09-08 10:26:35 +02:00
|
|
|
<title>Using <filename>amcheck</filename> Effectively</title>
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>amcheck</filename> can be effective at detecting various types of
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
failure modes that <link
|
2021-01-17 15:31:23 +01:00
|
|
|
linkend="app-initdb-data-checksums"><application>data
|
2020-10-28 21:31:40 +01:00
|
|
|
checksums</application></link> will fail to catch. These include:
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Structural inconsistencies caused by incorrect operator class
|
|
|
|
implementations.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
This includes issues caused by the comparison rules of operating
|
|
|
|
system collations changing. Comparisons of datums of a collatable
|
2017-10-09 03:44:17 +02:00
|
|
|
type like <type>text</type> must be immutable (just as all
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
comparisons used for B-Tree index scans must be immutable), which
|
|
|
|
implies that operating system collation rules must never change.
|
|
|
|
Though rare, updates to operating system collation rules can
|
|
|
|
cause these issues. More commonly, an inconsistency in the
|
2020-06-15 19:12:58 +02:00
|
|
|
collation order between a primary server and a standby server is
|
2017-10-09 03:44:17 +02:00
|
|
|
implicated, possibly because the <emphasis>major</emphasis> operating
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
system version in use is inconsistent. Such inconsistencies will
|
|
|
|
generally only arise on standby servers, and so can generally
|
|
|
|
only be detected on standby servers.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If a problem like this arises, it may not affect each individual
|
|
|
|
index that is ordered using an affected collation, simply because
|
2017-10-09 03:44:17 +02:00
|
|
|
<emphasis>indexed</emphasis> values might happen to have the same
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
absolute ordering regardless of the behavioral inconsistency. See
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="locale"/> and <xref linkend="collation"/> for
|
2017-10-09 03:44:17 +02:00
|
|
|
further details about how <productname>PostgreSQL</productname> uses
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
operating system locales and collations.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2018-04-01 04:52:01 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Structural inconsistencies between indexes and the heap relations
|
|
|
|
that are indexed (when <parameter>heapallindexed</parameter>
|
|
|
|
verification is performed).
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
There is no cross-checking of indexes against their heap relation
|
|
|
|
during normal operation. Symptoms of heap corruption can be subtle.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Corruption caused by hypothetical undiscovered bugs in the
|
2018-04-01 04:52:01 +02:00
|
|
|
underlying <productname>PostgreSQL</productname> access method
|
|
|
|
code, sort code, or transaction management code.
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Automatic verification of the structural integrity of indexes
|
|
|
|
plays a role in the general testing of new or proposed
|
2017-10-09 03:44:17 +02:00
|
|
|
<productname>PostgreSQL</productname> features that could plausibly allow a
|
2018-04-01 04:52:01 +02:00
|
|
|
logical inconsistency to be introduced. Verification of table
|
|
|
|
structure and associated visibility and transaction status
|
|
|
|
information plays a similar role. One obvious testing strategy
|
|
|
|
is to call <filename>amcheck</filename> functions continuously
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
when running the standard regression tests. See <xref
|
2017-11-23 15:39:47 +01:00
|
|
|
linkend="regress-run"/> for details on running the tests.
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-06-18 20:01:45 +02:00
|
|
|
File system or storage subsystem faults where checksums happen to
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
simply not be enabled.
|
|
|
|
</para>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Note that <filename>amcheck</filename> examines a page as represented in some
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
shared memory buffer at the time of verification if there is only a
|
|
|
|
shared buffer hit when accessing the block. Consequently,
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>amcheck</filename> does not necessarily examine data read from the
|
2017-06-18 20:01:45 +02:00
|
|
|
file system at the time of verification. Note that when checksums are
|
2017-10-09 03:44:17 +02:00
|
|
|
enabled, <filename>amcheck</filename> may raise an error due to a checksum
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
failure when a corrupt block is read into a buffer.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2018-08-08 21:56:11 +02:00
|
|
|
Corruption caused by faulty RAM, or the broader memory subsystem.
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<productname>PostgreSQL</productname> does not protect against correctable
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
memory errors and it is assumed you will operate using RAM that
|
|
|
|
uses industry standard Error Correcting Codes (ECC) or better
|
|
|
|
protection. However, ECC memory is typically only immune to
|
|
|
|
single-bit errors, and should not be assumed to provide
|
|
|
|
<emphasis>absolute</emphasis> protection against failures that
|
|
|
|
result in memory corruption.
|
|
|
|
</para>
|
2018-04-01 04:52:01 +02:00
|
|
|
<para>
|
|
|
|
When <parameter>heapallindexed</parameter> verification is
|
|
|
|
performed, there is generally a greatly increased chance of
|
|
|
|
detecting single-bit errors, since strict binary equality is
|
|
|
|
tested, and the indexed attributes within the heap are tested.
|
|
|
|
</para>
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
2020-10-28 21:31:40 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Structural corruption can happen due to faulty storage hardware, or
|
|
|
|
relation files being overwritten or modified by unrelated software.
|
|
|
|
This kind of corruption can also be detected with
|
2021-01-17 15:31:23 +01:00
|
|
|
<link linkend="checksums"><application>data page
|
2020-10-28 21:31:40 +01:00
|
|
|
checksums</application></link>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Relation pages which are correctly formatted, internally consistent, and
|
|
|
|
correct relative to their own internal checksums may still contain
|
|
|
|
logical corruption. As such, this kind of corruption cannot be detected
|
|
|
|
with <application>checksums</application>. Examples include toasted
|
|
|
|
values in the main table which lack a corresponding entry in the toast
|
|
|
|
table, and tuples in the main table with a Transaction ID that is older
|
|
|
|
than the oldest valid Transaction ID in the database or cluster.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Multiple causes of logical corruption have been observed in production
|
|
|
|
systems, including bugs in the <productname>PostgreSQL</productname>
|
|
|
|
server software, faulty and ill-conceived backup and restore tools, and
|
|
|
|
user error.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Corrupt relations are most concerning in live production environments,
|
|
|
|
precisely the same environments where high risk activities are least
|
|
|
|
welcome. For this reason, <function>verify_heapam</function> has been
|
|
|
|
designed to diagnose corruption without undue risk. It cannot guard
|
|
|
|
against all causes of backend crashes, as even executing the calling
|
|
|
|
query could be unsafe on a badly corrupted system. Access to <link
|
2020-12-24 09:05:49 +01:00
|
|
|
linkend="catalogs-overview">catalog tables</link> is performed and could
|
2020-10-28 21:31:40 +01:00
|
|
|
be problematic if the catalogs themselves are corrupted.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
In general, <filename>amcheck</filename> can only prove the presence of
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
corruption; it cannot prove its absence.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</sect2>
|
2023-01-09 21:08:24 +01:00
|
|
|
<sect2 id="amcheck-repairing-corruption">
|
2019-09-08 10:26:35 +02:00
|
|
|
<title>Repairing Corruption</title>
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
No error concerning corruption raised by <filename>amcheck</filename> should
|
2018-04-01 04:52:01 +02:00
|
|
|
ever be a false positive. <filename>amcheck</filename> raises
|
|
|
|
errors in the event of conditions that, by definition, should never
|
|
|
|
happen, and so careful analysis of <filename>amcheck</filename>
|
|
|
|
errors is often required.
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
There is no general method of repairing problems that
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>amcheck</filename> detects. An explanation for the root cause of
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
an invariant violation should be sought. <xref
|
2017-11-23 15:39:47 +01:00
|
|
|
linkend="pageinspect"/> may play a useful role in diagnosing
|
2017-10-09 03:44:17 +02:00
|
|
|
corruption that <filename>amcheck</filename> detects. A <command>REINDEX</command>
|
Add amcheck extension to contrib.
This is the beginning of a collection of SQL-callable functions to
verify the integrity of data files. For now it only contains code to
verify B-Tree indexes.
This adds two SQL-callable functions, validating B-Tree consistency to
a varying degree. Check the, extensive, docs for details.
The goal is to later extend the coverage of the module to further
access methods, possibly including the heap. Once checks for
additional access methods exist, we'll likely add some "dispatch"
functions that cover multiple access methods.
Author: Peter Geoghegan, editorialized by Andres Freund
Reviewed-By: Andres Freund, Tomas Vondra, Thomas Munro,
Anastasia Lubennikova, Robert Haas, Amit Langote
Discussion: CAM3SWZQzLMhMwmBqjzK+pRKXrNUZ4w90wYMUWfkeV8mZ3Debvw@mail.gmail.com
2017-03-10 00:50:40 +01:00
|
|
|
may not be effective in repairing corruption.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
</sect1>
|