postgresql

Design PostgreSQL schemas with data types, indexes, constraints, and partitioning patterns.

2|Updated Jun 16, 2026
One-click install
npx skills add https://github.com/monang404/lunawave --skill postgresql-monang404
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: postgresql
Source: https://github.com/monang404/lunawave/tree/main/.agent/skills/postgresql
Command: npx skills add https://github.com/monang404/lunawave --skill postgresql-monang404

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Designing a PostgreSQL schema involves many database-specific decisions—data types, indexing strategies, constraints, and partitioning—where wrong choices lead to slow queries, data integrity issues, and painful migrations later. ## Core Features & Use Cases - Data Type Selection: Guidance on choosing correct types such as TIMESTAMPTZ over TIMESTAMP, TEXT over VARCHAR, NUMERIC for money, and BIGINT identity columns over serial. - Indexing & Constraints: Covers B-tree, GIN, GiST, BRIN, partial, covering, and expression indexes, plus PK, FK, UNIQUE, CHECK, and EXCLUDE constraints. - Advanced Features: Partitioning strategies, row-level security, JSONB guidance, generated columns, and extensions like pgvector, PostGIS, and TimescaleDB. - Use Case: When building a new orders table, use this Skill to define proper foreign keys with indexes, status CHECK constraints, and created_at indexes validated with EXPLAIN. ## Quick Start Ask the AI to design a PostgreSQL schema for your application entities, including appropriate data types, indexes, and constraints.

Frequently Asked Questions about postgresql

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

FAQPage Schema
How do I design a PostgreSQL table schema with best practices?▼

Start by capturing entities, access patterns, and scale targets, then choose types like BIGINT GENERATED ALWAYS AS IDENTITY for primary keys, TIMESTAMPTZ for timestamps, and TEXT for strings. Add NOT NULL and CHECK constraints, then create indexes only for actual query paths and validate with EXPLAIN.

What data type should I use for primary keys in PostgreSQL?▼

Prefer BIGINT GENERATED ALWAYS AS IDENTITY for most tables. Use UUID only when global uniqueness or opaque IDs are needed, generating them with gen_random_uuid() or uuidv7() on PG18+. Avoid the legacy serial type.

Does PostgreSQL automatically index foreign key columns?▼

No, PostgreSQL does not auto-index foreign key columns. You must manually add indexes on referencing columns to speed up joins and prevent locking issues during parent table deletes or updates.

When should I use JSONB versus regular columns in PostgreSQL?▼

Keep core relational data in typed columns and use JSONB only for optional or semi-structured attributes. Index JSONB with GIN for containment and key-existence queries, and extract frequently filtered scalar fields into generated columns with B-tree indexes.

When should I partition a PostgreSQL table?▼

Partition tables exceeding roughly 100 million rows when queries consistently filter on the partition key, typically a time or date column. Use declarative RANGE, LIST, or HASH partitioning, and remember that unique constraints must include the partition key.

Why does adding a column with a default rewrite my PostgreSQL table?▼

Adding a NOT NULL column with a volatile default like now() or gen_random_uuid() forces a full table rewrite. Use non-volatile defaults for fast metadata-only changes, or add the column nullable and backfill values separately.