Postgres intelligence
Skill cskwork/postgres-intelligence/skills/postgres-intelligence
PostgreSQL for LLM agents: inspect schemas, run safe SQL, translate natural language to queries. Use when connecting to a PostgreSQL database, exploring an unfamiliar schema, debugging a SQL error, or investigating query performance.From its SKILL.md
npx -y skills add cskwork/postgres-intelligence --skill postgres-intelligenceAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
4.2 KB, as published. Nobody here has run it
postgres-intelligence
Credential-safe PostgreSQL access for LLM coding agents. The scripts load credentials from .env at runtime and print only safe summaries, schema metadata, query results, and errors. The agent writes SQL, calls the scripts, and reads that output; it never opens or prints .env itself.
Install
.env, scripts/, and schema_metadata.json all live in the skill directory. Run every command in this file from there.
cd postgres-intelligence # repo root
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -r requirements.txt
cd skills/postgres-intelligence # the skill directory
cp ../../.env.example .env
python scripts/config.py
python scripts/db_connector.py
python scripts/schema_extractor.py
Configure
Fill .env from the keys in ../../.env.example, the public template: connections DB1_ through DB10_, or DB1_DSN, which takes precedence over the host/port fields. DB*_NAME is the connection key --db expects. Keep real .env, .venv, and schema_metadata.json out of git.
Commands
# Validate loaded config; prints host, user, and database, never passwords or DSNs
python scripts/config.py
# Test all configured connections
python scripts/db_connector.py
# Extract schema metadata for every connection into schema_metadata.json
python scripts/schema_extractor.py
# Run a read-only query against the default connection
python scripts/query_executor.py "SELECT current_database(), current_schema();"
# Select a named connection
python scripts/query_executor.py --db analytics "SELECT count(*) FROM public.events;"
# Agent-friendly JSON output
python scripts/query_executor.py --json-only "SELECT now();"
# Raise the 30000 ms statement_timeout for a long analytical query
python scripts/query_executor.py --statement-timeout-ms 120000 "SELECT count(*) FROM public.events;"
# Writes require explicit user approval
python scripts/query_executor.py --allow-write "UPDATE table_name SET flag = true WHERE id = 1;"
# DDL requires explicit user approval
python scripts/query_executor.py --allow-ddl "CREATE INDEX CONCURRENTLY idx_name ON table_name (col);"
Agent Workflow
- Identify the target connection, schema, table, time range, and result limit.
- Run
python scripts/config.pyto confirm the connection is configured; it validates.envwithout printing secrets. - Read
schema_metadata.jsonin the skill directory before generating SQL; if it is absent or stale, runpython scripts/schema_extractor.pyto rewrite it. - If the target table is still missing from that metadata, query
information_schemaorpg_catalogfor it first. - Prefer explicit columns over
SELECT *; addLIMITfor exploratory reads. - On errors, use
sqlstateand suggestions to refine the query, with a maximum of three attempts. - Report the executed SQL, key rows, row count, and reasoning. Do not report credentials.
Safety Model
- Read-only by default:
SELECT,WITH,SHOW, andEXPLAINrun with no flag. - Writes require
--allow-write. - DDL and maintenance commands require
--allow-ddl. UPDATEandDELETEwithoutWHEREare blocked.- Multiple SQL statements in one call are blocked.
- Every query runs under a
statement_timeoutof 30000 ms unless--statement-timeout-msraises it. - Passwords and full DSNs are never printed.
PostgreSQL Guidance
- Use
EXPLAIN (ANALYZE, BUFFERS)for performance work. - Verify index usage before and after adding indexes.
- Use
CREATE INDEX CONCURRENTLYfor large production tables when appropriate. - Run
ANALYZEafter bulk data changes. - Use B-tree for common equality/range access, GIN for JSONB containment and full-text patterns, BRIN for large append-only time-series tables.
- Use connection pooling such as PgBouncer for long-running applications; agent scripts are short-lived.
Read ../../references/postgres_best_practices.md before recommending an index, a partitioning or schema change, or a maintenance job.