Search code examples
postgresqlpostgresql-9.3database-partitioning

Adding partition to a PostgreSQL table which is been used for insertion at that moment?


I'm checking how we can add partition to table which is used for insertion at that moment .

I'm using postgres 9.3 and I have created basic partitioning tables as follows.

  • Parent Table - customer
  • Child tables - customer_month_01 to customer_month_06

I created the trigger on insert and insert into all tables working accurately. ( Data is inserted to according to trigger for appropriate table )

Now my concern is how can I add new partition to parent while the records insert is happening.

I updated the trigger function, but I'm stuck in adding that trigger to master (parent) table. In order to add updated trigger, I have to drop old trigger first. Since continuous insert is going on, soon after I drop the trigger all the insert will go into parent table ( within the window of trigger drop and add new trigger). So, after new trigger creation is done, I have to manually move the data to appropriate partition. I want to prevent this.

How can I do this task without insert into parent table ?


Solution

  • In this case updating trigger function will be sufficient. After updating the trigger function new data will be redirected to appropriate child table.

    http://www.postgresql.org/docs/9.3/static/ddl-partitioning.html