I have two tables:
CREATE TABLE order (
id SERIAL PRIMARY KEY,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
total NUMERIC(10, 2) NOT NULL
);
CREATE TABLE order_item (
id SERIAL PRIMARY KEY,
order_id INTEGER NOT NULL REFERENCES order(id),
product_id INTEGER NOT NULL REFERENCES product(id),
quantity INTEGER NOT NULL,
price NUMERIC(10, 2) NOT NULL
);
I would like to partition these tables into two parts: order_current
for orders created within the last 12 months, and order_archive
for orders older than 12 months.
How can I achieve this? Additionally, should the order_item
table also be partitioned?
Thank you!
I was tring to find a solution using pg_partman, but could not find.
New contributor
1