Lock changes with 8.1 - what's the right lock?

From: Wes <wespvp(at)syntegra(dot)com>
To: pgsql general <pgsql-general(at)postgresql(dot)org>
Subject: Lock changes with 8.1 - what's the right lock?
Date: 2006-07-16 22:46:16
Message-ID: C0E02BE8.2A04A%wespvp@syntegra.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

8.1 improved locking for foreign key references but had an unexpected
consequence to our application - no parallel loads in our application.

The application does an EXCLUSIVE lock on 'addresses'. It then gets all of
the keys from 'addresses' it needs, and adds new ones encountered in this
load. It then completes the transaction, releases the exclusive lock, and
inserts the other table's records using the values read from/inserted into
'addresses'.

There are foreign key constraints between the various tables and 'addresses'
to insure referential integrity.

Previously (pgsql 7.4.5), multiple loads would run simultaneously - and
occasionally got 'deadlock detected' with the foreign key locks even though
they were referenced in sorted order. When loading tables other than
'addresses', foreign key locks did not prevent other jobs from grabbing the
exclusive lock on 'addresses'.

With 8.1.4, the foreign key locks prevent other instances from grabbing the
lock, so they wait until the first job is complete - only one job loads at a
time.

About EXCLUSIVE locks, the manual says: "...only reads from the table can
proceed in parallel with a transaction holding this lock mode."

What is now the appropriate lock? It needs to:

1. Prevent others from updating the table
2. Block other jobs that are requesting the same lock (if job 2 does a
SELECT and finds nothing, it will try to create the record that job 1 may
already have created in its transaction).
3. Not conflict with foreign key reference locks

SHARE does not appear to be appropriate - it would fail #2. Maybe "SHARE
UPDATE EXCLUSIVE"?

Wes

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message msiner 2006-07-17 00:12:54 Simple webuser setup
Previous Message Brian Mathis 2006-07-16 20:17:13 Re: customizing pg_dump together with copy.c's DoCopy function