Live migration of a partitioned table
If you executed the creation of partition, index, and trigger functions in this chapter against a live Dell Store 2 installation, you've now got all of the actual data in the parent orders
table, with a number of empty partitions. This is typically how a live migration to partitions would prefer to happen too. The other option is to dump the table, create the partition structure, then load the data back in again—which involves some downtime.
There is another way though. Consider the update trigger again. What if you installed one of those against the parent table? You could then migrate to the partitioned structure just by updating every row. Here's what the code looks like for that:
CREATE OR REPLACE FUNCTION orders_update_trigger() RETURNS TRIGGER AS $$ BEGIN DELETE FROM orders WHERE OLD.orderid=orderid; INSERT INTO orders values(NEW.*); RETURN NULL; END; $$ LANGUAGE plpgsql; CREATE TRIGGER update_orders BEFORE...