PostgreSQL - Transactions and Concurrency
You want to ensure two different sessions do not run a critical section simultaneously using advisory locks. Which approach is best?
-- Session 1 and 2 run this code:
SELECT pg_try_advisory_lock(42);
-- If true, run critical section, then
SELECT pg_advisory_unlock(42);
