postgresql-table-design

Design PostgreSQL table schemas with normalization, data types, constraints, and indexing.

1|Updated Nov 23, 2025
One-click install
npx skills add https://github.com/zmre/nix-pai --skill postgresql-table-design-zmre
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgresql-table-design
Source: https://github.com/zmre/nix-pai/tree/main/claude/skills/database-design/postgresql
Command: npx skills add https://github.com/zmre/nix-pai --skill postgresql-table-design-zmre

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps database architects and engineers design PostgreSQL schemas following industry best practices, reducing refactors by providing guidance on normalization, data types, constraints, and indexing.

Core Features & Use Cases

  • Best-practice Schema Design: Normalize up to 3NF; know when to denormalize for read performance.
  • Data Types & Constraints: Recommend appropriate data types, NOT NULL, DEFAULTs, and CHECK constraints.
  • Indexing & Performance: Advise on indexing primary keys, foreign keys, and frequently queried columns; discuss MVCC considerations.
  • Use Case: Design a schema for a user, product, and order system with proper FK relationships and scalable indexing.

Quick Start

Design a PostgreSQL schema for a simple e-commerce app with tables: users, products, orders, order_items, and reviews, including primary keys, foreign keys, appropriate NOT NULL constraints, and indexing on frequently queried columns (e.g., user_id, product_id, order_date).

Frequently Asked Questions about postgresql-table-design

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design a PostgreSQL schema that won't need major refactoring later?

Design schemas following normalization rules up to 3NF, use appropriate data types for each column, apply NOT NULL constraints with defaults, and define explicit foreign keys with indexes. This foundation reduces costly refactors by encoding best practices upfront.

What data types and constraints should I use in PostgreSQL tables?

Choose data types that match your data (integers for IDs, text for strings, timestamps for dates), apply NOT NULL constraints where values are required, set sensible defaults, and use CHECK constraints to enforce domain rules. Proper typing prevents silent bugs and improves query performance.

How do I index PostgreSQL tables for query performance?

Index primary keys automatically; explicitly index foreign keys to speed joins, index frequently queried columns like user_id or order_date, and consider MVCC storage implications for your workload. Strategic indexing accelerates reads without bloating writes.

When should I denormalize a PostgreSQL schema?

Denormalize selectively after normalizing to 3NF when analytical workloads or repeated joins become bottlenecks. Denormalization trades write complexity for read speed; apply it only where profiling shows benefit, not preemptively.

How do I handle primary keys and sequences in PostgreSQL?

Use serial or identity columns to auto-generate primary keys, or explicitly manage sequences for custom ID schemes. Identity columns simplify schema design and integrate cleanly with foreign key relationships.

Can I design schemas for both OLTP and analytical workloads in PostgreSQL?

Yes; OLTP schemas prioritize normalized writes with selective indexing on hot columns, while analytical schemas may denormalize for join reduction. Understand your workload mix before finalizing indexing and constraint strategy.