Command Palette

Search for a command to run...

Back to skills
skill № 46040

PostgreSQL

Tunes, designs, and operates PostgreSQL: slow queries, indexes, schemas, migrations, vacuum, locks, replication, backups. Use when writing Postgres SQL or…

FreeNo executable scripts
clawicby clawic★ 23 GitHub stars

Install PostgreSQL in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

About this skill

User preferences and memory live in ~/Clawic/data/pg/ (see setup.md on first use, memory-template.md for the file format). If you have data at an old location (~/pg/ or ~/clawic/pg/), move it to ~/Clawic/data/pg/, and say in one line that you moved it and from where.

When To Use

  • A query is slow, a plan needs interpretation, or an index is being ignored
  • Designing a schema: types, keys, constraints, partitions, JSONB vs columns
  • Running DDL, a migration, or a backfill against a live production table
  • Operating Postgres: connections, timeouts, vacuum, bloat, locks, replication, backups, upgrades
  • A production incident: disk full, wraparound warnings, connection storm, runaway query, suspected corruption
  • Building queue, upsert, search, or vector patterns that Postgres solves natively
  • Not for cross-engine SQL portability or ORM-level modeling (see Related Skills)

Quick Reference

Situation Play
Slow query, cause unknown Slow-Query Triage below, in order — never tune from query text alone
Plan shows a seq scan you did not expect Not automatically the bug: a scan beats an index past roughly 5-15% of the table (→ slow-queries.md)
WHERE on a function of a column Expression index matching the query text exactly (→ Indexing Essentials)
Status/flag column, minority of rows queried Partial index WHERE status = 'active'
Substring/fuzzy search (LIKE '%x%', ILIKE, typos) pg_trgm GIN index; a B-tree cannot serve a leading wildcard (→ search.md)
Word/phrase search, ranking Stored generated tsvector + GIN, queried via websearch_to_tsquery (→ search.md)
Job queue, retries, or an event outbox in Postgres SELECT ... FOR UPDATE SKIP LOCKED — no external broker needed (→ queues.md)
Insert-or-update INSERT ... ON CONFLICT ... DO UPDATE + RETURNING
First/top-N rows per group DISTINCT ON for first-row; LATERAL + matching index for top-N at scale
Deep pagination Keyset (WHERE (created_at, id) < (?, ?)), never a large OFFSET
DDL on a busy table SET lock_timeout first, then the online variant (→ Safe DDL on Busy Tables)
Query hangs with no CPU burn It is blocked: pg_blocking_pids() names the holder (→ locks.md)
Table grows on disk while row count is flat Bloat: find the oldest transaction or replication slot first (→ vacuum-bloat.md)
An error code or message to decode Error Codes below; full catalog in errors.md
Slow test suite, or a migration that needs rehearsing on real volume Transaction-per-test and template databases; rehearse on a restored copy (→ test-databases.md)
Anything else surprising EXPLAIN (ANALYZE, BUFFERS) before and after every change; if it is live and stuck, check pg_stat_activity for a blocker before touching anything

Depth on demand, by phase:

  • Diagnose — slow-queries.md plan reading and misestimates · locks.md blocked queries and deadlocks · errors.md SQLSTATE to cause · monitoring.md what to watch and alert on · incidents.md disk full, wraparound, runaway query, corruption
  • Design — schema-design.md types, keys, constraints · indexing.md index types and when each wins · partitioning.md tables too big for one heap · json.md JSONB modeling and indexing · search.md text, fuzzy, and vector search · queues.md job queues, retries, transactional outbox
  • Change — migrations.md online DDL, backfills, expand/contract · bulk-load.md loading millions of rows · upgrades.md major versions, OS/glibc, extensions · functions-triggers.md plpgsql, triggers, LISTEN/NOTIFY · test-databases.md fast test isolation, anonymized copies, CI, rehearsals
  • Operate — connections.md pooling and PgBouncer · vacuum-bloat.md autovacuum tuning and reclaim · tuning.md postgresql.conf memory, WAL, planner · backup-restore.md dumps, PITR, restore drills · replication.md replicas, lag, failover · security.md roles, grants, RLS, pg_hba · managed-postgres.md RDS, Aurora, Cloud SQL, Neon, Supabase · psql.md client workflow and scripting · extensions.md which extension solves this

Core Rules

  1. Tune from a plan, never from query text. EXPLAIN (ANALYZE, BUFFERS); plain EXPLAIN prints estimates and the estimate is usually the bug. Check: estimated vs actual rows per node — off by more than 10x means a statistics problem, not a missing index.
  2. Index every foreign key column you join or cascade on. Postgres indexes primary keys and unique constraints automatically, never FK columns. A parent DELETE of 10k rows against an unindexed 50M-row child is 10k sequential scans.
  3. Composite index order: equality columns first, then one range or sort column. (tenant_id, created_at) answers WHERE tenant_id = ? ORDER BY created_at DESC LIMIT 20 from the first 20 index entries; (created_at, tenant_id) walks every row in date order filtering as it goes, and gets slower as the tenant gets s
Full SKILL.md on GitHub

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

Bundled files

  • _meta.json
  • backup-restore.md
  • bulk-load.md
  • connections.md
  • errors.md
  • extensions.md
  • functions-triggers.md
  • incidents.md
  • indexing.md
  • json.md
  • locks.md
  • managed-postgres.md
  • memory-template.md
  • migrations.md
  • monitoring.md
  • partitioning.md
  • psql.md
  • queues.md
  • replication.md
  • schema-design.md
  • search.md
  • security.md
  • setup.md
  • slow-queries.md
  • test-databases.md
  • tuning.md
  • upgrades.md
  • vacuum-bloat.md

FAQ

What does the PostgreSQL skill do?

Tunes, designs, and operates PostgreSQL: slow queries, indexes, schemas, migrations, vacuum, locks, replication, backups. Use when writing Postgres SQL or psql, designing tables and indexes, reading an EXPLAIN plan, running DDL or a migration against a live table, or when a query suddenly got slow, a table keeps growing while rows stay flat, autovacuum cannot keep up, "too many clients already" appears, a replica lags, deadlocks and lock waits pile up, pg_wal fills the disk, or an upgrade, a restore, or a partitioning plan is on the table. Covers connection pooling and PgBouncer, full-text, trigram and pgvector search, JSONB, roles and row-level security, PITR, extensions, and managed Postgres (RDS, Aurora, Cloud SQL, Neon, Supabase). Not for cross-engine SQL portability or ORM-level modeling.

How do I install the PostgreSQL skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the PostgreSQL skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare PostgreSQL with