21.3. Создание базы данных #
В данном примере создаётся таблица pgbench_branches, а также совмещённые таблицы pgbench_accounts и pgbench_history. Каждая секция таблицы pgbench_history дополнительно разбивается на секции по диапазону.
CREATE TABLE pgbench_branches (
bid integer NOT NULL PRIMARY KEY,
bbalance integer,
filler character(88)
)
WITH (distributed_by = 'bid',
num_parts = 8);
CREATE TABLE pgbench_accounts (
aid integer NOT NULL,
bid integer,
abalance integer,
filler character(84),
PRIMARY KEY (bid, aid)
)
WITH (distributed_by = 'bid',
num_parts = 8,
colocate_with = 'pgbench_branches');
CREATE TABLE public.pgbench_history (
tid integer,
bid integer,
aid integer,
delta integer,
mtime timestamp without time zone,
filler character(22)
)
WITH (distributed_by = 'bid',
colocate_with = 'pgbench_branches',
partition_by = 'mtime',
partition_bounds =
$${{minvalue, '2021-01-01 00:00'},{'2021-01-01 00:00', '2022-01-01 00:00'},{'2022-01-01 00:00', maxvalue}}$$
);