PostgreSQL access
Use the consumer AGENTS.md/runbook to identify the database environment, schema
source and access policy. Read the access contract before
first use. Load .agents/local/.env.agents as data, never through shell source.
Do not print env files, full DSNs, passwords or raw authentication errors.
Schema-first sequence
- Identify symptom, IDs, time window and intended environment. Read repository schema/models/migrations and query code before contacting the database.
- Decide which evidence requires a live read. Do not dump the catalog when code already provides the relevant schema. Runtime-only objects or schema drift justify targeted catalog inspection.
- Validate the selected env file with the config command.
Explicit TLS modes and
uselibpqcompat=truemigration are documented in the access contract; do not rewrite credentials or silently switch runners. Verify connection; compare database/user metadata with the project's intended environment. Stop on an environment mismatch. Use the safe error category to distinguish a configuration, TLS, network, authentication or SQL problem; do not switch env files/runners or weaken an explicitly requested TLS mode. - Draft a narrow SELECT from known columns and IDs, bounded by LIMIT/time range. Inspect suspiciously expensive reads with plain EXPLAIN, not EXPLAIN ANALYZE. Avoid invoking unfamiliar functions: even SELECT can trigger side effects.
- Execute through the read-only helper. Report query, retrieval time and relevant rows, distinguishing current state from persisted event history. Current data cannot establish the full historical sequence on its own.
- Cross-check with code and logs when needed. If mutation is necessary, describe it separately and use the project's authorized mutation workflow. This helper has no write override, even when credentials are more privileged.
Commands
Install uv once. Run from the consumer checkout; set skill_dir to the installed
location. Python 3.12+ and pinned dependencies are resolved in an isolated uv
environment. No application dependency or Node runtime is required. Keep the
whole skill folder, including the script lockfile and catalog SQL.
skill_dir=.agents/skills/postgresql-access
uv run --locked "$skill_dir/scripts/postgres.py" config
uv run --locked "$skill_dir/scripts/postgres.py" check
uv run --locked "$skill_dir/scripts/postgres.py" query --sql 'SELECT current_timestamp;'
uv run --locked "$skill_dir/scripts/postgres.py" query --file .agents/local/evidence/query.sql
Each accepts --env-file PATH; URL/PG* fields and Prisma schema are supported.
The env file is sufficient for supported connection and certificate settings.
Without an explicit TLS mode, libpq prefer permits non-TLS servers; use explicit
verify-full and CA settings when authenticated TLS is required. check reports
the actual TLS and read-only state. postgres.py schema reads catalog columns
when necessary; it is not a DDL/backup exporter. --output PATH creates a new
private file rather than overwriting existing evidence. Query output may contain
personal data: select only required fields and redact before publication.
The runner uses a read-only transaction and the extended query protocol (one SQL statement), with bounded connection/query timeouts. Its conservative keyword filter can reject harmless SQL containing write-related words. It is not a SQL sandbox: use a least-privileged read-only role and do not call side-effecting functions. Do not weaken restrictions to make an investigation query pass.