I encountered the following log in 8.4.1 and HEAD. The deadlock occured
on the same object (relation 17498 of database 17497). Is it reasonable?
ERROR: deadlock detected
DETAIL: Process 6313 waits for ExclusiveLock on relation 17498 of database 17497; blocked by process 6312.
Process6312 waits for ExclusiveLock on relation 17498 of database 17497; blocked by process 6313. Process 6313:
SELECTtest() Process 6312: SELECT test()
HINT: See server log for query details.
CONTEXT: SQL function "test" statement 1
STATEMENT: SELECT test()
(relation 17498 is table 'a')
A reproducible test set is:
----
CREATE TABLE a (i integer PRIMARY KEY);
CREATE TABLE b (i integer REFERENCES a(i));
CREATE FUNCTION test() RETURNS VOID AS
$$
LOCK a IN EXCLUSIVE MODE;
LOCK b IN EXCLUSIVE MODE;
DELETE FROM a;
$$
LANGUAGE sql STRICT;
----
# Repeat the following commands in shell.
psql -c "SELECT test()" &
psql -c "SELECT test()" &
psql -c "SELECT test()" &
wait
Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center