referential integrity preventing simultaneous insert - Mailing list pgsql-general

From Edwin Grubbs
Subject referential integrity preventing simultaneous insert
Date
Msg-id d6b3d4ab04090910533700a02a@mail.gmail.com
Whole thread Raw
Responses Re: referential integrity preventing simultaneous insert  (Michael Fuhr <mike@fuhr.org>)
List pgsql-general
Hello,

I have experienced problems with postgres hanging when two inserts
reference the same foreign key. It appears that the second insert is
waiting for the first insert to release a lock.
Here is an example of how to recreate the problem. Please ignore the
lack of sequences, since that is irrelevent to the problem. I have
tested this under pg 7.4.3.

----------------------------------------------------------
-- Set up test database:

CREATE TABLE model (
    id INTEGER PRIMARY KEY,
    name varchar(20)
);

CREATE TABLE car (
    id INTEGER PRIMARY KEY,
    model_id INTEGER REFERENCES model
);

INSERT INTO model VALUES (1, 'one');

----------------------------------------------------------
-- First connection opens a transaction and adds a reference to model id=1.
BEGIN; INSERT INTO car VALUES (5, 1);
-- Do not commit this transaction.
----------------------------------------------------------
-- Open a separate connection.
-- Second connection does the same and will hang until the
-- first transaction ends.
BEGIN; INSERT INTO car VALUES (6, 1);
----------------------------------------------------------

Is this fixed in postgres 8? If it still requires work, I may be able
to help fund it to get it completed sooner.

Thanks,
Edwin Grubbs

pgsql-general by date:

Previous
From: Phil Endecott
Date:
Subject: Re: Obtaining the Julian Day from a date
Next
From: Oleg Bartunov
Date:
Subject: Re: Text Search vs MYSQL vs Lucene