Creating partitions

First, I want to focus your attention on the old method to partition data.

Before digging deeper into the advantages of partitioning, I want to show how partitions can be created. The entire thing starts with a parent table:

test=# CREATE TABLE t_data (id serial, t date, payload text);CREATE TABLE

In this example, the parent table has three columns. The date column will be used for partitioning but more on that a bit later.

Now that the parent table is in place, the child tables can be created. This is how it works:

test=# CREATE TABLE t_data_2016 () INHERITS (t_data);CREATE TABLEtest=# \d t_data_2016                       Table "public.t_data_2016"  Column  | Type    | Modifiers ---------+---------+----------------------------------------------------- ...

Get Mastering PostgreSQL 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.