我有一个表,本机按日期分区。分区涵盖 1 个月。我有另一个非常大的表(19GB),我想将数据复制到分区表中。我已经使用过pg_partman
这个过程,但是该partman.partition_data_proc
过程花了 12 个小时才将 9GB 数据移动到 60 个新分区。作为参考,我在 Amazon RDS (M5 Large) 上使用 Postgres 15。
我曾尝试使用partman.partition_data_proc
来移动数据。对于更具体的情况,请进行以下查询:
-- 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'
);
我还尝试使用 DBeaver 导出/导入数据功能来移动数据(它速度较慢,并且将数据插入到默认分区中)。有没有更快的方法来做到这一点?我希望能够在 8 小时内传输数据,并且不必将 RDS 实例升级为更昂贵的实例。