Add pg_relation_check_pages() to check on-disk pages of a relation
authorMichael Paquier <michael@paquier.xyz>
Wed, 28 Oct 2020 03:15:00 +0000 (12:15 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 28 Oct 2020 03:15:00 +0000 (12:15 +0900)
commitf2b883969557f4572cdfa87e1a40083d2b1272e7
tree4269340b2912f8dae50c29580a2ac8d9ec5a5bb8
parentc780a7a90a8e7b074405ea2007e34f94e227e695
Add pg_relation_check_pages() to check on-disk pages of a relation

This makes use of CheckBuffer() introduced in c780a7a, adding a SQL
wrapper able to do checks for all the pages of a relation.  By default,
all the fork types of a relation are checked, and it is possible to
check only a given relation fork.  Note that if the relation given in
input has no physical storage or is temporary, then no errors are
generated, allowing full-database checks when coupled with a simple scan
of pg_class for example.  This is not limited to clusters with data
checksums enabled, as clusters without data checksums can still apply
checks on pages using the page headers or for the case of a page full of
zeros.

This function returns a set of tuples consisting of:
- The physical file where a broken page has been detected (without the
segment number as that can be AM-dependent, which can be guessed from
the block number for heap).  A relative path from PGPATH is used.
- The block number of the broken page.

By default, only superusers have an access to this function but
execution rights can be granted to other users.

The feature introduced here is still minimal, and more improvements
could be done, like:
- Addition of a start and end block number to run checks on a range
of blocks, which would apply only if one fork type is checked.
- Addition of some progress reporting.
- Throttling, with configuration parameters in function input or
potentially some cost-based GUCs.

Regression tests are added for positive cases in the main regression
test suite, and TAP tests are added for cases involving the emulation of
page corruptions.

Bump catalog version.

Author: Julien Rouhaud, Michael Paquier
Reviewed-by: Masahiko Sawada, Justin Pryzby
Discussion: https://postgr.es/m/CAOBaU_aVvMjQn=ge5qPiJOPMmOj5=ii3st5Q0Y+WuLML5sR17w@mail.gmail.com
12 files changed:
doc/src/sgml/func.sgml
src/backend/catalog/system_views.sql
src/backend/utils/adt/Makefile
src/backend/utils/adt/pagefuncs.c [new file with mode: 0644]
src/include/catalog/catversion.h
src/include/catalog/pg_proc.dat
src/test/recovery/t/022_page_check.pl [new file with mode: 0644]
src/test/regress/expected/pagefuncs.out [new file with mode: 0644]
src/test/regress/parallel_schedule
src/test/regress/serial_schedule
src/test/regress/sql/pagefuncs.sql [new file with mode: 0644]
src/tools/pgindent/typedefs.list