summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Freund2017-03-14 20:07:38 +0000
committerAndres Freund2017-03-14 20:07:38 +0000
commit71504026556fc1494c9a7045aad9645f7d9e4cdf (patch)
tree7fa010fd2c12e02b0de000e15a70e64edb4e3948
parentbb4a39637ac6155b4ed5a9f83d17921fb57400b6 (diff)
amcheck: Harden tests against concurrent autovacuums.
The previous coding of the test was vulnerable against autovacuum triggering work on one of the tables in check_btree.sql. For the purpose of the test it's entirely sufficient to check for locks taken by the current process, so add an appropriate restriction. While touching the test, expand it to also check for locks on the underlying relations, rather than just the indexes. Reported-By: Tom Lane Discussion: https://postgr.es/m/[email protected]
-rw-r--r--contrib/amcheck/expected/check_btree.out4
-rw-r--r--contrib/amcheck/sql/check_btree.sql4
2 files changed, 6 insertions, 2 deletions
diff --git a/contrib/amcheck/expected/check_btree.out b/contrib/amcheck/expected/check_btree.out
index 612ce7799d..df3741e2c9 100644
--- a/contrib/amcheck/expected/check_btree.out
+++ b/contrib/amcheck/expected/check_btree.out
@@ -77,7 +77,9 @@ SELECT bt_index_parent_check('bttest_b_idx');
(1 row)
-- make sure we don't have any leftover locks
-SELECT * FROM pg_locks WHERE relation IN ('bttest_a_idx'::regclass, 'bttest_b_idx'::regclass);
+SELECT * FROM pg_locks
+WHERE relation = ANY(ARRAY['bttest_a', 'bttest_a_idx', 'bttest_b', 'bttest_b_idx']::regclass[])
+ AND pid = pg_backend_pid();
locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted | fastpath
----------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-----+------+---------+----------
(0 rows)
diff --git a/contrib/amcheck/sql/check_btree.sql b/contrib/amcheck/sql/check_btree.sql
index 783fb635e7..fd90531027 100644
--- a/contrib/amcheck/sql/check_btree.sql
+++ b/contrib/amcheck/sql/check_btree.sql
@@ -49,7 +49,9 @@ 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
-SELECT * FROM pg_locks WHERE relation IN ('bttest_a_idx'::regclass, 'bttest_b_idx'::regclass);
+SELECT * FROM pg_locks
+WHERE relation = ANY(ARRAY['bttest_a', 'bttest_a_idx', 'bttest_b', 'bttest_b_idx']::regclass[])
+ AND pid = pg_backend_pid();
COMMIT;
-- cleanup