用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/Dev-Toolbelt/dev-team-agents --skill postgres命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | postgres |
| description | PostgreSQL — MVCC, indexes, partitioning, JSONB, query tuning. |
Load when the project uses PostgreSQL (signal: pg, psycopg2, postgres: in docker-compose, DATABASE_URL with postgres://, prisma with postgresql provider).
psql "$DATABASE_URL"
# or with individual vars:
PGPASSWORD="$DB_PASSWORD" psql -h "$DB_HOST" -p "${DB_PORT:-5432}" -U "$DB_USER" -d "$DB_NAME"
# Supabase local dev:
psql "postgresql://postgres:postgres@localhost:54322/postgres"
Key inspection commands:
psql -c "\d+ table_name" # table structure + storage info
psql -c "EXPLAIN (ANALYZE, BUFFERS) SELECT ..."
psql -c "SELECT * FROM pg_stat_user_tables ORDER BY n_dead_tup DESC;"
psql -c "SELECT * FROM pg_stat_activity WHERE state = 'active';"
| Isolation level | Default | Prevents |
|---|---|---|
| Read Committed | ✅ PostgreSQL default | Dirty reads |
| Repeatable Read | — | Non-repeatable reads |
| Serializable | — | Phantom reads |
VACUUMSELECT relname, n_dead_tup FROM pg_stat_user_tables ORDER BY n_dead_tup DESC| Type | Use when |
|---|---|
| B-tree (default) | Equality and range queries on orderable types |
| GIN | Full-text search; JSONB containment (@>); array overlap |
| GiST | Geometric types; range types; nearest-neighbour |
| BRIN | Append-only large tables with sequential correlation (e.g., time series) |
| Hash | Equality-only; rarely preferred over B-tree |
| Partial | Index a subset of rows: CREATE INDEX ON orders(user_id) WHERE status = 'active' |
jsonb (binary storage, indexable, operators) over json (text storage, preserved order)jsonb: CREATE INDEX ON table USING GIN (col) for @> and ? operators| Type | Best for |
|---|---|
| Range | Time series (partition by month/year) |
| List | Enum-like values (region, status) |
| Hash | Even distribution without natural range |
Use pg_partman for automated range partition creation. Always include the partition key in queries to enable partition pruning.
WITH MATERIALIZED (>= 12) or NOT MATERIALIZEDEXPLAIN (ANALYZE, BUFFERS) is mandatory before merging slow queriesSeq Scan on large tables, Rows Removed by Filter, high Buffers hit/read ratio| Gotcha | Fix |
|---|---|
LIKE '%term%' can't use B-tree | Use pg_trgm extension + GIN index |
OFFSET n scans all preceding rows | Use keyset pagination: WHERE id > :last_id |
COUNT(*) is expensive on large tables | Use pg_stat_user_tables.n_live_tup for estimates |
CURRENT_TIMESTAMP vs NOW() | Same within a transaction; clock_timestamp() changes mid-transaction |
| UUID as PK causes index fragmentation | Use gen_random_uuid() (UUIDv4) or UUIDv7 for sequential behaviour |
| Extension | Purpose |
|---|---|
pg_trgm | Trigram similarity for fuzzy search and LIKE index |
pgcrypto | gen_random_uuid(), encryption functions |
uuid-ossp | Alternative UUID generation |
pg_stat_statements | Track slow query statistics |
timescaledb | Time-series optimizations |
PostGIS | Spatial data and geospatial queries |