I have a table, natively partitioned by date. The partitions encompass 1 month. I have another very large table (19GB), from which I want to copy data into the partitioned table. I have used pg_partman
for this process, however the partman.partition_data_proc
procedure took 12 hours to move 9GB of data, into 60 new partitions. For reference, I am using Postgres 15 on Amazon RDS (M5 Large).
I have attempted to use partman.partition_data_proc
to move the data.
Take the following queries, for a more concrete case:
-- NOTE: Both tables have more columns, this is a minimal example
CREATE TABLE IF NOT EXISTS table1(
id bigint not null,
date timestamp not null,
col_a integer,
col_b double precision,
col_c varchar(255)
);
-- insert some data into "table" at this step
-- for example using something like this:
-- insert into table (
-- "id",
-- "date",
-- "col_a" ,
-- "col_b",
-- "col_c"
-- )
-- select
-- i,
-- get_random_date_between(start:='10 years', end:='1 day'),
-- random()::int,
-- (random()* 100)::numeric(10, 2),
-- 'Some Text'
-- from
-- generate_series(1,300000000) s(i);
CREATE TABLE IF NOT EXISTS partitioned_table(
id bigint not null,
date timestamp not null,
col_a integer,
col_b double precision,
col_c varchar(255)
) PARTITION BY RANGE (date);
-- NOTE: you will need to have pg_partman extension installed
-- https://github.com/pgpartman/pg_partman
SELECT partman.create_parent(
p_parent_table => 'public.partitioned_table',
p_control => 'date',
p_interval => '1 month'
);
-- This operation takes a very long time
call partman.partition_data_proc(
p_parent_table := 'public.partitioned_table',
p_interval := '1 month',
p_source_table := 'public.table1'
);
I have also attempted to move the data with DBeaver export/import data functionality (it was both slower and inserted data into the default partition). Is there a faster way to do this ? I would like to be able to transfer the data in less than 8 hours and, not have to bump up the RDS instance to something more expensive.
create_parent
is selected. And other would be created when thepartition_data_proc
procedure runs. But no rows are present whenpartition_data_proc
is called