pgsql: Avoid potential deadlock in InitCatCachePhase2().

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Avoid potential deadlock in InitCatCachePhase2().
Date: 2011-03-22 17:01:37
Message-ID: E1Q24xd-0001bb-Sl@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Avoid potential deadlock in InitCatCachePhase2().

Opening a catcache's index could require reading from that cache's own
catalog, which of course would acquire AccessShareLock on the catalog.
So the original coding here risks locking index before heap, which could
deadlock against another backend trying to get exclusive locks in the
normal order. Because InitCatCachePhase2 is only called when a backend
has to start up without a relcache init file, the deadlock was seldom seen
in the field. (And by the same token, there's no need to worry about any
performance disadvantage; so not much point in trying to distinguish
exactly which catalogs have the risk.)

Bug report, diagnosis, and patch by Nikhil Sontakke. Additional commentary
by me. Back-patch to all supported branches.

Branch
------
REL8_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/e2d64f81a6a6502799e0cf7b7b8aa4b764e657f9

Modified Files
--------------
src/backend/utils/cache/catcache.c | 9 +++++++++
src/backend/utils/cache/relcache.c | 6 ++++++
2 files changed, 15 insertions(+), 0 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2011-03-22 19:58:31 pgsql: Throw error for indeterminate collation of an ORDER/GROUP/DISTIN
Previous Message Simon Riggs 2011-03-22 16:37:49 pgsql: Update docs to say you need fsync to make sync rep work fast.