create table p (id int, val text) partition by hash (id);

create table p0 (id int primary key, val text);
create table p1 (id int primary key, val text);
create table p2 (id int primary key, val text);
create table p3 (id int primary key, val text);
create table p4 (id int primary key, val text);
create table p5 (id int primary key, val text);
create table p6 (id int primary key, val text);
create table p7 (id int primary key, val text);

create extension postgres_fdw;
create server pg foreign data wrapper postgres_fdw options ( host 'localhost', dbname 'test');
create user mapping for "user" server pg options ( user 'user');

create foreign table p0f partition of p for values with (modulus 8, remainder 0) server pg options (table_name 'p0');
create foreign table p1f partition of p for values with (modulus 8, remainder 1) server pg options (table_name 'p1');
create foreign table p2f partition of p for values with (modulus 8, remainder 2) server pg options (table_name 'p2');
create foreign table p3f partition of p for values with (modulus 8, remainder 3) server pg options (table_name 'p3');
create foreign table p4f partition of p for values with (modulus 8, remainder 4) server pg options (table_name 'p4');
create foreign table p5f partition of p for values with (modulus 8, remainder 5) server pg options (table_name 'p5');
create foreign table p6f partition of p for values with (modulus 8, remainder 6) server pg options (table_name 'p6');
create foreign table p7f partition of p for values with (modulus 8, remainder 7) server pg options (table_name 'p7');

create table t as select i, md5(i::text) from generate_series(1,1000000) s(i);
vacuum analyze t;

checkpoint;

\timing
insert into p select * from t;
truncate p0;
truncate p1;
truncate p2;
truncate p3;
truncate p4;
truncate p5;
truncate p6;
truncate p7;

insert into p select * from t;
truncate p0;
truncate p1;
truncate p2;
truncate p3;
truncate p4;
truncate p5;
truncate p6;
truncate p7;

insert into p select * from t;
truncate p0;
truncate p1;
truncate p2;
truncate p3;
truncate p4;
truncate p5;
truncate p6;
truncate p7;

insert into p select * from t;
truncate p0;
truncate p1;
truncate p2;
truncate p3;
truncate p4;
truncate p5;
truncate p6;
truncate p7;

insert into p select * from t;
truncate p0;
truncate p1;
truncate p2;
truncate p3;
truncate p4;
truncate p5;
truncate p6;
truncate p7;

insert into p select * from t;
truncate p0;
truncate p1;
truncate p2;
truncate p3;
truncate p4;
truncate p5;
truncate p6;
truncate p7;

insert into p select * from t;
truncate p0;
truncate p1;
truncate p2;
truncate p3;
truncate p4;
truncate p5;
truncate p6;
truncate p7;

insert into p select * from t;
truncate p0;
truncate p1;
truncate p2;
truncate p3;
truncate p4;
truncate p5;
truncate p6;
truncate p7;

insert into p select * from t;
truncate p0;
truncate p1;
truncate p2;
truncate p3;
truncate p4;
truncate p5;
truncate p6;
truncate p7;

insert into p select * from t;
truncate p0;
truncate p1;
truncate p2;
truncate p3;
truncate p4;
truncate p5;
truncate p6;
truncate p7;
