postgresql-table-design
Design or review a PostgreSQL-specific schema: data types, indexing, constraints, partitioning, RLS, performance patterns, and advanced features
- License 许可
- MIT
- 所属仓库
- HigorAlves/orc
- 最近更新
- 2026-11-07
- Stars
- ★ 7
- Forks
- 0
01 前言 Front Matter
- name
- postgresql-table-design
- description
- Design or review a PostgreSQL-specific schema: data types, indexing, constraints, partitioning, RLS, performance patterns, and advanced features
- when_to_use
- Use when modeling or auditing PG tables.
02 资源文件 5
- 参考文档references/DATA-TYPES.md4.5 KB
- 参考文档references/EXAMPLES.md1003 B
- 参考文档references/INDEXING-CONSTRAINTS-PARTITIONING.md3.6 KB
- 参考文档references/JSONB.md1.4 KB
- 参考文档references/WORKLOAD-PATTERNS.md3.2 KB
03 SKILL.md 正文
PostgreSQL Table Design
This SKILL.md is a thin index — the Core Rules and Gotchas below cover most design/review calls; Read the relevant references/*.md on demand for the rest, never all up front.
Core Rules
- Define a PRIMARY KEY for reference tables (users, orders, etc.). Not always needed for time-series/event/log data. When used, prefer
BIGINT GENERATED ALWAYS AS IDENTITY; useUUIDonly when global uniqueness/opacity is needed. - Normalize first (to 3NF) to eliminate data redundancy and update anomalies; denormalize only for measured, high-ROI reads where join performance is proven problematic. Premature denormalization creates maintenance burden.
- Add NOT NULL everywhere it's semantically required; use DEFAULTs for common values.
- Create indexes for access paths you actually query: PK/unique (auto), FK columns (manual!), frequent filters/sorts, and join keys.
- Prefer TIMESTAMPTZ for event time; NUMERIC for money; TEXT for strings; BIGINT for integer values, DOUBLE PRECISION for floats (or
NUMERICfor exact decimal arithmetic).
PostgreSQL "Gotchas"
- Identifiers: unquoted → lowercased. Avoid quoted/mixed-case names. Convention:
snake_casefor table/column names. - Unique + NULLs: UNIQUE allows multiple NULLs. Use
UNIQUE (...) NULLS NOT DISTINCT(PG15+) to restrict to one NULL. - FK indexes: PostgreSQL does not auto-index FK columns. Add them.
- No silent coercions: length/precision overflows error out (no truncation).
- Sequences/identity have gaps (normal; don't "fix").
- Heap storage: no clustered PK by default;
CLUSTERis one-off, not maintained. - MVCC: updates/deletes leave dead tuples; vacuum handles them — design to avoid hot wide-row churn.
Detail map (read on demand)
| Question | Reference |
|---|---|
Which type for X? Banned types (char(n), money, timestamp w/o tz, serial)? Table types, generated columns |
DATA-TYPES.md |
| RLS, constraint shapes, which index kind (B-tree/GIN/GiST/BRIN, partial, covering), when to partition | INDEXING-CONSTRAINTS-PARTITIONING.md |
| Update-heavy / insert-heavy / upsert designs, safe schema evolution, useful extensions | WORKLOAD-PATTERNS.md |
| JSONB vs columns, indexing JSONB | JSONB.md |
| Worked schemas (users, orders, JSONB) | EXAMPLES.md |
For query-side work (JSONB operators, window functions, full-text search, PG-unique SQL) use orc-postgresql-optimization instead.
04 同仓库更多 Skills
writing-plans
Write a comprehensive implementation plan of bite-sized TDD tasks that an engineer with zero codebase context could execute — exact files, code, tests, and verification steps
writing-for-agents
orc's doctrine layer for writing any document an agent consumes — skills, AGENTS.md/CLAUDE.md, reference docs
workspace-mode
Use when cwd is a parent dir holding multiple sibling git repos — defines repo auto-detection, --repos/--repo/--all-repos/--this-repo precedence, per-repo dispatch, and linked-PR mechanics.
wizard
Generate an interactive bash wizard walking a human through work only they can perform — credentials, secrets, one-off migrations
wait-what
Stop and re-pitch — the last message did not land; say it again simply, in the project's own vocabulary.
vitest
Vitest fast unit testing framework powered by Vite with Jest-compatible API