# Design postgres tables

> Design postgres tables is an open-source agent skill for databases. Guides an agent through PostgreSQL table design, types, constraints and indexing. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/timescale/pg-aiguide/tree/main/skills/design-postgres-tables
- **Repository:** https://github.com/timescale/pg-aiguide
- **GitHub stars:** 1,892
- **License:** Apache-2.0
- **Skill name:** design-postgres-tables
- **Collection:** https://github.com/timescale/pg-aiguide
- **Categories:** [databases](https://ai-powered.com/categories/databases)
- **Listing updated:** 2026-12-04

## About

This skill gives the agent a reference-style playbook for designing PostgreSQL tables. It covers choosing column types, primary and foreign keys, NOT NULL and CHECK constraints, unique rules, and which index type fits a given access pattern, including B-tree, GIN, GiST and BRIN. It also includes guidance for JSONB columns, partitioning, row-level security, and tables that are update-heavy, insert-heavy or upsert-driven.

The skill is instructional only. It contains no scripts, so the agent works from the rules and SQL examples in the document, such as a users, orders and profiles schema. It flags common PostgreSQL pitfalls, for example that foreign key columns are not indexed automatically, that identifiers fold to lowercase, and that sequence gaps are normal.

The guidance targets PostgreSQL and mentions version-specific features such as NULLS NOT DISTINCT and uuidv7 for PG18+, so the agent should check the target server version. Extensions like TimescaleDB, PostGIS, pgvector and pgcrypto are referenced where relevant.

## When your agent uses it

> 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.

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/timescale/pg-aiguide/tree/HEAD/skills/design-postgres-tables)
- [License: Apache-2.0](https://github.com/timescale/pg-aiguide/tree/HEAD/skills/design-postgres-tables)

## Features

- **Column type selection:** Recommends PostgreSQL data types for IDs, money, timestamps, text, floats and booleans, and lists types to avoid.
- **Constraint guidance:** Explains primary keys, foreign key actions, unique handling of NULLs, CHECK and exclusion constraints.
- **Index strategy:** Covers composite, partial, covering, expression and GIN, GiST and BRIN indexes for real query paths.
- **JSONB modeling:** Describes when to use JSONB, GIN and jsonb_path_ops indexing, and extracting hot fields into generated columns.
- **Partitioning options:** Outlines range, list and hash partitioning and the limits on unique constraints and foreign keys.
- **Write-heavy table patterns:** Gives advice for update-heavy, insert-heavy and upsert-friendly tables, including fillfactor and HOT updates.
- **Safe schema changes:** Notes on transactional DDL, concurrent index builds and avoiding table rewrites when adding columns.

## Good for

- Design a schema for a new orders and customers database
- Choose data types and constraints for a money or timestamp column
- Add indexes for foreign keys and frequent filters on an existing table
- Model optional attributes with a JSONB column and a GIN index
- Plan partitioning for a very large time-series table
- Tune a high-update table to reduce bloat

## Install

### Claude Code

This skill ships in the `pg` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add timescale/pg-aiguide
/plugin install pg@aiguide
```

Or copy only this skill to `~/.claude/skills/design-postgres-tables`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/timescale/pg-aiguide.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/design-postgres-tables &&
cp -R "$tmp/skills/design-postgres-tables" ~/.claude/skills/design-postgres-tables &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/design-postgres-tables` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/design-postgres-tables` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/timescale/pg-aiguide.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/design-postgres-tables &&
cp -R "$tmp/skills/design-postgres-tables" ~/.agents/skills/design-postgres-tables &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/design-postgres-tables` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/design-postgres-tables` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/timescale/pg-aiguide.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/design-postgres-tables &&
cp -R "$tmp/skills/design-postgres-tables" ~/.cursor/skills/design-postgres-tables &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/design-postgres-tables` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/timescale/pg-aiguide.git --path skills/design-postgres-tables
```

Or copy the folder to `~/.gemini/skills/design-postgres-tables` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/design-postgres-tables`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/timescale/pg-aiguide.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/design-postgres-tables &&
cp -R "$tmp/skills/design-postgres-tables" ~/.copilot/skills/design-postgres-tables &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/design-postgres-tables` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/timescale/pg-aiguide.git
```

Then copy `pg-aiguide/skills/design-postgres-tables` into your agent's skills folder as `design-postgres-tables`. Agents that support SKILL.md read one folder per skill.

## FAQ

### Does Design postgres tables run any scripts or change my database?

No. The skill ships only a SKILL.md with guidance and SQL examples and no scripts, so it informs the agent's table design rather than executing anything.

### Which PostgreSQL versions does Design postgres tables assume?

It mentions features from PG15 and PG18, such as NULLS NOT DISTINCT and uuidv7 for PG18+ and gen_random_uuid for older versions, so the agent must pick the right options for the server version in use.

### When does the skill apply?

It applies when a user asks to design or modify PostgreSQL tables, schemas or data models, choose types, constraints or indexes, or design JSONB or OLTP-style tables.

### How do I install Design postgres tables in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/design-postgres-tables to use it in all your projects, or to .claude/skills/design-postgres-tables in one project. Or install the pg plugin, which includes it: /plugin marketplace add timescale/pg-aiguide, then /plugin install pg@aiguide.

### Does Design postgres tables run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Design postgres tables?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

### What are the best alternatives to Design postgres tables?

The closest alternatives to Design postgres tables are Postgres, Design postgis tables, PostgreSQL optimization, Postgres database migration and Database migrations.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Postgres](https://ai-powered.com/skills/postgres-timescale): Postgres is an open-source agent skill for databases.
- [Design postgis tables](https://ai-powered.com/skills/design-postgis-tables): Design postgis tables is an open-source agent skill for databases.
- [PostgreSQL optimization](https://ai-powered.com/skills/postgresql-optimization): PostgreSQL optimization is an open-source agent skill for databases.
- [Postgres database migration](https://ai-powered.com/skills/postgres-database-migration): Postgres database migration is an open-source agent skill for databases.
- [Database migrations](https://ai-powered.com/skills/database-migrations): Database migrations is an open-source agent skill for databases.
- [Data layer patterns edho ferdian](https://ai-powered.com/skills/data-layer-patterns-edho-ferdian): Data layer patterns edho ferdian is an open-source agent skill for databases.
- [PostgreSQL code review](https://ai-powered.com/skills/postgresql-code-review): PostgreSQL code review is an open-source agent skill for databases.
- [Database migrations](https://ai-powered.com/skills/database-migrations-nabwinsaud): Database migrations is an open-source agent skill for databases.

---
Source: https://ai-powered.com/skills/design-postgres-tables
