postgres.git / summary / log / commit / refs

commit    43b6f3ed8b135d8452e820e6489d90bd86c4ef4e
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Fri Sep 04 16:40:28 2020 +0000
First released in: 14.0, 9.6.20, 10.15, 11.10, 12.5, 13.0

    Fix rare deadlock failure in create_am regression test.
    
    The "DROP ACCESS METHOD gist2" test will require locking the index
    to be dropped and then its table; while most ordinary operations
    lock a table first then its index.  While no concurrent test scripts
    should be touching fast_emp4000, autovacuum might chance to be
    processing that table when the DROP runs, resulting in a deadlock
    failure.  This is pretty rare but we see it in the buildfarm from
    time to time.
    
    To fix, acquire a lock on fast_emp4000 before issuing the DROP.
    
    Since the point of the exercise is mostly to prevent buildfarm
    failures, back-patch to 9.6 where this test was introduced.
    
    Discussion: https://postgr.es/m/839004.1599185607@sss.pgh.pa.us


src/test/regress/expected/create_am.out | 5 +++++ src/test/regress/sql/create_am.sql | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/test/regress/expected/create_am.out b/src/test/regress/expected/create_am.out index 47dd885c4e9..0b8ba6dbfab 100644 --- a/src/test/regress/expected/create_am.out +++ b/src/test/regress/expected/create_am.out @@ -97,5 +97,10 @@ ERROR: cannot drop access method gist2 because other objects depend on it DETAIL: index grect2ind2 depends on operator class box_ops for access method gist2 HINT: Use DROP ... CASCADE to drop the dependent objects too. -- Drop access method cascade +-- To prevent a (rare) deadlock against autovacuum, +-- we must lock the table that owns the index that will be dropped +BEGIN; +LOCK TABLE fast_emp4000; DROP ACCESS METHOD gist2 CASCADE; NOTICE: drop cascades to index grect2ind2 +COMMIT; diff --git a/src/test/regress/sql/create_am.sql b/src/test/regress/sql/create_am.sql index 3e0ac104f3c..1aa338d3e67 100644 --- a/src/test/regress/sql/create_am.sql +++ b/src/test/regress/sql/create_am.sql @@ -65,4 +65,9 @@ ROLLBACK; DROP ACCESS METHOD gist2; -- Drop access method cascade +-- To prevent a (rare) deadlock against autovacuum, +-- we must lock the table that owns the index that will be dropped +BEGIN; +LOCK TABLE fast_emp4000; DROP ACCESS METHOD gist2 CASCADE; +COMMIT; [parent: 526df0a236df]