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-09 15:50:40 -08:00
|
|
|
-- minimal test, basically just verifying that amcheck
|
|
|
|
CREATE TABLE bttest_a(id int8);
|
|
|
|
CREATE TABLE bttest_b(id int8);
|
|
|
|
|
|
|
|
INSERT INTO bttest_a SELECT * FROM generate_series(1, 100000);
|
|
|
|
INSERT INTO bttest_b SELECT * FROM generate_series(100000, 1, -1);
|
|
|
|
|
|
|
|
CREATE INDEX bttest_a_idx ON bttest_a USING btree (id);
|
|
|
|
CREATE INDEX bttest_b_idx ON bttest_b USING btree (id);
|
|
|
|
|
2019-06-25 23:19:31 -04:00
|
|
|
CREATE ROLE regress_bttest_role;
|
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-09 15:50:40 -08:00
|
|
|
|
|
|
|
-- verify permissions are checked (error due to function not callable)
|
2019-06-25 23:19:31 -04:00
|
|
|
SET ROLE regress_bttest_role;
|
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-09 15:50:40 -08:00
|
|
|
SELECT bt_index_check('bttest_a_idx'::regclass);
|
|
|
|
SELECT bt_index_parent_check('bttest_a_idx'::regclass);
|
|
|
|
RESET ROLE;
|
|
|
|
|
|
|
|
-- we, intentionally, don't check relation permissions - it's useful
|
|
|
|
-- to run this cluster-wide with a restricted account, and as tested
|
|
|
|
-- above explicit permission has to be granted for that.
|
2019-06-25 23:19:31 -04:00
|
|
|
GRANT EXECUTE ON FUNCTION bt_index_check(regclass) TO regress_bttest_role;
|
|
|
|
GRANT EXECUTE ON FUNCTION bt_index_parent_check(regclass) TO regress_bttest_role;
|
|
|
|
SET ROLE regress_bttest_role;
|
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-09 15:50:40 -08:00
|
|
|
SELECT bt_index_check('bttest_a_idx');
|
|
|
|
SELECT bt_index_parent_check('bttest_a_idx');
|
|
|
|
RESET ROLE;
|
|
|
|
|
|
|
|
-- verify plain tables are rejected (error)
|
|
|
|
SELECT bt_index_check('bttest_a');
|
|
|
|
SELECT bt_index_parent_check('bttest_a');
|
|
|
|
|
|
|
|
-- verify non-existing indexes are rejected (error)
|
|
|
|
SELECT bt_index_check(17);
|
|
|
|
SELECT bt_index_parent_check(17);
|
|
|
|
|
|
|
|
-- verify wrong index types are rejected (error)
|
|
|
|
BEGIN;
|
|
|
|
CREATE INDEX bttest_a_brin_idx ON bttest_a USING brin(id);
|
|
|
|
SELECT bt_index_parent_check('bttest_a_brin_idx');
|
|
|
|
ROLLBACK;
|
|
|
|
|
|
|
|
-- normal check outside of xact
|
|
|
|
SELECT bt_index_check('bttest_a_idx');
|
|
|
|
-- more expansive test
|
|
|
|
SELECT bt_index_parent_check('bttest_b_idx');
|
|
|
|
|
|
|
|
BEGIN;
|
|
|
|
SELECT bt_index_check('bttest_a_idx');
|
|
|
|
SELECT bt_index_parent_check('bttest_b_idx');
|
|
|
|
-- make sure we don't have any leftover locks
|
2017-03-14 13:07:38 -07:00
|
|
|
SELECT * FROM pg_locks
|
|
|
|
WHERE relation = ANY(ARRAY['bttest_a', 'bttest_a_idx', 'bttest_b', 'bttest_b_idx']::regclass[])
|
|
|
|
AND pid = pg_backend_pid();
|
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-09 15:50:40 -08:00
|
|
|
COMMIT;
|
|
|
|
|
2022-05-09 08:35:08 -07:00
|
|
|
--
|
|
|
|
-- Check that index expressions and predicates are run as the table's owner
|
|
|
|
--
|
|
|
|
TRUNCATE bttest_a;
|
|
|
|
INSERT INTO bttest_a SELECT * FROM generate_series(1, 1000);
|
|
|
|
ALTER TABLE bttest_a OWNER TO regress_bttest_role;
|
|
|
|
-- A dummy index function checking current_user
|
|
|
|
CREATE FUNCTION ifun(int8) RETURNS int8 AS $$
|
|
|
|
BEGIN
|
|
|
|
ASSERT current_user = 'regress_bttest_role',
|
|
|
|
format('ifun(%s) called by %s', $1, current_user);
|
|
|
|
RETURN $1;
|
|
|
|
END;
|
|
|
|
$$ LANGUAGE plpgsql IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE INDEX bttest_a_expr_idx ON bttest_a ((ifun(id) + ifun(0)))
|
|
|
|
WHERE ifun(id + 10) > ifun(10);
|
|
|
|
|
|
|
|
SELECT bt_index_check('bttest_a_expr_idx');
|
|
|
|
|
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-09 15:50:40 -08:00
|
|
|
-- cleanup
|
|
|
|
DROP TABLE bttest_a;
|
|
|
|
DROP TABLE bttest_b;
|
2022-05-09 08:35:08 -07:00
|
|
|
DROP FUNCTION ifun(int8);
|
2019-06-25 23:19:31 -04:00
|
|
|
DROP OWNED BY regress_bttest_role; -- permissions
|
|
|
|
DROP ROLE regress_bttest_role;
|