Should I implement DROP INDEX CONCURRENTLY? - Mailing list pgsql-hackers

From Daniel Farina
Subject Should I implement DROP INDEX CONCURRENTLY?
Date
Msg-id CACN56+NNLO=RamDAy+uSa_mKXVsM+HjrVj8ehGjfg-mO9qcpzA@mail.gmail.com
Whole thread Raw
Responses Re: Should I implement DROP INDEX CONCURRENTLY?
Re: Should I implement DROP INDEX CONCURRENTLY?
Re: Should I implement DROP INDEX CONCURRENTLY?
List pgsql-hackers
Hello list,

At Heroku we use CREATE INDEX CONCURRENTLY with great success, but
recently when frobbing around some indexes I realized that there is no
equivalent for DROP INDEX, and this is a similar but lesser problem
(as CREATE INDEX takes much longer), as DROP INDEX takes an ACCESS
EXCLUSIVE lock on the parent table while doing the work to unlink
files, which nominally one would think to be trivial, but I assure you
it is not at times for even indexes that are a handful of gigabytes
(let's say ~=< a dozen).  By non-trivial, I mean it can take 30+
seconds, but less than a couple of minutes.  The storage layer
(starting from the higher levels of abstraction) are XFS, a somewhat
trivial lvm setup, mdraid (8-ways), Amazon EBS (NBD?).

I was poking around at tablecmds and index.c and wonder if a similar
two-pass approach as used by CREATE INDEX CONCURRENTLY can be used to
create a DROP INDEX CONCURRENTLY, and if there would be any interest
in accepting such a patch.

Quoth index.c:
/* * To drop an index safely, we must grab exclusive lock on its parent * table.  Exclusive lock on the index alone is
insufficientbecause * another backend might be about to execute a query on the parent table. * If it relies on a
previouslycached list of index OIDs, then it could * attempt to access the just-dropped index.  We must therefore take
a* table lock strong enough to prevent all queries on the table from * proceeding until we commit and send out a
shared-cache-invalnotice * that will make them update their index lists. */
 

Could I make the ACCESS EXCLUSIVE section just long enough to commit
catalog updates, and then have the bulk of the work happen afterwards?

The general idea is:

1) set an index as "invalid", to ensure no backend will use it in planning
2) wait for the xmin horizon to advance to ensure no open snapshots
that may not see the invalidation of the index are gone (is there a
way to tighten that up? although even this conservative version would
be 80-90% of the value for us...)
3) then use performDeletions without taking a lock on the parent
table, similar to what's in tablecmds.c already.

A DROP INDEX CONCURRENTLY may leave an invalid index if aborted
instead of waiting for statement confirmation, just like CREATE INDEX
CONCURRENTLY.

--
fdr


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Windows env returns error while running "select pgstatindex"
Next
From: Peter Eisentraut
Date:
Subject: Re: REGRESS_OPTS default