postgres
Skill1 starsChanged 7 months agoMITView on GitHub
Use when user references PostgreSQL/Postgres, postgres:// or postgresql:// connection strings, asks for ad-hoc SELECT, EXPLAIN/ANALYZE plans, schema/index/lock inspection, or slow-query investigation. Read-only by default. Multi-database via PG_PROFILE.
15 other projects use a version of this.
Adopted by
Most recently taken up by
- fworks-tech/agenthoodtheir own version, first seen Sep 28, 2026
- nahid-sparktales/agent-dispatchertheir own version, first seen Sep 21, 2026
- timescale/pg-aiguidetheir own version, first seen Sep 2, 2026
- chenwei791129/agent-skillstheir own version, first seen Aug 29, 2026
- LDKTC/Agent-P-FullStacktheir own version, first seen Jul 31, 2026
- magnus919/agent-skillstheir own version, first seen Jul 21, 2026
Used with
Projects with it also use mysql and deep-research.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
planetscaleSkillmysql
Plan and review MySQL/InnoDB schema, indexing, query tuning, transactions, and operations. Use when creating or modifying MySQL tables, indexes, or queries; diagnosing slow/locking behavior; planning migrations; or troubleshooting replication and connection issues. Load when using a MySQL database.
Also in 4 projects that use this
NVIDIASkilldeep-research
Queue deep, multi-step research and analysis tasks to the DeepAgents worker. Supports execution depth presets, request-specific rubrics, SubAgent delegation, and RubricMiddleware cross-validation.
Also in 3 projects that use this
Other versions15 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 15
- timescale/pg-aiguide★ 1.9ksame name
- planetscale/database-skills★ 692same name
- sanjay3290/ai-skills★ 429same name
- magnus919/agent-skills★ 109same name
- damusix/skills★ 62same name
- nahid-sparktales/agent-dispatcher★ 59same name
- digitalocean-labs/do-app-platform-skills★ 36same name
- nimadorostkar/Claude-Skills-collection★ 28same name
- mamamou/ai-coding-skills★ 16same name
- qhkm/zeptoclaw-skills★ 4same name
5 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository16 other files it gives its agents.
- azure-devopsSkill
- fastlaneSkill
- firebaseSkill
- herokuSkill
- k6Skill
- linearSkill
- maestroSkill
- profiles-and-credentialsSkill
- rails-securitySkill
- react-nativeSkill
- rspecSkill
- sentrySkill
- shopifySkill
- slackSkill
- trelloSkill
- xlsx-testcasesSkill
The file
Files
/postgres — read-mostly DB ops (multi-database)
Wraps psql. Read-only by default; mutating SQL requires --write + typed confirm.
Profile resolution: --profile → PG_PROFILE → ~/.postgres/active_profile → [default].
Overview
Wraps psql with read-only-by-default safety. Mutating SQL requires explicit --write flag plus typed database name confirmation. Profile-level read_only=true hard-refuses writes even with the flag (defense-in-depth).
When to Use
- Ad-hoc SELECT queries against dev/staging/prod
- EXPLAIN plans for slow queries
- Schema / index / lock inspection during incidents
- Identifying slow queries via
pg_stat_statements - Killing stuck backends (with
--force+ typedKILL)
When NOT to Use
- Application data writes → that's the app, not this skill
- Migrations → use Rails / Alembic / Flyway with version control
- Bulk data exports →
pg_dumporCOPYdirectly - Cross-database queries → use FDW or app-side joins
Profile config
~/.postgres/credentials (mode 600):
[default]
host = localhost
port = 5432
database = myapp_development
user = postgres
password = postgres
sslmode = prefer
[prod]
host = prod-db.example.com
database = myapp_production
user = readonly_user # defense-in-depth: physical RO at DB level
password = xxxxxxxxxxxxxx
sslmode = verify-full # min `require` for non-localhost
read_only = true # hard refuse writes even with --write
require_confirm = trueSSL modes: disable (local only), prefer, require (min for remote), verify-ca, verify-full (strongest).
Why readonly_user: defense-in-depth. Skill is read-only by default but DB-level grants prevent accidents even if skill is bypassed.
Helpers
Shared profile/INI/
ctt_*pattern reference: profiles-and-credentials.
source "$HOME/.claude-team-toolkit/lib/credentials.sh"
source "$HOME/.claude-team-toolkit/lib/confirm.sh"
ctt_load_creds postgres "$PROFILE"
pg_run() {
PGPASSWORD="$CTT_PASSWORD" psql \
--host "$CTT_HOST" --port "${CTT_PORT:-5432}" \
--dbname "$CTT_DATABASE" --username "$CTT_USER" \
--set "sslmode=${CTT_SSLMODE:-prefer}" --no-password "$@"
}
is_mutating_sql() {
echo "$1" | tr '[:upper:]' '[:lower:]' | tr -s '[:space:]' ' ' \
| grep -qE '\b(insert|update|delete|drop|truncate|alter|grant|revoke|create|copy|vacuum|reindex)\b'
}
# Identifier validation: prevent SQL injection in unquoted contexts
valid_ident() {
case "$1" in ''|*[!a-zA-Z0-9_]*) return 1 ;; *) return 0 ;; esac
}Dispatch
query <sql> — execute (read-only by default)
SQL="$1"; WRITE="${WRITE:-false}"
if is_mutating_sql "$SQL"; then
[ "$WRITE" != "true" ] && { echo "Mutating SQL detected. Re-run with --write." >&2; return 1; }
[ "$CTT_READ_ONLY" = "true" ] && { echo "Profile $CTT_PROFILE is read_only. Refusing." >&2; return 1; }
ctt_warn_destructive "Mutating SQL on $CTT_DATABASE@$CTT_HOST ($CTT_PROFILE)"
ctt_confirm "Type the database name '$CTT_DATABASE' to confirm:" "$CTT_DATABASE" || return 1
fi
pg_run -c "$SQL"
[ "$WRITE" = "true" ] && ctt_audit_log postgres "MUTATE: ${SQL:0:100}"explain <sql> — query plan
pg_run -c "EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) $SQL"Drop ANALYZE to see plan without running query.
schema <table> — describe a table (validate identifier)
valid_ident "$TABLE" || { echo "Invalid table name: $TABLE" >&2; return 1; }
pg_run -v t="$TABLE" -c "\d+ :\"t\""tables [--schema name] — list tables with sizes
SCHEMA="${SCHEMA:-public}"
valid_ident "$SCHEMA" || { echo "Invalid schema: $SCHEMA" >&2; return 1; }
pg_run -v schema="$SCHEMA" -c "
SELECT c.relname AS table,
pg_size_pretty(pg_total_relation_size(c.oid)) AS size,
c.reltuples::bigint AS approx_rows
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind = 'r' AND n.nspname = :'schema'
ORDER BY pg_total_relation_size(c.oid) DESC LIMIT 50;"indexes <table> — list indexes + usage stats
valid_ident "$TABLE" || return 1
pg_run -v t="$TABLE" -c "
SELECT i.relname AS index,
pg_size_pretty(pg_relation_size(i.oid)) AS size,
s.idx_scan AS scans, s.idx_tup_read AS reads
FROM pg_class i
JOIN pg_index ix ON i.oid = ix.indexrelid
JOIN pg_class t ON t.oid = ix.indrelid
LEFT JOIN pg_stat_user_indexes s ON s.indexrelid = i.oid
WHERE t.relname = :'t' ORDER BY i.relname;"scans=0 after weeks = removal candidate.
locks — current locks (debug hangs)
pg_run -c "
SELECT pid, usename, state, wait_event_type, wait_event,
query_start, now() - query_start AS duration, left(query, 80) AS query
FROM pg_stat_activity
WHERE state != 'idle' AND pid != pg_backend_pid()
ORDER BY query_start;"kill <pid> — terminate backend (require --force)
[ "$FORCE" != "true" ] && { echo "Add --force flag" >&2; return 1; }
case "$PID" in ''|*[!0-9]*) echo "PID must be numeric" >&2; return 1 ;; esac
ctt_confirm "Type KILL to confirm:" "KILL" || return 1
pg_run -v pid="$PID" -c "SELECT pg_terminate_backend(:'pid'::int);"
ctt_audit_log postgres "killed pid $PID"slow [--limit N] — slowest queries (requires pg_stat_statements)
pg_run -c "
SELECT round(mean_exec_time::numeric, 2) AS avg_ms,
calls, round((total_exec_time/1000)::numeric, 1) AS total_sec,
left(query, 100) AS query
FROM pg_stat_statements
ORDER BY mean_exec_time DESC LIMIT ${LIMIT:-20};"Common Mistakes
- Using
EXPLAIN ANALYZEon expensive queries → it actually runs them. PlainEXPLAINfirst. sslmode=disablefor non-localhost → MITM risk. Minrequirefor remote.- Connecting as superuser when
readonly_userworks → blast radius huge on accidents - Running mutations without
--write→ skill refuses (this is correct behavior) - Killing a backend without checking
pg_stat_activityfirst → can break replication - "connection refused" → check
host,port, firewall,sslmodein profile
Safety
- Read-only by default: mutating keywords need
--writeflag explicitly. read_only=trueprofile flag: hard refuse even with--write.- Use a readonly DB user for staging/prod (defense-in-depth).
PGPASSWORDenv, not command line — process listing won't show password.sslmode=requireminimum for non-localhost.- EXPLAIN ANALYZE runs the query — use plain
EXPLAINfirst for expensive scans. - Audit log truncates SQL to 100 chars to avoid logging sensitive payloads.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

