Re: Deadlock with REINDEX TABLE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Erik Jones <erik(at)myemma(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Deadlock with REINDEX TABLE
Date: 2007-03-22 18:01:09
Message-ID: 19302.1174586469@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Erik Jones <erik(at)myemma(dot)com> writes:
> Mar 21 19:36:18 [info] User Info: REINDEX TABLE
> emma_messages_email_queue; [nativecode=ERROR: deadlock detected
> DETAIL: Process 12912 waits for AccessExclusiveLock on relation
> 138763808 of database 16384; blocked by process 15217.
> Process 15217 waits for RowExclusiveLock on relation 17111 of
> database 16384; blocked by process 12912.]

> Relation 138763808 is the primary key index on the table relation 17111.
> Proc 12912 is the REINDEX and proc 15217 is the contending query, I'm
> assuming it was an update due being a RowExclusive lock.

This looks like a lock-upgrade deadlock to me. REINDEX TABLE takes only
ShareLock on the table itself, but needs AccessExclusiveLock on each
index successively. What I'm guessing happened is that the conflicting
transaction did first a SELECT and then an UPDATE on the table; the
SELECT would take AccessShare (which it could hold concurrently with
the reindex's ShareLock) and then the UPDATE would block because its
RowExclusiveLock request has to wait for the ShareLock to release.

What's not entirely clear though is why the conflicting transaction had
any lock on the index at this point. The UPDATE wouldn't have acquired
index locks yet. The only idea that comes to mind is that the SELECT
was actually a cursor that was still open at the time of the UPDATE ...
does your app do things like that?

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message araza 2007-03-22 18:30:55 Re: Insert fail: could not open relation with OID 3221204992
Previous Message Tom Lane 2007-03-22 17:50:42 Re: Bug in CREATE/DROP TABLESPACE command