1/ On master
CREATE TABLE event_store (
id bigint DEFAULT nextval('public.eid_seq_1'::regclass) NOT NULL,
topic character varying(255),
created_at timestamp(6) without time zone DEFAULT now()
) PARTITION BY RANGE (created_at);
CREATE TABLE event_store_y2020m09 PARTITION of event_store
FOR VALUES FROM ('2020-09-01') TO ('2020-10-01') ;
CREATE TABLE event_store_y2020m10 PARTITION of event_store
FOR VALUES FROM ('2020-10-01') TO ('2020-11-01') ;
CREATE TABLE event_store_y2020m11 PARTITION of event_store
FOR VALUES FROM ('2020-11-01') TO ('2020-12-01') ;
CREATE TABLE event_store_default PARTITION of event_store DEFAULT;
-- create publications for partitions
create publication event_store_y2020m09 for table event_store_y2020m09;
create publication event_store_y2020m10 for table event_store_y2020m10;
create publication event_store_y2020m11 for table event_store_y2020m11;
2/ On slave
CREATE TABLE event_store (
id bigint DEFAULT nextval('public.eid_seq_1'::regclass) NOT NULL,
topic character varying(255),
created_at timestamp(6) without time zone DEFAULT now()
) PARTITION BY RANGE (created_at);
CREATE TABLE event_store_y2020m09 PARTITION of event_store
FOR VALUES FROM ('2020-09-01') TO ('2020-10-01') ;
CREATE TABLE event_store_y2020m10 PARTITION of event_store
FOR VALUES FROM ('2020-10-01') TO ('2020-11-01') ;
CREATE TABLE event_store_y2020m11 PARTITION of event_store
FOR VALUES FROM ('2020-11-01') TO ('2020-12-01') ;
CREATE TABLE event_store_default PARTITION of event_store DEFAULT;
-- create subscriptions for partitions
create subscription event_store_y2020m09 CONNECTION 'port=5432' publication event_store_y2020m09;
create subscription event_store_y2020m10 CONNECTION 'port=5432' publication event_store_y2020m10;
create subscription event_store_y2020m11 CONNECTION 'port=5432' publication event_store_y2020m11;