Re: does reindex need exclusive table access? - Mailing list pgsql-general

From Craig Ringer
Subject Re: does reindex need exclusive table access?
Date
Msg-id 4EAF6EE1.3080007@ringerc.id.au
Whole thread Raw
In response to does reindex need exclusive table access?  ("Gauthier, Dave" <dave.gauthier@intel.com>)
Responses Re: does reindex need exclusive table access?  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: does reindex need exclusive table access?  (Vincent de Phily <vincent.dephily@mobile-devices.fr>)
List pgsql-general
On 01/11/11 02:51, Gauthier, Dave wrote:
> v8.3.4 on linux.
>
>
>
> Does "reindex table foo" require no other users accessing the foo
> table?  Trying to understand why this seems to be stalled when I attempt
> this on a live DB (if runs fine/fast on a copy of the DB that no one uses).

Yes, it requires an exclusive lock.

It doesn't matter whether or not you run it as part of an explicit
transaction.

There is not currently any 'REINDEX CONCURRENTLY' command - not unless
it's been added in a very recent version and I haven't noticed yet. You
can CREATE INDEX CONCURRENTLY then drop the old index, though.

A workaround for reindexing while live is to begin a transaction, create
the new index with a new name, drop the old one, rename the new one to
the old one, and commit. This only requires an exclusive lock for the
period of the drop and rename. On more recent versions you can even use
this for indexes that implement primary key or unique constrants by
using the 'ADD CONSTRAINT ... USING INDEX ...' syntax; see:

  http://www.postgresql.org/docs/current/static/sql-altertable.html

--
Craig Ringer

pgsql-general by date:

Previous
From: "daflmx"
Date:
Subject:
Next
From: Tom Lane
Date:
Subject: Re: does reindex need exclusive table access?