design-postgres-tables

仓库创建 2025年7月24日最近提交 1 个月前SkillHot 收录 20 天前
▸ 精选理由

实践导向的规则与示例,适合架构设计与开发阶段使用

这个 Skill 做什么

提供 PostgreSQL 表/模式设计原则与推荐实践

给 PostgreSQL 表和模式设计实用建议:主键选型、字段类型、约束、索引(B-tree、GIN)、JSONB 用法与分区策略都涵盖。在建新表、改数据模型或优化 OLTP/高并发表时会用。特点是强调先规范化再在有数据证据时反规范化,兼顾可维护性与性能优化。

▸ 展开 SKILL.md 英文原文

Use this skill for general PostgreSQL table design. **Trigger when user asks to:** - Design PostgreSQL tables, schemas, or data models when creating new tables and when modifying existing ones. - Choose data types, constraints, or indexes for PostgreSQL - Create user tables, order tables, reference tables, or JSONB schemas - Understand PostgreSQL best practices for normalization, constraints, or indexing - Design update-heavy, upsert-heavy, or OLTP-style tables **Keywords:** PostgreSQL schema, table design, data types, PRIMARY KEY, FOREIGN KEY, indexes, B-tree, GIN, JSONB, constraints, normalization, identity columns, partitioning, row-level security Comprehensive reference covering data types, indexing strategies, constraints, JSONB patterns, partitioning, and PostgreSQL-specific best practices.

开发编程PostgreSQL表设计规范通用
1.8k
Stars
99
Forks
10
仓库内 Skill
+13
7 日增星
安装 / 使用
给你的 Agent 一句话(通用)
帮我安装这个 skill:https://raw.githubusercontent.com/timescale/pg-aiguide/main/skills/design-postgres-tables/SKILL.md
或 curl 直取 SKILL.md
curl -fsSL "https://raw.githubusercontent.com/timescale/pg-aiguide/main/skills/design-postgres-tables/SKILL.md"
SKILL.MD 节选查看完整文件 ↗
# PostgreSQL Table Design

## 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`; use `UUID` only 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 **DEFAULT**s for common values.
- Create **indexes for access paths you actually query**: PK/unique (auto), **FK columns (manual
via SKILL·HOT · 数据来自 GitHub 公开信息 · 原文版权归作者所有