Re: Connections hang indefinitely while taking a gin index's LWLock buffer_content lock(PG10.7)
Alexander Korotkov <a.korotkov@postgrespro.ru>
From: Alexander Korotkov <a.korotkov@postgrespro.ru>
To: chenhj <chjischj@163.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2019-09-29T15:12:31Z
Lists: pgsql-hackers
On Sun, Sep 29, 2019 at 5:38 PM Alexander Korotkov
<a.korotkov@postgrespro.ru> wrote:
> On Sun, Sep 29, 2019 at 11:17 AM chenhj <chjischj@163.com> wrote:
> > Does the locking order of autovacuum process(root->right->left) correct? While insert process lock gin buffer by order of bottom->top and left->right.
> >
> > 1. vacuum(root->right->left):
>
> Starting from root seems OK for me, because vacuum blocks all
> concurrent inserts before doing this. But this needs to be properly
> documented in readme.
>
> Locking from right to left is clearly wrong. It could deadlock with
> concurrent ginStepRight(), which locks from left to right. I expect
> this happened in your case. I'm going to reproduce this and fix.
I just managed to reproduce this using two sessions on master branch.
session 1
session 2
# create table test with (autovacuum_enabled = false) as (select
array[1] ar from generate_series(1,20000) i);
# create index test_ar_idx on test using gin (ar);
# vacuum analyze test;
# delete from test;
# set enable_seqscan = off;
gdb> b ginbtree.c:150
# select * from test where ar @> '{1}'::integer[];
Step in gdb just before ReadBuffer() in ReleaseAndReadBuffer().
gdb> b ginvacuum.c:155
# vacuum test;
gdb > continue
gdb> continue
------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Commits
-
Fix traversing to the deleted GIN page via downlink
- ab64b474d9be 10.12 landed
- c0bf35421529 11.7 landed
- ee437ca7408b 12.2 landed
- d5ad7a09afd0 13.0 landed
- 1414821e1688 9.4.26 landed
- 4fc4856849de 9.5.21 landed
- 99f5888d358a 9.6.17 landed
-
Revise GIN README
- b6f57c2d7bfc 10.12 landed
- 287192bda245 11.7 landed
- ca05fa5375eb 12.2 landed
- 32ca32d0bed4 13.0 landed
- 91ce01a6e07b 9.4.26 landed
- 8165384babd9 9.5.21 landed
- 84dcf5235984 9.6.17 landed
-
Fix deadlock between ginDeletePage() and ginStepRight()
- 21ad61ab3178 10.12 landed
- 9f292798992e 11.7 landed
- 051c50c01c32 12.2 landed
- e14641197a56 13.0 landed