I am new for PostgreSQL. I want to simulate deadlock for this schedule:
How to simulate deadlock in PostgreSQL? Is it possible at all? How to lock particular column?
BEGIN;
UPDATE deadlock_demonstration
SET salary1=(SELECT salary1
FROM deadlock_demonstration
WHERE worker_id = 1
FOR UPDATE)+100
WHERE worker_id=1;
SELECT pg_sleep(5);
commit;
SELECT salary2 FROM deadlock_demonstration WHERE worker_id = 1 FOR UPDATE;
In another screen, I have run this:
BEGIN;
UPDATE deadlock_demonstration
SET salary2=(SELECT salary1
FROM deadlock_demonstration
WHERE worker_id = 1
FOR UPDATE)+200
WHERE worker_id=1;
SELECT pg_sleep(5);
commit;
SELECT salary1 FROM deadlock_demonstration WHERE worker_id = 1 FOR UPDATE;
Why deadlock is not happening? Can you give a suggestion, what I should change in order to stimulate deadlock?