postgresql/src/test/regress/sql/pagefuncs.sql

42 lines
1.5 KiB
MySQL
Raw Normal View History

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
2020-10-28 04:15:00 +01:00
--
-- Tests for functions related to relation pages
--
-- Restricted to superusers by default
CREATE ROLE regress_pgfunc_user;
SET ROLE regress_pgfunc_user;
SELECT pg_relation_check_pages('pg_class'); -- error
SELECT pg_relation_check_pages('pg_class', 'main'); -- error
RESET ROLE;
DROP ROLE regress_pgfunc_user;
-- NULL and simple sanity checks
SELECT pg_relation_check_pages(NULL); -- empty result
SELECT pg_relation_check_pages(NULL, NULL); -- empty result
SELECT pg_relation_check_pages('pg_class', 'invalid_fork'); -- error
-- Relation types that are supported
CREATE TABLE pgfunc_test_tab (id int);
CREATE INDEX pgfunc_test_ind ON pgfunc_test_tab(id);
INSERT INTO pgfunc_test_tab VALUES (generate_series(1,1000));
SELECT pg_relation_check_pages('pgfunc_test_tab');
SELECT pg_relation_check_pages('pgfunc_test_ind');
DROP TABLE pgfunc_test_tab;
CREATE MATERIALIZED VIEW pgfunc_test_matview AS SELECT 1;
SELECT pg_relation_check_pages('pgfunc_test_matview');
DROP MATERIALIZED VIEW pgfunc_test_matview;
CREATE SEQUENCE pgfunc_test_seq;
SELECT pg_relation_check_pages('pgfunc_test_seq');
DROP SEQUENCE pgfunc_test_seq;
-- pg_relation_check_pages() returns no results if passed relations that
-- do not support the operation, like relations without storage or temporary
-- relations.
CREATE TEMPORARY TABLE pgfunc_test_temp AS SELECT generate_series(1,10) AS a;
SELECT pg_relation_check_pages('pgfunc_test_temp');
DROP TABLE pgfunc_test_temp;
CREATE VIEW pgfunc_test_view AS SELECT 1;
SELECT pg_relation_check_pages('pgfunc_test_view');
DROP VIEW pgfunc_test_view;