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.

Revisions

  1. filipechagas created this gist Sep 2, 2021.
    6 changes: 6 additions & 0 deletions pg-advisory-lock.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    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