Command Palette

Search for a command to run...

Назад к скиллам
скилл № 46040

PostgreSQL

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

БесплатноБез исполняемых скриптов
clawicот clawic★ 23 звезды на GitHub

Установить PostgreSQL в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

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
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • _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

Что делает скилл PostgreSQL?

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.

Как установить скилл PostgreSQL?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл PostgreSQL запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить PostgreSQL с