Skip to content

Instantly share code, notes, and snippets.

@filipechagas
Created September 2, 2021 17:11
Show Gist options
  • Save filipechagas/f89c7ca6d2314f16e571b30fc0cf14cf to your computer and use it in GitHub Desktop.
Save filipechagas/f89c7ca6d2314f16e571b30fc0cf14cf to your computer and use it in GitHub Desktop.
Postgres Advisory Lock - Pessimistic application enforced lock
SELECT version, json_content, pg_try_advisory_xact_lock(s.id) as locked, s.id as id
FROM snapshots s
WHERE ar_id = $1
-- from https://github.com/crabzilla/crabzilla/blob/f66e43ca4d7c119a00fab68c48386aa7672b0e95/crabzilla-engine-postgres/src/main/java/io/github/crabzilla/engine/command/CommandController.kt#L48
-- more at https://hashrocket.com/blog/posts/advisory-locks-in-postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment