pgsql: Add pg_relation_check_pages() to check on-disk pages of a relati - Mailing list pgsql-committers

From Michael Paquier
Subject pgsql: Add pg_relation_check_pages() to check on-disk pages of a relati
Date
Msg-id E1kXbwH-0006Jz-9q@gemulon.postgresql.org
Whole thread Raw
Responses Re: pgsql: Add pg_relation_check_pages() to check on-disk pages of a relati  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-committers
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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f2b883969557f4572cdfa87e1a40083d2b1272e7

Modified Files
--------------
doc/src/sgml/func.sgml                  |  50 +++++++
src/backend/catalog/system_views.sql    |   9 ++
src/backend/utils/adt/Makefile          |   1 +
src/backend/utils/adt/pagefuncs.c       | 229 +++++++++++++++++++++++++++++++
src/include/catalog/catversion.h        |   2 +-
src/include/catalog/pg_proc.dat         |   7 +
src/test/recovery/t/022_page_check.pl   | 231 ++++++++++++++++++++++++++++++++
src/test/regress/expected/pagefuncs.out |  72 ++++++++++
src/test/regress/parallel_schedule      |   2 +-
src/test/regress/serial_schedule        |   1 +
src/test/regress/sql/pagefuncs.sql      |  41 ++++++
src/tools/pgindent/typedefs.list        |   1 +
12 files changed, 644 insertions(+), 2 deletions(-)


pgsql-committers by date:

Previous
From: Michael Paquier
Date:
Subject: pgsql: Add CheckBuffer() to check on-disk pages without shared buffer l
Next
From: Tom Lane
Date:
Subject: Re: pgsql: Add pg_relation_check_pages() to check on-disk pages of a relati