PostgreSQL retention and partitions

  Kiến thức lập trình

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

Odin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT