Agent skill

Pglock Integration

by cirello-io in cirello-io/pglock

A skill your agent uses when building or modifying a Go application that uses cirello.io/pglock for PostgreSQL-backed distributed locks, per-resource mutual exclusion, leader election, leases…

Apache-2.0Auto-check passedTesting & QA

Install Pglock Integration

skills CLI
$ npx skills add cirello-io/pglock --skill pglock-integration -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install cirello-io/pglock pglock-integration --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/cirello-io/pglock.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/pglock-integration .claude/skills/pglock-integration && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
pglock-integration
GitHub stars
123
Token cost
~2.2k tokens
SKILL.md length
962 words
Files
5 (incl. scripts, references)
Skills in repo
1
Repo updated
First seen
Licence
Apache-2.0

At a glance

A skill your agent uses when building or modifying a Go application that uses cirello.io/pglock for PostgreSQL-backed distributed locks, per-resource mutual exclusion, leader election, leases…

  • Works in 7 steps: Add cirello.io/pglock to the… → Choose the driver constructor… → Provision the lock table and its _rvn… → …
  • Modifying a Go application that uses cirello.io/pglock for PostgreSQL-backed distributed locks
  • SKILL.md covers Integration Sequence, Basic Bootstrap, Lock Patterns and Errors And Operations, plus 2 more sections
  • Runs Python scripts from its folder; calls python3

What it does

Pglock Integration is an agent skill from cirello-io/pglock. Use when building or modifying a Go application that uses cirello.io/pglock for PostgreSQL-backed distributed locks, per-resource mutual exclusion, leader election, leases, heartbeats, lock metadata, or lock-aware workflows. Guide dependency and driver selection, schema provisioning, client configuration, acquisition and release, context cancellation, error handling, and integration tests. Do not use for changing pglock's own internals or for generic PostgreSQL administration.

Its SKILL.md is about 2.2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 7 other files, including scripts and reference files (for example `evals/evals.json`, `evals/trigger_queries.json` and `references/integration-guide.md`). Compatibility notes: Requires a Go module compatible with the selected pglock version and PostgreSQL 15 or newer. The current package declares Go 1.25.0. Integration tests need a…

It sits in Testing & QA, covering Integration testing. It works with PostgreSQL and SQL. The repository describes itself as: PostgreSQL Lock Client for Go. The licence is Apache-2.0.

When your agent uses it

  • Modifying a Go application that uses cirello.io/pglock for PostgreSQL-backed distributed locks
  • Per-resource mutual exclusion
  • Leader election
  • Lock-aware workflows

Example prompts

  • “/pglock-integration”

Requirements

  • Python 3
  • Compatibility (from SKILL.md): Requires a Go module compatible with the selected pglock version and PostgreSQL 15 or newer. The current package declares Go 1.25.0. Integration tests need a reachable PostgreSQL primary and permission to create or migrate the lock table and sequence.

Workflow steps

7 steps, taken from the first numbered list in SKILL.md.

  1. Add cirello.io/pglock to the application's Go module at the version the
  2. Choose the driver constructor deliberately. pglock.New validates the
  3. Provision the lock table and its _rvn sequence once. Prefer a
  4. Configure a single shared table and a stable owner identity for all
  5. Select lease and heartbeat values from the workload. A positive heartbeat
  6. Use AcquireContext or Do with an application context, and always release
  7. Test contention and lease behavior against PostgreSQL. SQLite or an in-memory

What it can do on your machine

Read from SKILL.md and the folder at commit 6d39959. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships 1 file in scripts/ (Python), which the agent can run.

    Shell commands in SKILL.md call:

    • python3

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

  • Compatibility

    Requires a Go module compatible with the selected pglock version and PostgreSQL 15 or newer. The current package declares Go 1.25.0. Integration tests need a reachable PostgreSQL primary and permission to create or migrate the lock table and sequence.

    From compatibility in the SKILL.md frontmatter.

Context cost

Pglock Integration loads about 2.2k tokens when it runs, and up to ~3.4k if it reads all its reference files. Until then it costs about 125 tokens; SKILL.md has 962 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~125
When it runs · the whole SKILL.md, loaded when a task matches
~2.2k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~3.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.

SKILL.md

The full file from cirello-io/pglock at commit 6d39959, republished under its Apache-2.0 licence (© cirello-io). 962 words, ~2,244 tokens.

Download SKILL.mdSave it as .claude/skills/pglock-integration/SKILL.md (or your agent's skills folder). This skill also uses 4 other files; get the full folder from GitHub.
name
pglock-integration
description
Use when building or modifying a Go application that uses cirello.io/pglock for PostgreSQL-backed distributed locks, per-resource mutual exclusion, leader election, leases, heartbeats, lock metadata, or lock-aware workflows. Guide dependency and driver selection, schema provisioning, client configuration, acquisition and release, context cancellation, error handling, and integration tests. Do not use for changing pglock's own internals or for generic PostgreSQL administration.
compatibility
Requires a Go module compatible with the selected pglock version and PostgreSQL 15 or newer. The current package declares Go 1.25.0. Integration tests need a reachable PostgreSQL primary and permission to create or migrate the lock table and sequence.
license
Apache-2.0
metadata.repository
cirello.io/pglock
metadata.purpose
third-party-application-integration
metadata.version
1

pglock Integration

Use this skill for application code that consumes cirello.io/pglock. Do not modify the library's implementation or tests unless the user explicitly asks for an upstream change. First identify the application operation that must be exclusive, the stable lock key, the maximum hold time, the behavior on contention, and what should happen if the database or lease becomes unhealthy.

Integration Sequence

  1. Add cirello.io/pglock to the application's Go module at the version the application supports. Use a PostgreSQL *sql.DB; keep one shared pool open for the application's clients.
  2. Choose the driver constructor deliberately. pglock.New validates the connection as the lib/pq driver. If the application uses pgx through github.com/jackc/pgx/v5/stdlib, use pglock.UnsafeNew after verifying that the *sql.DB really targets PostgreSQL. Do not use UnsafeNew to bypass an unknown or non-PostgreSQL driver.
  3. Provision the lock table and its <table>_rvn sequence once. Prefer a migration or TryCreateTable during controlled startup; use CreateTable when a duplicate table should be an error. Never drop the shared table from normal application startup.
  4. Configure a single shared table and a stable owner identity for all contenders. Use WithCustomTable only with a trusted, validated identifier; the package interpolates that table name into SQL. Never derive it directly from user input.
  5. Select lease and heartbeat values from the workload. A positive heartbeat must be no more than half the lease, and a lease at least four times the heartbeat is the safer starting point. The defaults are a 20-second lease and a 5-second heartbeat. Set the lease above normal critical-section time plus expected database latency, not merely above average execution time.
  6. Use AcquireContext or Do with an application context, and always release an acquired lock. Make long-running callbacks stop when their callback context is canceled because that context is also canceled when heartbeat loss is detected.
  7. Test contention and lease behavior against PostgreSQL. SQLite or an in-memory substitute cannot validate this package's PostgreSQL upsert, sequence, locking, and serialization behavior.

Basic Bootstrap

For lib/pq, the safe constructor is:

go
import (
	"context"
	"database/sql"
	"log"
	"time"

	"cirello.io/pglock"
	_ "github.com/lib/pq"
)

ctx := context.Background()
db, err := sql.Open("postgres", dsn)
if err != nil {
	log.Fatal(err)
}
if err := db.PingContext(ctx); err != nil {
	log.Fatal(err)
}

client, err := pglock.New(db,
	pglock.WithOwner(instanceID),
	pglock.WithLeaseDuration(20*time.Second),
	pglock.WithHeartbeatFrequency(5*time.Second),
)
if err != nil {
	log.Fatal(err)
}
if err := client.TryCreateTable(); err != nil {
	log.Fatal(err)
}

For pgx stdlib, open with the pgx driver and call UnsafeNew; New will return ErrNotPostgreSQLDriver because it only recognizes lib/pq:

go
import _ "github.com/jackc/pgx/v5/stdlib"

db, err := sql.Open("pgx", dsn)
client, err := pglock.UnsafeNew(db)

Check err after every setup call and close db only after all locks using it have been released.

Lock Patterns

Use a stable, bounded key shared by every process that must contend, such as campaign:<id> or leader:<service>. The schema stores names and owners in VARCHAR(255), so bound or hash longer application identifiers before passing them to pglock.

For a bounded critical section:

go
import (
	"errors"
	"log"
)

lock, err := client.AcquireContext(ctx, lockKey)
if err != nil {
	if errors.Is(err, pglock.ErrNotAcquired) {
		// The context ended before acquisition, or use FailIfLocked below.
	}
	return err
}
defer func() {
	if releaseErr := lock.Close(); releaseErr != nil &&
		!errors.Is(releaseErr, pglock.ErrLockAlreadyReleased) {
		log.Printf("release %q: %v", lockKey, releaseErr)
	}
}()

// Do the exclusive work while the lock is held.
  • Acquire waits until the key is available. Use FailIfLocked() when a caller should get ErrNotAcquired immediately instead of waiting.
  • AcquireContext returns ErrNotAcquired when its context is already done or ends before acquisition. Give it a deadline when a request cannot wait indefinitely.
  • Do acquires, invokes func(context.Context, *pglock.Lock) error, cancels that callback context on heartbeat loss, and releases on return. Callback code must select on ctx.Done() around long work and must not continue externally visible side effects after losing the lock.
  • KeepOnRelease() retains the row after release. Combine it with WithData when lock metadata should survive ownership changes. Use ReplaceData() on a later acquisition when retained data must be replaced; otherwise existing data is reused.
  • Get, GetData, and GetAllLocks are inspection APIs. They do not acquire ownership and must not be used as an authorization check for protected work.
  • WithOwner makes the current process or instance visible to Get and GetAllLocks. Use a stable, non-secret identifier, not a password or token.
Show full SKILL.md (386 more words)Show less

Errors And Operations

Use errors.Is and errors.As, never error-string matching:

  • ErrNotAcquired: contention or acquisition context ended.
  • ErrLockAlreadyReleased: the lock was already released or lost; a deferred close may treat this as an expected cleanup result.
  • ErrLockNotFound and NotExistError: an inspection target is absent.
  • ErrDurationTooSmall: the heartbeat is too slow relative to the lease.
  • ErrNotPostgreSQLDriver: New received a driver other than lib/pq.
  • UnavailableError, FailedPreconditionError, and OtherError classify wrapped database failures. The client retries PostgreSQL serialization failures (SQLSTATE 40001) internally, but application work must still be idempotent if the caller chooses to retry after a returned error.

Point the client at the PostgreSQL primary, not a read replica. Every contender must reach the same database and lock table. Grant the application the DDL permissions needed for one-time setup, or run the equivalent schema.sql migration under a database owner and grant runtime DML/sequence access. Keep credentials in the application's normal secret/configuration path.

Integration Tests

At minimum, run these scenarios against a real PostgreSQL service:

  1. Two clients acquire the same key; the first owns it and a second client with FailIfLocked() receives ErrNotAcquired.
  2. Release the first lock and verify a second client can acquire the same key.
  3. Cancel or time out a waiting AcquireContext and verify it does not enter the critical section.
  4. Hold a lock longer than one heartbeat interval and verify the owner remains valid. Use a lease/heartbeat pair that keeps the test deterministic.
  5. For Do, cancel the callback context and verify the callback exits and the lock becomes available to another client.
  6. If using lock data or custom owners, read them with Get/GetData and test KeepOnRelease and ReplaceData explicitly.

Use unique trusted test table names or an isolated database, clean up with DropTable only in test teardown, and do not let parallel tests share a fixed table/key unless the contention is intentional. Run the application race detector as well, but do not treat -race without PostgreSQL as proof of distributed-lock correctness.

Bundled Resources

  • Read references/integration-guide.md for the API matrix, schema shape, and failure-mode details when the integration spans multiple components.
  • Run python3 scripts/validate_skill.py --help for the dependency-free skill validator. It emits structured JSON and never prompts.
  • Use evals/evals.json for application-level output evals and evals/trigger_queries.json for description-trigger evaluation. Keep the trigger train/validation split fixed when measuring a compatible agent client's activation rate.

© cirello-io, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 4 other files (scripts, references) in skills/pglock-integration of cirello-io/pglock.

  • SKILL.md
  • evals/evals.json
  • evals/trigger_queries.json
  • references/integration-guide.md
  • scripts/validate_skill.py

Open the folder on GitHubat commit 6d39959

Compare with similar skills

Pglock Integration next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Pglock Integration compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Pglock Integration this skillcirello-io/pglock123—~2.2kAutomated safety check: PassApache-2.0
Rust Sqlx Postgres Servicehashgraph-online/awesome-codex-plugins1.3k—~938Automated safety check: PassMIT
Database Testingpetrkindlmann/qa-skills168—~4.2kAutomated safety check: PassMIT
Airbyte Postgres Source E2E Testsairbytehq/airbyte22k—~2.5kAutomated safety check: PassCustom licence
TiDB Integration Test Recorderpingcap/tidb41k—~260Automated safety check: PassApache-2.0
Postgres CDC E2E Test Harnessairbytehq/airbyte22k—~1.9kAutomated safety check: PassCustom licence

Similar skills

  • Rust Sqlx Postgres Service

    hashgraph-online/awesome-codex-plugins

    A skill your agent uses when adding, changing, testing, or reviewing Postgres persistence in Rust services that use sqlx, especially when designing migrations, query!

    1.3k GitHub stars~938 tokensUpdated today
    Testing & QAAuto-check passed
  • Database Testing

    petrkindlmann/qa-skills

    Validate database integrity, test migrations forward and backward, verify schema constraints, manage seed data, detect migration drift, and identify query performance issues.

    168 GitHub stars~4.2k tokensUpdated 4 mo ago
    DatabasesAuto-check passed
  • Official

    Starts a local PostgreSQL 16 container, loads SQL fixtures and runs the Airbyte spec, check, discover and read commands against a chosen source-postgres image.

    22k GitHub stars~2.5k tokensUpdated today
    Testing & QAAuto-check passed
  • Use when recording TiDB integration tests under tests/integrationtest and verifying regenerated result files stay minimal and correct.

    41k GitHub stars~260 tokensUpdated today
    Testing & QAAuto-check passed
  • Official

    Reproduces PostgreSQL logical-decoding CDC behavior for Airbyte's source-postgres connector on a local backend, with CDC fixtures, a catalog and smoke case scripts.

    22k GitHub stars~1.9k tokensUpdated today
    Testing & QAAuto-check passed
  • cargo-pgrx Commands and Tests

    yugabyte/yugabyte-db

    Helps choose and run cargo-pgrx commands and decide whether a Rust test is a plain test or a pg_test, so code never crosses the Postgres boundary the wrong way.

    11k GitHub stars~1.9k tokensUpdated today
    Testing & QAAuto-check passed

Works with

Questions about Pglock Integration

What does Pglock Integration do?

A skill your agent uses when building or modifying a Go application that uses cirello.io/pglock for PostgreSQL-backed distributed locks, per-resource mutual exclusion, leader election, leases…. Pglock Integration is an agent skill from cirello-io/pglock.io/pglock for PostgreSQL-backed distributed locks, per-resource mutual exclusion, leader election, leases, heartbeats, lock metadata, or lock-aware workflows.

When should I use Pglock Integration?

Pglock Integration fits situations like: modifying a Go application that uses cirello.io/pglock for PostgreSQL-backed distributed locks; per-resource mutual exclusion; leader election; lock-aware workflows.

How do I install Pglock Integration in Claude Code?

Run `npx skills add cirello-io/pglock --skill pglock-integration -a claude-code`. Or copy the skill folder (skills/pglock-integration in cirello-io/pglock) into .claude/skills/pglock-integration in your project. Claude Code loads it when a task matches its description.

How do I install Pglock Integration in Codex?

Run `npx skills add cirello-io/pglock --skill pglock-integration -a codex`. Or copy the skill folder (skills/pglock-integration in cirello-io/pglock) into .agents/skills/pglock-integration in your project. Codex loads it when a task matches its description.

Can I use Pglock Integration in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add cirello-io/pglock --skill pglock-integration -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/pglock-integration, .gemini/skills/pglock-integration, .github/skills/pglock-integration and .opencode/skills/pglock-integration in your project.

What does Pglock Integration need to run?

Going by SKILL.md and its folder, Pglock Integration needs Python for the scripts in its folder and the command-line tools its instructions call (python3). Our summary lists: Python 3. Compatibility (from SKILL.md): Requires a Go module compatible with the selected pglock version and PostgreSQL 15 or newer. The current package declares Go 1.25.0. Integration tests need a reachable PostgreSQL primary and permission to create or migrate the lock table and sequence..

Does Pglock Integration access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Pglock Integration safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.

What licence does Pglock Integration use?

Pglock Integration is published under the Apache-2.0 licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Pglock Integration use?

About 2.2k tokens (SKILL.md is roughly 9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 1.2k tokens, read only when the agent opens those files.

What are the alternatives to Pglock Integration?

Skills that share tags, products or a category with Pglock Integration: Rust Sqlx Postgres Service (hashgraph-online/awesome-codex-plugins, 1.3k stars), Database Testing (petrkindlmann/qa-skills, 168 stars), Airbyte Postgres Source E2E Tests (airbytehq/airbyte, 22k stars) and TiDB Integration Test Recorder (pingcap/tidb, 41k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Pglock Integration?

cirello-io (a GitHub organization) maintains it in cirello-io/pglock, which has 123 GitHub stars. The repository was last updated on October 8, 2026.

Source: cirello-io/pglock on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.