Postgres Advisory Lock and Keyset Scan
Two plain-Postgres patterns on the node-postgres driver with no ORM and no lock table. Job locks are transaction-level only, because the manual states that session-level locks survive a rolled-back transaction and need matched unlock pairs, so a worker that dies mid-job strands a lock on a pooled connection; pg_advisory_xact_lock releases on COMMIT, ROLLBACK, and a dropped socket alike, and pg_try_advisory_xact_lock gives a cron worker the skip signal instead of a queue. String keys hash through SHA-256 into the full signed int64 space, and the manual's own LIMIT footgun is documented in place so nobody reintroduces a locking function in the target list of a paginated query. The scan half replaces OFFSET with the seek method, using the row-value predicate that Postgres can turn into an index access predicate rather than the OR expansion that it cannot. Cursors are opaque base64url tuples validated on decode against length, charset, arity, field types, timestamp parseability, and UUID shape, since a cursor arrives off a query string and is a trust boundary.
npx shadcn@latest add https://ui.aryank.space/r/pg-advisory-lock-keyset-scan.jsonInstalls from ui.aryank.space. To add it by hand, copy the files in Files below, or register the @compronents namespace via the docs.
pg_advisory_xact_lock is transaction-scoped: the lock is acquired inside the job's transaction and released when it commits, no matched unlock call to forget.