From: | Rémi Cura <remi(dot)cura(at)gmail(dot)com> |
---|---|
To: | PostgreSQL General <pgsql-general(at)postgresql(dot)org> |
Subject: | pg_advisory_lock problem |
Date: | 2014-08-10 23:10:59 |
Message-ID: | CAJvUf_vsEto-OW1ZbzrGkzbNpVamLHh-becWu0EV5hKpMcnQ_g@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hey dear list,
following the advise of Depesz I'm trying to use advisory lock.
I'm trying to perform parallel upsert.
I have 2 different sessions in which I run a very complicated querry (lot's
of CTE) concurrently. In fact this complicated querry is simply put inside
a plpgsql function for ease of calling.
the querry performs upsert in 3 different tables, each time using a
dedicated plpgsql function that looks like this :
---------
PERFORM pg_advisory_lock(#1 , 2 or 3 depending on the table#,id of the
stuff I want to upsert) ;
WITH stuff_to_upsert ()
,updating AS (update returning id)
,inserting AS (insert if not updated)
PERFORM pg_advisory_unlock(same as above).
--------
The querry call such plpgsql function like this
CTE_N(
SELECT r.*
FROM result_to_be_upserted, function_upserting(...) as r
)
Yet I still have errors of duplicated primary key being broken because
trying to insert 2 times the same stuff.
ERROR: duplicate key value violates unique constraint
"result_intersection_pkey"
DETAIL: Key (node_id)=(*12621*) already exists.
Of course when performing the querry sequencially I don't have any errors,
even performing it several times.
I have read the 2 pages relevant to pg_advisory lock, and I clean all the
advisory lock before executing the test that gives those errors.
After the errors happens (which means that 1 process completed and the
other failed), I can see that there is a lock in pg_locks with the id of
the row that caused the error when being upserted.
advisory;2953366;;;;;;3;*12621*;2;8/0;11380;ExclusiveLock;t;f
Any help is greatly appreciated, I have tried everything I could think of.
Thanks,
Cheers,
Rémi-C
From | Date | Subject | |
---|---|---|---|
Next Message | David G Johnston | 2014-08-11 03:23:56 | Re: pg_advisory_lock problem |
Previous Message | Seref Arikan | 2014-08-10 13:48:49 | Re: Disk space available, but getting error "could not write to hash-join temporary file: No space left on device" |