postgresqldatabase-partitioningrange-partitions

POSTGRES - Range Partitioning


I have table which is already designed to partition based on month range.

I am writing code in java to check all existing partitions and would create a new one when it doesnt exist.

If I create a new range partition for the upcoming month, will postgres automatically push data from main table onto the new range once new range data is attempted to be saved in DB ?

I tried inserting data into the main table to make postgres save data into range partition but I suppose its not required.


Solution

  • You have to create the partition before you insert data that belong into that partition, just to make that clear.

    As soon as the new partition has been created, you can insert new data for that partition into the partitioned table, and the data will end up in the correct partition automatically. Note that the partitioned table itself does not contain any data; all data are routed to the appropriate partition. You simply use the partitioned table as if it were a regular table.