Re: Concurrency issue with DROP INDEX CONCURRENTLY

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Kiriakos Georgiou <kg(dot)postgresql(at)olympiakos(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Concurrency issue with DROP INDEX CONCURRENTLY
Date: 2023-02-09 20:16:06
Message-ID: 4b211593aff671b688c08d1870363cb46f5a335b.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 2023-02-09 at 10:45 -0500, Kiriakos Georgiou wrote:
> I have an interesting concurrency issue with DROP INDEX CONCURRENTLY that I
> can summarize with this test scenario:
>
> /**************************************************/
>
> — suppose we have this table and index
> create table test(x int);
> create index idx1 on test(x);
>
> — now suppose with the database “live” and the above table super busy (lots
> of queries on the table using index idx1), I decide to make the index unique
> create unique index concurrently idx2 on test(x); — runs fine
> drop index concurrently idx1; — took 3 hours to finish, since the table is super busy
>
> /**************************************************/
>
> Taking 3 hours to drop the index is not surprising (lots of queries on the table
> using idx1).  What surprises me is the drop index causes havoc with concurrency
> on the table, causing queries to pile up.
> Once the drop index finishes, everything goes back to normal.
>
> I thought by using the CONCURRENTLY option, the drop index is “safe” from concurrency
> issues for the underlying table, but in the above scenario it doesn’t appear to be “safe”.

DROP INDEX CONCURRENTLY also locks the table, but it waits until it finds a time when
it can get the lock right away. Once it has the lock, it finishes the task.
In the time when the table is locked, concurrent statements are blocked. This should
not take a long time, but perhaps that is enough to cause the havoc you observe.

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Brad White 2023-02-09 22:43:34 Re: Quoting issue from ODBC
Previous Message Kiriakos Georgiou 2023-02-09 19:12:06 Re: Concurrency issue with DROP INDEX CONCURRENTLY