PostgreSQL Performance Cheat Sheet/Create range-partitioned table

Partition large time-series tables by range.

Section: High-value Query Performance Patterns

Create range-partitioned table

sql
sql
CREATE TABLE metrics (
  ts timestamptz NOT NULL,
  device_id bigint NOT NULL,
  value numeric NOT NULL
) PARTITION BY RANGE (ts);
Explanation

See summary for usage details.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing High-value Query Performance Patterns
Keyset pagination
Prefer keyset pagination over deep OFFSET scans for large result sets.
OpenIn sheetsqlsame section
Select needed columns
Avoid fetching unnecessary columns, especially wide rows.
OpenIn sheetsqlsame section
Covering index with INCLUDE
Use included columns to support index-only reads for certain queries.
OpenIn sheetsqlsame section
Batch updates
Chunk large writes into batches to reduce contention and WAL spikes.
OpenIn sheetsqlsame section
Attach partition
Add a partition for a date range.
OpenIn sheetsqlsame section
Batch deletes
Delete in chunks to avoid huge transactions.
OpenIn sheetsqlsame section