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 07:50:40 +08:00
|
|
|
CREATE TABLE bttest_a(id int8);
|
|
|
|
CREATE TABLE bttest_b(id int8);
|
2018-04-08 04:00:39 +08:00
|
|
|
CREATE TABLE bttest_multi(id int8, data int8);
|
2018-04-26 03:05:53 +08:00
|
|
|
CREATE TABLE delete_test_table (a bigint, b bigint, c bigint, d bigint);
|
|
|
|
-- Stabalize tests
|
|
|
|
ALTER TABLE bttest_a SET (autovacuum_enabled = false);
|
|
|
|
ALTER TABLE bttest_b SET (autovacuum_enabled = false);
|
|
|
|
ALTER TABLE bttest_multi SET (autovacuum_enabled = false);
|
|
|
|
ALTER TABLE delete_test_table SET (autovacuum_enabled = false);
|
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 07:50:40 +08:00
|
|
|
INSERT INTO bttest_a SELECT * FROM generate_series(1, 100000);
|
|
|
|
INSERT INTO bttest_b SELECT * FROM generate_series(100000, 1, -1);
|
2018-04-08 04:00:39 +08:00
|
|
|
INSERT INTO bttest_multi SELECT i, i%2 FROM generate_series(1, 100000) as i;
|
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 07:50:40 +08:00
|
|
|
CREATE INDEX bttest_a_idx ON bttest_a USING btree (id);
|
|
|
|
CREATE INDEX bttest_b_idx ON bttest_b USING btree (id);
|
2018-04-08 04:00:39 +08:00
|
|
|
CREATE UNIQUE INDEX bttest_multi_idx ON bttest_multi
|
|
|
|
USING btree (id) INCLUDE (data);
|
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 07:50:40 +08:00
|
|
|
CREATE ROLE bttest_role;
|
|
|
|
-- verify permissions are checked (error due to function not callable)
|
|
|
|
SET ROLE bttest_role;
|
|
|
|
SELECT bt_index_check('bttest_a_idx'::regclass);
|
|
|
|
ERROR: permission denied for function bt_index_check
|
|
|
|
SELECT bt_index_parent_check('bttest_a_idx'::regclass);
|
|
|
|
ERROR: permission denied for function bt_index_parent_check
|
|
|
|
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.
|
|
|
|
GRANT EXECUTE ON FUNCTION bt_index_check(regclass) TO bttest_role;
|
|
|
|
GRANT EXECUTE ON FUNCTION bt_index_parent_check(regclass) TO bttest_role;
|
2018-04-01 10:52:01 +08:00
|
|
|
GRANT EXECUTE ON FUNCTION bt_index_check(regclass, boolean) TO bttest_role;
|
|
|
|
GRANT EXECUTE ON FUNCTION bt_index_parent_check(regclass, boolean) TO 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-10 07:50:40 +08:00
|
|
|
SET ROLE bttest_role;
|
|
|
|
SELECT bt_index_check('bttest_a_idx');
|
|
|
|
bt_index_check
|
|
|
|
----------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT bt_index_parent_check('bttest_a_idx');
|
|
|
|
bt_index_parent_check
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
RESET ROLE;
|
|
|
|
-- verify plain tables are rejected (error)
|
|
|
|
SELECT bt_index_check('bttest_a');
|
|
|
|
ERROR: "bttest_a" is not an index
|
|
|
|
SELECT bt_index_parent_check('bttest_a');
|
|
|
|
ERROR: "bttest_a" is not an index
|
|
|
|
-- verify non-existing indexes are rejected (error)
|
|
|
|
SELECT bt_index_check(17);
|
|
|
|
ERROR: could not open relation with OID 17
|
|
|
|
SELECT bt_index_parent_check(17);
|
|
|
|
ERROR: could not open relation with OID 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');
|
|
|
|
ERROR: only B-Tree indexes are supported as targets for verification
|
|
|
|
DETAIL: Relation "bttest_a_brin_idx" is not a B-Tree index.
|
|
|
|
ROLLBACK;
|
|
|
|
-- normal check outside of xact
|
|
|
|
SELECT bt_index_check('bttest_a_idx');
|
|
|
|
bt_index_check
|
|
|
|
----------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
2018-04-01 10:52:01 +08:00
|
|
|
-- more expansive tests
|
|
|
|
SELECT bt_index_check('bttest_a_idx', true);
|
|
|
|
bt_index_check
|
|
|
|
----------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT bt_index_parent_check('bttest_b_idx', true);
|
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 07:50:40 +08:00
|
|
|
bt_index_parent_check
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
BEGIN;
|
|
|
|
SELECT bt_index_check('bttest_a_idx');
|
|
|
|
bt_index_check
|
|
|
|
----------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT bt_index_parent_check('bttest_b_idx');
|
|
|
|
bt_index_parent_check
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- make sure we don't have any leftover locks
|
2017-03-15 04:07:38 +08: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-10 07:50:40 +08:00
|
|
|
locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted | fastpath
|
|
|
|
----------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-----+------+---------+----------
|
|
|
|
(0 rows)
|
|
|
|
|
|
|
|
COMMIT;
|
2018-04-08 04:00:39 +08:00
|
|
|
-- normal check outside of xact for index with included columns
|
|
|
|
SELECT bt_index_check('bttest_multi_idx');
|
|
|
|
bt_index_check
|
|
|
|
----------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- more expansive test for index with included columns
|
|
|
|
SELECT bt_index_parent_check('bttest_multi_idx', true);
|
|
|
|
bt_index_parent_check
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
2018-04-09 14:19:09 +08:00
|
|
|
-- repeat expansive test for index built using insertions
|
2018-04-08 04:00:39 +08:00
|
|
|
TRUNCATE bttest_multi;
|
|
|
|
INSERT INTO bttest_multi SELECT i, i%2 FROM generate_series(1, 100000) as i;
|
|
|
|
SELECT bt_index_parent_check('bttest_multi_idx', true);
|
|
|
|
bt_index_parent_check
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
2018-04-26 03:05:53 +08:00
|
|
|
--
|
|
|
|
-- Test for multilevel page deletion/downlink present checks
|
|
|
|
--
|
|
|
|
INSERT INTO delete_test_table SELECT i, 1, 2, 3 FROM generate_series(1,80000) i;
|
|
|
|
ALTER TABLE delete_test_table ADD PRIMARY KEY (a,b,c,d);
|
|
|
|
DELETE FROM delete_test_table WHERE a > 40000;
|
|
|
|
VACUUM delete_test_table;
|
|
|
|
DELETE FROM delete_test_table WHERE a > 10;
|
|
|
|
VACUUM delete_test_table;
|
|
|
|
SELECT bt_index_parent_check('delete_test_table_pkey', true);
|
|
|
|
bt_index_parent_check
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
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 07:50:40 +08:00
|
|
|
-- cleanup
|
|
|
|
DROP TABLE bttest_a;
|
|
|
|
DROP TABLE bttest_b;
|
2018-04-08 04:00:39 +08:00
|
|
|
DROP TABLE bttest_multi;
|
2018-04-26 03:05:53 +08:00
|
|
|
DROP TABLE delete_test_table;
|
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 07:50:40 +08:00
|
|
|
DROP OWNED BY bttest_role; -- permissions
|
|
|
|
DROP ROLE bttest_role;
|