/major-ai-skills:postgresqlfrom major-ai-skills
Design PostgreSQL schemas, indexes, and safe online migrations; diagnose locks and slow queries with EXPLAIN; configure pooling, auth, and backup/restore without PgBouncer or invalid-index traps.
Ships in major-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
PostgreSQL is a relational database with MVCC: updates create new row versions; dead tuples remain until VACUUM. Writers never block readers on row data, but DDL and some migrations take strong locks. Connection storms are a common production failure mode—apps should pool (PgBouncer, RDS Proxy, or app pool) and cap max_connections.
App / ORM
-> PgBouncer (session vs transaction pool) OR app pool
-> Postmaster
-> backends (one per session)
-> shared_buffers + WAL
-> heap / TOAST / indexes (B-tree, GIN, GiST, BRIN)
-> autovacuum + pg_stat_statements
Use when
EXPLAIN (ANALYZE, BUFFERS)Do not use when
@clickhouse, @duckdb, @snowflake)@mongodb)(cores * 2–4) on the DB side, not “one connection per request.” Never run migrations through PgBouncer transaction pooling without session pool or direct DB URL—advisory locks break.CREATE INDEX CONCURRENTLY and DROP INDEX CONCURRENTLY cannot run inside a transaction block. One statement per migration when DDL transactions are disabled; drop invalid indexes before retry—never rely on IF NOT EXISTS after a failed concurrent build.CONCURRENTLY in prod; validate with pg_index.indisvalid.lock_timeout / statement_timeout on migration roles; expand/contract for column type changes.pg_dump). Restoring a dump to prod without rename/isolation destroys data—require explicit approval and restore targets.pg_stat_statements; correlate pg_locks, pg_stat_activity, and EXPLAIN on representative data volumes—not empty dev DBs.CREATE TABLE orders (
id bigserial PRIMARY KEY,
customer_id bigint NOT NULL REFERENCES customers(id),
status text NOT NULL,
total_cents integer NOT NULL CHECK (total_cents >= 0),
created_at timestamptz NOT NULL DEFAULT now()
);
-- Production: CONCURRENTLY, outside a transaction wrapper
DROP INDEX CONCURRENTLY IF EXISTS orders_customer_created_idx;
CREATE INDEX CONCURRENTLY orders_customer_created_idx
ON orders (customer_id, created_at DESC)
WHERE status <> 'cancelled';
WHERE id > $last LIMIT 5000) with short transactions.CONCURRENTLY index swaps as needed.postgresql://app_ro:***@db.internal:5432/app?sslmode=verify-full&connect_timeout=10&statement_timeout=30000
Migrations: use direct Postgres or PgBouncer session mode URL, not transaction pool.
EXPLAIN (ANALYZE, BUFFERS, VERBOSE)
SELECT customer_id, sum(total_cents)
FROM orders
WHERE created_at >= now() - interval '30 days'
GROUP BY customer_id;
SELECT pid, wait_event_type, wait_event, query
FROM pg_stat_activity
WHERE state <> 'idle' AND query NOT LIKE '%pg_stat_activity%';
SELECT indexrelid::regclass, indisvalid
FROM pg_index
WHERE NOT indisvalid;
| Failure signature | Root cause | Diagnostic & fix |
|---|---|---|
CREATE INDEX CONCURRENTLY cannot run inside a transaction block | ORM migration wrapped in transaction | Disable DDL transaction for that migration only; single statement |
| Migration “succeeds” but queries slow | Invalid index left after timeout | pg_index.indisvalid = false; DROP INDEX CONCURRENTLY then recreate |
ConcurrentMigrationError / stuck advisory lock | PgBouncer transaction pooling | Session pool for migrations; kill stray advisory locks |
too many connections | Unbounded app pools | PgBouncer; lower per-service pool; raise max_connections only after math |
| Rising dead tuples / bloat | Long txs / autovacuum blocked | Find blockers in pg_stat_activity; tune autovacuum; avoid long REPEATABLE READ reports |
| Seq Scan on large table | Missing or invalid index | Add partial/covering index; ANALYZE; check casts/wrappers on indexed columns |
| Restore “worked” but app broken | Restored over production or wrong timeline | Restore to new cluster/DB; repoint apps; verify extensions and roles |
pg_stat_statements for top queries; fix plans before buying bigger hardware.idle_in_transaction_session_timeout on app roles to prevent connection leaks holding locks.WHERE id > $cursor ORDER BY id LIMIT n) over large OFFSET.VALIDATE CONSTRAINT vs full table lock on add.CONCURRENTLY is permitted from your migration runner.@supabase — Postgres product surface with RLS@prisma — ORM migrations still need SQL review@redis — cache-aside in front of hot reads@vault — dynamic DB credentialsMANDATORY: Never run production DDL inside a transaction that includes
CONCURRENTLY. Never route schema migrations through PgBouncer transaction pooling without an explicit session-pool path. After any failed concurrent index build, check for invalid indexes before marking migrations complete. Do not put credentials in git or suggestsslmode=disableon untrusted networks.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub alivirgo/major-ai-skills --plugin major-ai-skills412 skills in this plugin
/3d-slicerAutomate 3D Slicer research workflows with MRML, VTK/ITK, DICOM data, and Segment Editor. Use for software workflows, not clinical interpretation./abbreviated-git-statusInspect Git branch, staging, and working-tree changes with short or porcelain status output when a compact repository check is needed./ableton-liveAutomate Ableton Live sessions with Python MIDI Remote Scripts, Max for Live, AbletonOSC, and Link synchronization./act-as-a-personal-tutorExplain a subject step by step, assess prior knowledge, and use short exercises to check understanding before advancing.Other plugins' skills for the same job