design-postgres-tables

Design PostgreSQL table schemas with data types, constraints, and indexes.

1.8k|104|Updated Jul 23, 2025
One-click install
npx skills add https://github.com/timescale/pg-aiguide --skill design-postgres-tables
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: design-postgres-tables
Source: https://github.com/timescale/pg-aiguide/tree/main/skills/design-postgres-tables
Command: npx skills add https://github.com/timescale/pg-aiguide --skill design-postgres-tables

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps engineers design robust PostgreSQL table schemas with appropriate data types, constraints, and indexes. It emphasizes normalization, proper referential integrity, and scalable access patterns to reduce maintenance and data anomalies.

Core Features & Use Cases

  • Guidance on selecting data types, constraints, and indexes for common OLTP and analytical workloads.
  • Best practices for normalization (3NF), primary/foreign keys, identity columns, partitioning, and JSONB patterns.
  • Real-world example: design a users and orders schema with proper foreign keys, constraints, and targeted indexing.

Quick Start

Ask the AI to design a normalized customers and orders schema with primary keys, foreign keys, and required indexes.

Frequently Asked Questions about design-postgres-tables

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

FAQPage Schema
How do I design a normalized PostgreSQL schema with proper constraints and indexes?

To design a normalized PostgreSQL schema, apply 3NF principles to separate entities and establish referential integrity using primary and foreign keys. You must select appropriate data types, enforce NOT NULL constraints, and add unique indexes to support targeted OLTP access patterns and prevent data anomalies.

When should I use partitioning and JSONB patterns in PostgreSQL tables?

Use PostgreSQL partitioning to manage large data-intensive workloads by splitting tables into smaller physical segments, and apply JSONB patterns when you need flexible, semi-structured data storage. Combining both strategies ensures scalable access patterns while maintaining schema robustness for analytical queries.

What is the best way to model foreign keys and identity columns for OLTP workloads?

Modeling foreign keys and identity columns for OLTP workloads requires defining identity columns for synthetic primary key generation and enforcing foreign key constraints to maintain referential integrity. This combination ensures reliable transactional relationships and reduces data anomalies across normalized tables.

Does this PostgreSQL schema design approach support data-intensive analytical workloads?

Yes, this PostgreSQL schema design approach supports data-intensive analytical workloads by providing best practices for selecting optimized data types, applying table partitioning for large datasets, and implementing targeted indexing strategies to accelerate complex queries without sacrificing normalization.

What are the limitations of using 3NF normalization for high-volume PostgreSQL databases?

While 3NF normalization reduces data anomalies, strict normalization in high-volume PostgreSQL databases can introduce complex joins that degrade analytical query performance. You must balance normalized schemas with strategic denormalization, partitioning, and targeted indexes to maintain acceptable read performance.

Can I use this skill to generate a complete customers and orders schema?

Yes, you can use this skill to generate a complete customers and orders schema by requesting a normalized design. It will output tables with appropriate primary keys, foreign keys, identity columns, NOT NULL constraints, and required indexes for real-world OLTP applications.