# Postgresql Access

> Read PostgreSQL evidence using project-local env configuration and Python Psycopg. Use to recover schema from code, verify the selected database and run narrow investigation queries; bundled helpers do not support mutations.

- Skill: `gertyhiler/postgresql-access` (Agent Skill, multi-file: 7 files)
- Install (CLI): `npx get-skill add gertyhiler/postgresql-access`
- Raw SKILL.md: https://api.skillmd.com/api/skills/gertyhiler/postgresql-access/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: gertyhiler (https://skillmd.com/u/gertyhiler)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/gertyhiler/postgresql-access

---


# PostgreSQL access

Use the consumer AGENTS.md/runbook to identify the database environment, schema
source and access policy. Read [the access contract](references/access.md) 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

1. Identify symptom, IDs, time window and intended environment. Read repository
   schema/models/migrations and query code before contacting the database.
2. 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.
3. Validate the selected env file with the config command.
   Explicit TLS modes and `uselibpqcompat=true` migration 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.
4. 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.
5. 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.
6. 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.

```sh
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.

