Help us improve
Share bugs, ideas, or general feedback.
From pgtool
PostgreSQL database exploration and debugging. Use when user asks to explore database schemas, tables, columns, or run queries. Requires a `.pgtool.json` file in the project directory.
npx claudepluginhub joshuarweaver/cascade-ai-ml-agents-misc-2 --plugin thilinatlm-agent-skillsHow this skill is triggered — by the user, by Claude, or both
Slash command
/pgtool:pgtoolThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
A CLI tool for exploring and debugging PostgreSQL databases with JSON-first output designed for AI agents.
SETUP.mdscripts/pgtool-cli/bun.lockscripts/pgtool-cli/package.jsonscripts/pgtool-cli/pgtoolscripts/pgtool-cli/pgtool.ps1scripts/pgtool-cli/src/commands/constraints.tsscripts/pgtool-cli/src/commands/count.tsscripts/pgtool-cli/src/commands/describe.tsscripts/pgtool-cli/src/commands/explain.tsscripts/pgtool-cli/src/commands/indexes.tsscripts/pgtool-cli/src/commands/overview.tsscripts/pgtool-cli/src/commands/query.tsscripts/pgtool-cli/src/commands/relationships.tsscripts/pgtool-cli/src/commands/sample.tsscripts/pgtool-cli/src/commands/schemas.tsscripts/pgtool-cli/src/commands/search.tsscripts/pgtool-cli/src/commands/tables.tsscripts/pgtool-cli/src/index.tsscripts/pgtool-cli/src/lib/config.tsscripts/pgtool-cli/src/lib/connection.tsPostgreSQL 16+ reference for writing SQL queries (SELECT, CTEs, windows), designing schemas, creating indexes (B-tree, GIN), managing transactions, using JSONB, analyzing with EXPLAIN ANALYZE, and psql CLI.
Guides PostgreSQL operations: schema design, index selection (B-tree/GIN/GiST/BRIN), query tuning (EXPLAIN ANALYZE), backups (pg_dump/pg_basebackup), replication, vacuum tuning, monitoring (pg_stat_statements), RLS, extensions (PostGIS/timescaledb).
Reference for PostgreSQL query optimization, schema design, indexing strategies, and Row Level Security. Based on Supabase best practices.
Share bugs, ideas, or general feedback.
A CLI tool for exploring and debugging PostgreSQL databases with JSON-first output designed for AI agents.
The CLI is located at ./scripts/pgtool-cli/ relative to this SKILL.md file.
| Platform | Script |
|---|---|
| Unix/Linux/macOS | pgtool |
| Windows | pgtool.ps1 |
Claude Code: Use ${CLAUDE_PLUGIN_ROOT}/skills/pgtool/scripts/pgtool-cli/pgtool (or pgtool.ps1 on Windows).
For setup instructions, see SETUP.md in this directory.
psql directly.LIMIT to SELECT queries to avoid fetching excessive data.pgtool schemas
Output: {"ok":true,"schemas":[{"name":"public","owner":"postgres"}]}
# Tables in default schema
pgtool tables
# Tables in a specific schema
pgtool tables auth
Output: {"ok":true,"schema":"public","tables":[{"name":"users","type":"table","rowEstimate":1000,"sizeHuman":"256 KB"}]}
Get column details with primary key and foreign key information.
# Table in default schema
pgtool describe users
# Table in specific schema
pgtool describe auth.users
Output includes column types, nullability, defaults, PK/FK info, and foreign key references.
pgtool indexes users
Output: {"ok":true,"indexes":[{"name":"users_pkey","unique":true,"primary":true,"columns":["id"],"type":"btree"}]}
pgtool constraints users
Output includes PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, and EXCLUDE constraints.
Get all foreign key relationships in a schema.
pgtool relationships
pgtool relationships auth
Output: {"ok":true,"relationships":[{"fromTable":"orders","fromColumns":["user_id"],"toTable":"users","toColumns":["id"]}]}
pgtool query "SELECT * FROM users WHERE active = true LIMIT 100"
Output: {"ok":true,"rows":[...],"rowCount":5,"fields":["id","name","email"]}
Best Practices:
LIMIT to SELECT queries to avoid fetching excessive dataGet sample data from a table quickly.
# Default: 5 rows
pgtool sample users
# Custom limit
pgtool sample users --limit 10
# Specific schema
pgtool sample auth.users
Output: {"ok":true,"schema":"public","table":"users","rows":[...],"rowCount":5,"columns":["id","name","email"]}
Get exact row count (not estimate).
pgtool count users
pgtool count auth.sessions
Output: {"ok":true,"schema":"public","table":"users","count":12345}
Plain: public.users: 12,345 rows
Find tables and columns matching a pattern.
pgtool search email
pgtool search user
Output:
{
"ok": true,
"pattern": "email",
"matches": {
"tables": [{ "schema": "public", "name": "emails" }],
"columns": [
{
"schema": "public",
"table": "users",
"column": "email",
"type": "varchar(255)"
},
{
"schema": "public",
"table": "contacts",
"column": "email_address",
"type": "text"
}
]
}
}
Compact ERD-like view showing tables, primary keys, and relationships.
pgtool overview
pgtool overview auth
Output (plain):
Schema: public (3 tables)
users (1.2k rows)
PK: id
→ orders.user_id, profiles.user_id
orders (45k rows)
PK: id
FK: user_id → users.id
→ order_items.order_id
products (500 rows)
PK: id
Analyze query execution plan.
# With ANALYZE (executes query)
pgtool explain "SELECT * FROM users WHERE email = 'x'"
# Without ANALYZE (plan only)
pgtool explain "SELECT * FROM users WHERE id = 1" --no-analyze
Output: {"ok":true,"query":"SELECT...","plan":["Seq Scan on users...","..."]}
All errors follow a consistent JSON format with ok: false, an error code, and a helpful hint:
Configuration not found:
{
"ok": false,
"error": "Configuration file not found",
"code": "CONFIG_NOT_FOUND",
"hint": "Create a .pgtool.json file in your project root with database connection details."
}
Connection failed:
{
"ok": false,
"error": "Could not connect to database server: connect ECONNREFUSED 127.0.0.1:5432",
"code": "CONNECTION_FAILED",
"hint": "Verify host and port in .pgtool.json and ensure PostgreSQL is running"
}
Authentication failed:
{
"ok": false,
"error": "Authentication failed",
"code": "PERMISSION_DENIED",
"hint": "Check your username and password in .pgtool.json"
}
Table not found:
{
"ok": false,
"error": "relation \"nonexistent_table\" does not exist",
"code": "TABLE_NOT_FOUND",
"hint": "Check that the table exists and you have permission to access it"
}
Error codes: CONFIG_NOT_FOUND, CONFIG_INVALID, CONNECTION_FAILED, QUERY_FAILED, TABLE_NOT_FOUND, SCHEMA_NOT_FOUND, PERMISSION_DENIED, TIMEOUT
Exploring a new database:
pgtool schemas - See available schemaspgtool overview - Quick view of tables and relationshipspgtool tables <schema> - List tables with sizespgtool describe <table> - Understand table structurespgtool sample <table> - See example dataFinding data:
pgtool search <pattern> - Find tables/columns by namepgtool sample <table> - Quick data previewpgtool count <table> - Get exact row countpgtool query "SELECT..." - Custom queriesDebugging data issues:
pgtool describe <table> - Verify column typespgtool sample <table> - Check actual datapgtool explain "SELECT..." - Analyze query performancepgtool indexes <table> - Check index coverageUnderstanding relationships:
pgtool overview - Visual relationship mappgtool relationships - Get all FK relationshipspgtool constraints <table> - See specific table constraints