Performance Locks DML
Claim Queue Rows with FOR UPDATE SKIP LOCKED in PostgreSQL
Oct 24, 2026 / · 11 min read · skip locked row locking queue table delete returning ctid mvcc concurrency batch delete ·Claim Queue Rows with FOR UPDATE SKIP LOCKED in PostgreSQL Several workers poll the same job table with SELECT ... LIMIT 10, and a plain LIMIT does nothing to stop two of them from getting the same list of items to process. Add FOR UPDATE and the second worker hangs until the first one commits. Put FOR UPDATE SKIP …
Read MoreTrack Two-Phase Commit State with pg_prepared_xacts
Jun 19, 2026 / · 7 min read · postgresql database administration sql queries transactions two-phase commit pg_prepared_xacts postgres dba ·Track Two-Phase Commit State with pg_prepared_xacts A prepared transaction that never gets committed or rolled back is one of the quieter ways a PostgreSQL database degrades. It keeps holding locks, it pins the transaction-ID horizon so VACUUM cannot reclaim dead rows, and nothing in normal monitoring screams about it. …
Read MorePostgreSQL Advisory Locks with pg_advisory_lock
PostgreSQL Advisory Locks with pg_advisory_lock Two scheduled jobs fire at the same minute and both try to process the same nightly batch. Nothing in the data stops them — there is no single row to lock, because the work has not produced rows yet. Row and table locks are the wrong tool here. What you want is a named …
Read More