Rj_*_*j_N 5 postgresql partitioning postgresql-11
我最近将数据库从 PostgreSQL v9.6 升级到 v11.7。我们有一些分区表,inherence并计划将它们迁移到declaration.
表 DDL:
CREATE TABLE c_account_p
(
billing_account_guid character varying(40) NOT NULL,
ingestion_process_id bigint NOT NULL DEFAULT '-1'::integer,
load_dttm timestamp(6) without time zone NOT NULL,
ban integer NOT NULL,
CONSTRAINT billing_account_pkey PRIMARY KEY (billing_account_guid, ban)
) PARTITION by RANGE(load_dttm);
Run Code Online (Sandbox Code Playgroud)
当我尝试创建表时,它抛出以下错误:
ERROR: insufficient columns in the PRIMARY KEY constraint definition
DETAIL: PRIMARY KEY constraint on table "l_billing_account_p" lacks column "load_dttm" which is part of the partition key.
SQL state: 0A000
Run Code Online (Sandbox Code Playgroud)
partition column应该是主键是强制性/必要的吗?因为如果我包括load_dttm作为PK那么它的工作的罚款。数据库<>小提琴
如果partition column应该是 a PK,则使用日期列按范围创建分区是具有挑战性的,load_dttm如果加载数据COPY或INSERT.
INSERT INTO c_account_p SELECT * from c_account_p_bkp ON CONFLICT (billing_account_guid,ban,load_dttm) DO UPDATE SET 'some stuff..'
Run Code Online (Sandbox Code Playgroud)
如果我收到 billing_account_guid,禁止与不同的 load_dttm 组合,那么它最终会得到重复的密钥。
有人可以帮我理解这个场景吗?
谢谢。
是的,这是必需的。PostgreSQL 中不存在针对所有分区的索引的概念。分区键是主键子集的要求允许我们通过在每个分区上拥有单独的唯一索引来实现主键。
5.10.2.3 节中有提到。“分区表的唯一约束必须包括所有分区键列。存在此限制是因为 PostgreSQL 只能单独强制每个分区的唯一性。
CREATE TABLE c_account_p
(
billing_account_guid character varying(40) NOT NULL,
ingestion_process_id bigint NOT NULL DEFAULT '-1'::integer,
load_dttm timestamp(6) without time zone NOT NULL,
ban integer NOT NULL,
CONSTRAINT billing_account_pkey PRIMARY KEY (billing_account_guid,ban,load_dttm)
) PARTITION by RANGE(load_dttm);
Run Code Online (Sandbox Code Playgroud)