FOR UPDATE SKIP LOCKED is the whole queue
A job queue in Postgres needs one query. Workers select pending rows FOR UPDATE SKIP LOCKED, and a row another worker holds is skipped instead of waited on. No advisory locks, no polling table, no second system.
SELECT id, payload FROM jobs
WHERE status = 'pending' AND run_at <= now()
ORDER BY id LIMIT 50
FOR UPDATE SKIP LOCKED;Run the workers at READ COMMITTED. Under REPEATABLE READ they spend their lives retrying serialization failures.
postgresqlqueues