zoukankan      html  css  js  c++  java
  • Atitit pg10分区 总结 1.1. create table tmp_log (  1 1.2. 创建索引 1 1.3. 查看表 in pgadmin4 2 2. 二 分区表管理 2 2.1

    Atitit pg10分区 总结

    1.1. create table tmp_log (  1

    1.2. -创建索引 1

    1.3. 查看表 in pgadmin4 2

    2. 分区表管理 2

    2.1. --分区表管理:断开分区 2

    2.2. --a区表管理:连接分区 3

    2.3. --分区表管理:删除分区 3

    3. 三、参考 3

    1.1. creaate table tmp_log ( 

      id serial,

      create_time timestamp(0) without time zone, 

      remark char(1)

    ) partition by RANGE(create_time);

     

    CREATE TABLE tmp_log_p2016_befor PARTITION OF tmp_log FOR VALUES FROM (UNBOUNDED)  TO ('2016-01-01');

    CREATE TABLE tmp_log_p201601 PARTITION OF tmp_log FOR VALUES FROM ('2016-01-01') TO ('2016-02-01');

    1.2. -创建索引

    create index idx_tmp_log_p2016_befor_ctime on tmp_log_p2016_befor using btree (create_time);

    create index idx_tmp_log_p201601_ctime on tmp_log_p201601 using btree (create_time);

    索引只能在分区字表是上查看。。

    ,注意 constraint_exclusion 设备成 partition ;目前分区上的索引、约束、主键需要使用单独的命令创建。

     

    1.3. 查看表 in pgadmin4

    2.  分区表管理

    2.1. --分区表管理:断开分区

    francs=> alter table tmp_log DETACH PARTITION tmp_log_p201702;

    ALTER TABLE

    备注:DETACH 操作是指将分区从分区表断开,类似从一列火车中断开一节车厢类似,这个表将转变成普通表,仍然可读写。

     

    2.2. --分区表管理:连接分区

    francs=> alter table tmp_log ATTACH PARTITION tmp_log_p201702 FOR VALUES FROM ('2017-02-01') TO ('2017-03-01');

    ALTER TABLE

    备注:ATTACH 操作是指将普通表连接到指定分区表,有一点要注意,ATTACH 和 DETACH 操作过程中,会在父表、此张分区表上加上 AccessExclusiveLock 排它锁,因此分区表的这两个操作应该在业务低谷时进行,避免影响业务。

    2.3. --分区表管理:删除分区

    francs=> drop table tmp_log_p201702;

    DROP TABLE

    备注:删除对就分区表即可。

     

    3. 现有表转换分区

    貌似不能直接转。只好原表现改名备用。

    然后新建分区主表

     primary key constraints are not supported on partitioned tables

    主表不能有主键 和任何索引 也不能有任何数据,就是个空表

    4. 三、参考

    · Table Partitioning

    · PostgreSQL: 分区表应用二(取模分区)  

    · CREATE TABLE

  • 相关阅读:
    vc++ 编译器工具
    lesson 17 进程间通信 孙鑫 VC++
    VC++ msdn
    VC++ 相关问题
    MySQL
    Git
    Angular
    Linux
    阿里云服务器
    Git
  • 原文地址:https://www.cnblogs.com/attilax/p/15197678.html
Copyright © 2011-2022 走看看