Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有citus扩展的Postgresql分片不工作_Postgresql_Sharding_Postgresql 9.6_Citus - Fatal编程技术网

带有citus扩展的Postgresql分片不工作

带有citus扩展的Postgresql分片不工作,postgresql,sharding,postgresql-9.6,citus,Postgresql,Sharding,Postgresql 9.6,Citus,我正在使用带有citus扩展的Postgresql进行切分,无法切分如下表。 下表有一个主键和两个唯一键。我正在尝试使用主键(即pid)对列进行切分。 注意:不允许我更改表结构。这些表是通过工具创建的 CREATE TABLE person ( pid bigint NOT NULL, name character varying(100), address_pid bigint NOT NULL, address_type character varying(

我正在使用带有citus扩展的Postgresql进行切分,无法切分如下表。 下表有一个主键和两个唯一键。我正在尝试使用主键(即pid)对列进行切分。 注意:不允许我更改表结构。这些表是通过工具创建的

CREATE TABLE person 
(
    pid bigint NOT NULL,
    name character varying(100),
    address_pid bigint NOT NULL,
    address_type character varying(100),
    CONSTRAINT id_pkey PRIMARY KEY (pid),
    CONSTRAINT addr_id UNIQUE (address_pid),
    CONSTRAINT addr_type_id UNIQUE (address_type, address_pid)
);
这是我的分片查询:

select create_distributed_table('person', 'pid');
它抛出的错误是:

Error: Distributed relations cannot have UNIQUE, EXCLUDE, or PRIMARY KEY constraints that do not include the partition column
有人能帮我把这些桌子切碎吗

@CraigKerstiens除了这个问题:

当我们有多个像这样的外键时,如何处理切分

CREATE TABLE table
(
    pid bigint NOT NULL,
    search_order integer NOT NULL,
    resource_pid bigint NOT NULL,
    search_pid bigint NOT NULL,
    CONSTRAINT hfj_search_result_pkey PRIMARY KEY (pid),
    CONSTRAINT idx_searchres_order UNIQUE (search_pid, search_order),
    CONSTRAINT fk_searchres_res FOREIGN KEY (resource_pid)
        REFERENCES public.table1 (res_id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT fk_searchres_search FOREIGN KEY (search_pid)
        REFERENCES public.table2 (pid) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

假设表1和表2已经被切分。

此时在Citus中,您不能有一个唯一的约束,该约束不包括您正在分区的列。在这种情况下,可以强制地址对于个人id是唯一的,但不是全局唯一的。为此,您可以:

CREATE TABLE person 
(
    pid bigint NOT NULL,
    name character varying(100),
    address_pid bigint NOT NULL,
    address_type character varying(100),
    CONSTRAINT id_pkey PRIMARY KEY (pid),
    CONSTRAINT addr_id UNIQUE (pid, address_pid),
    CONSTRAINT addr_type_id UNIQUE (pid, address_type, address_pid)
);

我在上面的一个内联问题中又添加了一个问题。对于外键,它们应该可以工作,您只需使它们成为复合外键,然后设置所有外键。这样做的原因是,系统知道数据驻留在该特定节点上,而不必跨节点。