【GaussDB分布式特性】

实验环境

  1. 华为云GaussDB云数据库,规则如下:
    在这里插入图片描述
  2. 集群拓扑结构,如下:
    在这里插入图片描述

一、分布式架构

  1. 逻辑架构
    在这里插入图片描述

  2. 常用部署方式
    在这里插入图片描述
    部署说明:
    1.双AZ采用带第三方仲裁方式部署,即独立Server9网络域
    2.4C4D4副本,一共需要9台物理机(4+4+1)
    3.DN主备交叉部署,主统一在AZ1
    4.主机故障优先在同AZ切换
    5.核心组件两个AZ对称,支持跨AZ双活;

二、分片和分区

  1. 分片:

    • REPLICATION:表的每一行存在所有数据节点(DN)中,即每个数据节点都有完整的表数据。
    • HASH:对指定的列进行Hash,通过映射,把数据分布到指定DN。
    • RANGE:对指定列按照范围进行映射,把数据分布到对应DN。
    • LIST :对指定列按照具体值进行映射,把数据分布到对应DN。
  2. 分区:
    如RANGE:类似二级分区,单机上的分区功能

  3. 两者关系:
    在这里插入图片描述

  4. 数据分片示例

    • 查询节点名称
      SELECT * FROM pgxc_node where node_type='D';
      
      结果如下:
      postgres=> SELECT * FROM pgxc_node where node_type='D';
           node_name     | node_type | node_port |   node_host   | node_port1 |  node_host1   | hostis_primary | nodeis_primary | nodeis_preferred |   node_id   | sctp_port | control_port | sctp_port1 | control_port1 | nodeis_central | nodeis_active
      -------------------+-----------+-----------+---------------+------------+---------------+----------------+----------------+------------------+-------------+-----------+--------------+------------+---------------+----------------+---------------
       dn_6001_6002_6003 | D         |     40000 | 192.168.0.230 |      40000 | 192.168.0.230 | t              | f              | f                | -1072999043 |     40002 |        40003 |          0 |             0 | f              | t
       dn_6004_6005_6006 | D         |     40000 | 192.168.0.193 |      40000 | 192.168.0.193 | t              | f              | f                |  -564789568 |     40002 |        40003 |          0 |             0 | f              | t
       dn_6007_6008_6009 | D         |     40000 | 192.168.0.122 |      40000 | 192.168.0.122 | t              | f              | f                |  1532339558 |     40002 |        40003 |          0 |             0 | f              | t
      (3 rows)
      
    • 创建组
      create node group group_dn1_dn2 with(dn_6007_6008_6009,dn_6004_6005_6006);
      
    • 建表到指定组
      create table test(id int not null) distribute by hash(id) to group group_dn1_dn2;
      
      在这里插入图片描述
      create table test1(id int not null) 
      DISTRIBUTE BY RANGE(id)(
      slice s1 values less than(10) datanode dn_6004_6005_6006,
      slice s2 values less than(20) datanode dn_6007_6008_6009,
      slice s3 values less than(30) datanode dn_6001_6002_6003,
      slice s4 values less than(40) datanode dn_6001_6002_6003
      );
      
      在这里插入图片描述
    • test表准备数据
      insert into test values(1),(2),(3),(4);
      
    • test表的数据分布查询
      execute direct on(dn_6001_6002_6003) 'select * from test';
      execute direct on(dn_6004_6005_6006) 'select * from test';
      execute direct on(dn_6007_6008_6009) 'select * from test';
      
      在这里插入图片描述
      注意:这里的test表在创建时指定了所属node group,所以该表只在在两个节点上存在。
    1. test表的数据分布情况

      select b.node_name,a.count from(select xc_node_id,count(*) from test group by xc_node_id) a,pgxc_node b where a.xc_node_id=b.node_id;
      

      在这里插入图片描述

    2. test1表进行测试

      insert into test1 values(1),(10),(20),(30),(35),(39);
      execute direct on(dn_6001_6002_6003) 'select * from test1';
      execute direct on(dn_6004_6005_6006) 'select * from test1';
      execute direct on(dn_6007_6008_6009) 'select * from test1';
      

      在这里插入图片描述
      test1是按照range分片,得出重要结论分片的范围是左闭右开的区间即"[ )"
      test1表的数据分布情况:

      select b.node_name,a.count from(select xc_node_id,count(*) from test1 group by xc_node_id) a,pgxc_node b where a.xc_node_id=b.node_id;
      

      在这里插入图片描述

  5. 数据分区示例

    • 创建分片分区表

      create table test_part(id int not null,age int) 
      DISTRIBUTE BY RANGE(id)(
      slice s1 values less than(10) datanode dn_6001_6002_6003,
      slice s2 values less than(20) datanode dn_6004_6005_6006,
      slice s3 values less than(30) datanode dn_6007_6008_6009,
      slice s4 values less than(40) datanode dn_6007_6008_6009
      )
      PARTITION BY RANGE(age)(
      PARTITION p1 values less than(10),
      PARTITION p2 values less than(20),
      PARTITION p3 values less than(30),
      PARTITION p4 values less than(40)
      );
      

      查看表结构:
      在这里插入图片描述
      插入测试数据:

      insert into test_part values(1,5),(2,9),(10,10),(19,19),(20,20),(30,30);
      

      数据分布查询:

      execute direct on(dn_6001_6002_6003) 'select * from test_part';
      execute direct on(dn_6004_6005_6006) 'select * from test_part';
      execute direct on(dn_6007_6008_6009) 'select * from test_part';
      

      在这里插入图片描述

      test_part表的数据分布情况:

      select b.node_name,a.count from(select xc_node_id,count(*) from test_part group by xc_node_id) a,pgxc_node b where a.xc_node_id=b.node_id;
      

      在这里插入图片描述

由此,我们可以看出GaussDB中表是按照分片进行存储,且可在分片下进行分区存储。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

若兰幽竹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值