DO $$
BEGIN
FOR count IN 1..100000
LOOP
PERFORM m.topic FROM messages m
WHERE m.id = floor(random() * 1376000 + 1)
FOR UPDATE SKIP LOCKED;
PERFORM pg_sleep(0.1);
END LOOP;
END;
$$
The problem is that transactions might want to lock large numbers of tuples at
any one time, so it's not possible to keep the locks objects in shared memory.
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
DO
$$
DECLARE
arg_1 int;
arg_2 int;
res int;
BEGIN
BEGIN
arg_1 := 10;
arg_2 := 0;
res := arg_1 / arg_2;
COMMIT;
EXCEPTION WHEN OTHERS THEN
ROLLBACK;
res := 0;
END;
END;
$$;
SQL Error [2D000]: ERROR: invalid transaction termination
Where: PL/pgSQL function inline_code_block line 12 at ROLLBACK
Да без шансов.