question on foreign key lock - Mailing list pgsql-general

From Filip Rembiałkowski
Subject question on foreign key lock
Date
Msg-id 5092A452.3070602@gmail.com
Whole thread Raw
List pgsql-general
Hello.

Why adding FK creates AccessExclusiveLock on referenced tabble?

{{{
CREATE TABLE A ( id integer, idb integer );
INSERT INTO A (id,idb) SELECT x, x%4 FROM generate_series(1,100) x;

CREATE TABLE B ( id int primary key );
INSERT INTO B VALUES (0),(1),(2),(3);

BEGIN;
ALTER TABLE A ADD CONSTRAINT a_idb_fkey FOREIGN KEY (idb) REFERENCES b;
SELECT * FROM pg_locks l, pg_class c WHERE l.pid = pg_backend_pid() AND
l.locktype='relation' AND l.mode ilike '%exclusive%' AND l.relation=c.oid;
ROLLBACK;
}}}


Last SELECT is showing AccessExclusive on B.
Why not Exclusive?


Thanks,
Filip


pgsql-general by date:

Previous
From: Vincent Veyron
Date:
Subject: Re: role does not exist
Next
From: Alban Hertroys
Date:
Subject: Re: Unexplained Major Vacuum Archive Activity During Vacuum