postgresql-table-design

Design PostgreSQL schemas with primary keys, normalization, data types, and indexing.

Updated Jan 20, 2026
One-click install
npx skills add https://github.com/ollieb89/ugro --skill postgresql-table-design-ollieb89
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgresql-table-design
Source: https://github.com/ollieb89/ugro/tree/main/.windsurf/skills/postgresql
Command: npx skills add https://github.com/ollieb89/ugro --skill postgresql-table-design-ollieb89

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides structured guidance for PostgreSQL schema design, helping teams create correct, scalable tables by outlining best practices for keys, normalization, data types, indexing, constraints, and extension considerations.

Core Features & Use Cases

  • Primary key and normalization guidance: enforce 3NF where appropriate, use BIGINT generated identities for surrogate keys, and apply UUIDs when global uniqueness is needed.
  • Data types and constraints: recommendations for TIMESTAMPTZ, TEXT, NUMERIC, JSONB, and proper NOT NULL/DEFAULT patterns; discusses MVCC, vacuum, and commit behavior to minimize bloat.
  • Indexing, constraints, and maintenance: PK/FK indexing, unique constraints with NULL handling, partial and expression indexes, and notes on partitioning and extension usage (e.g., jsonb, timescaledb).
  • Use Case: design a users table with id as BIGINT GENERATED ALWAYS AS IDENTITY primary key, created_at TIMESTAMPTZ NOT NULL DEFAULT now(), and a separate normalized reference table structure to illustrate efficient foreign keys.

Quick Start

Apply these guidelines to blueprint a new PostgreSQL schema for a bounded domain. Start by defining a primary key, normalization to 3NF, appropriate data types for each column, NOT NULL constraints, and indexes on frequently queried fields. Draft a sample CREATE TABLE for a simple domain (e.g., users) that demonstrates IDENTITY-based primary keys, timestamp columns, and a foreign key relationship.

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 follows best practices?

Design PostgreSQL schemas by defining primary keys using BIGINT GENERATED ALWAYS AS IDENTITY, normalizing to 3NF, selecting appropriate data types (TIMESTAMPTZ, TEXT, NUMERIC, JSONB), applying NOT NULL and DEFAULT constraints, and indexing frequently queried fields. This ensures correctness, scalability, and performance across transactional and analytical workloads.

What's the best way to choose primary keys and handle normalization in PostgreSQL?

Use BIGINT generated identities for surrogate keys in most cases, and UUIDs when global uniqueness across systems is required. Normalize tables to 3NF by separating concerns into distinct tables with foreign key relationships, reducing data redundancy and maintaining referential integrity.

How do I index PostgreSQL tables for better query performance?

Index primary keys and foreign keys automatically, create unique constraints for business rules (accounting for NULL handling), and use partial or expression indexes on frequently filtered or computed columns. Partitioning and extensions like jsonb and timescaledb further optimize specific workload patterns.

What data types should I use in PostgreSQL and why does it matter?

PostgreSQL data types like TIMESTAMPTZ, TEXT, NUMERIC, and JSONB each serve specific purposes and affect storage, query performance, and MVCC behavior. Correct type selection minimizes table bloat, reduces vacuum overhead, and ensures accurate comparisons and constraints.

Can I use constraints and NOT NULL defaults to ensure data quality in PostgreSQL?

Yes. Apply NOT NULL constraints to mandatory columns, set DEFAULT values (like `now()` for timestamps) to enforce consistent initialization, and use unique and foreign key constraints to maintain referential integrity and prevent invalid states.

When should I use extensions like jsonb or timescaledb in schema design?

Use jsonb for semi-structured or nested data without schema rigidity, and timescaledb for time-series data requiring efficient compression and time-bucketed queries. Extensions integrate into schema design to handle specialized workload patterns beyond standard normalization.