_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

PostgreSQL Partitioning

04. 07. 2023 1 min read intermediate

Faster queries, easier maintenance of large tables.

Range Partitioning

CREATE TABLE orders (
    id SERIAL, 
    created_at TIMESTAMPTZ NOT NULL, 
    total DECIMAL
) PARTITION BY RANGE (created_at);

CREATE TABLE orders_2024_q1 PARTITION OF orders 
FOR VALUES FROM ('2024-01-01') TO ('2024-04-01');

List Partitioning

CREATE TABLE logs (id SERIAL, level TEXT, message TEXT) 
PARTITION BY LIST (level);

CREATE TABLE logs_error PARTITION OF logs 
FOR VALUES IN ('error','fatal');

pg_partman

CREATE EXTENSION pg_partman;
SELECT partman.create_parent('public.orders','created_at','native','monthly');
  • 100M+ rows
  • Time-series data
  • DROP PARTITION instead of DELETE

Partitioning for Large Tables

Speeds up queries and simplifies maintenance.

postgresqlpartitioningperformance
Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.