Postgres intelligence
PostgreSQL intelligence skill for Claude Code, Codex, Cursor, Windsurf, and local LLM agents
npx -y skills add cskwork/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
- 0 stars0 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.
What its author says it does
Copied from the file, not written here
Use when an LLM agent needs to connect to PostgreSQL, inspect schemas, run safe SQL, translate natural language into PostgreSQL queries, or analyze query performance without exposing credentials.
The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
4.4 KB, 908 tokens by cl100k_base, as published. Nobody here has run it
postgres-intelligence
PostgreSQL intelligence for LLM coding agents. It gives Claude Code, Codex, and other local agents a credential-safe way to discover PostgreSQL schemas, run read-first SQL, inspect query errors, and reason about performance.
The core rule is simple: the agent should not open or print .env directly. Scripts load credentials at runtime, and the agent only sees safe summaries, query results, and metadata.
What It Does
- Loads one or more PostgreSQL connections from
.envusingDB1_...DB10_.... - Tests connectivity without printing passwords or full DSNs.
- Extracts schema metadata from
information_schemaandpg_catalog. - Executes read-only SQL by default:
SELECT,WITH,SHOW, andEXPLAIN. - Blocks writes and DDL unless explicit flags are passed after user approval.
- Returns structured JSON that any LLM agent can parse.
- Provides PostgreSQL-specific guidance for indexes, JSONB,
EXPLAIN, and maintenance.
Install
cd postgres-intelligence
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -r requirements.txt
cp .env.example .env
python scripts/config.py
python scripts/db_connector.py
python scripts/schema_extractor.py
Use .env.example as the public template. Keep real .env, .venv, and schema_metadata.json out of git.
Configure
DB1_HOST=localhost
DB1_PORT=5432
DB1_USER=your_username
DB1_PASSWORD=your_password
DB1_DATABASE=your_database
DB1_NAME=primary
DB1_SSLMODE=prefer
DB1_CONNECT_TIMEOUT=10
DB1_APPLICATION_NAME=postgres-intelligence
Use DB*_NAME as the connection key for --db.
Commands
# Validate loaded config without printing secrets
python scripts/config.py
# Test all configured connections
python scripts/db_connector.py
# Extract schema metadata
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();"
# 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.
- Confirm
.envexists, but do not open or print it. - Load or refresh
schema_metadata.jsonbefore generating SQL. - If schema context is missing, query
information_schemaorpg_catalogfirst. - 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
- The agent generates SQL and calls scripts.
- Scripts load credentials from
.env. - Passwords and full DSNs are never printed.
UPDATEandDELETEwithoutWHEREare blocked.- Multiple SQL statements in one call are blocked.
- DDL and maintenance commands require
--allow-ddl. - Writes require
--allow-write.
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 only when deeper PostgreSQL-specific guidance is needed.