首页 > 其他分享 >MogDB 学习笔记之 --exchange partition

MogDB 学习笔记之 --exchange partition

时间:2024-02-19 19:48:01浏览次数:28  
标签:00 01 1981 -- partition emp hiredate openGauss exchange

概念描述

MogDB 提供了从分区交换的功能,如单表转化到一个分区中
基本语法:ALTER TABLE...EXCHANGE PARTITION
数据库版本

测试验证

1、环境准备


miao=> select version();
version
--------------------------------------------------------------------------------------------------------------------------------------------------
(MogDB 2.1.1 build b5f25b20) compiled at 2022-03-21 14:42:30 commit 0 last mr on x86_64-unknown-linux-gnu, compiled by g++ (GCC) 7.3.0, 64-bit
(1 row)

2、创建测试表

CREATE TABLE emp_range
( empno NUMBER(8,0)
, ename VARCHAR2(10)
, job VARCHAR2(9)
, mgr NUMBER(4,0)
, hiredate DATE
, sal NUMBER(7,2)
, comm NUMBER(7,2)
, deptno NUMBER(8,0)
)
PARTITION BY RANGE (hiredate)
(PARTITION hiredate_1979 VALUES LESS THAN (TO_DATE('1980-01-01','YYYY-MM-DD')),
PARTITION hiredate_1980 VALUES LESS THAN (TO_DATE('1981-01-01','YYYY-MM-DD')),
PARTITION hiredate_1981 VALUES LESS THAN (TO_DATE('1982-01-01','YYYY-MM-DD')),
PARTITION hiredate_1982 VALUES LESS THAN (TO_DATE('1983-01-01','YYYY-MM-DD')),
PARTITION hiredate_1983 VALUES LESS THAN (TO_DATE('1984-01-01','YYYY-MM-DD')),
PARTITION hiredate_1984 VALUES LESS THAN (TO_DATE('1985-01-01','YYYY-MM-DD')),
PARTITION hiredate_1985 VALUES LESS THAN (TO_DATE('1986-01-01','YYYY-MM-DD')),
PARTITION hiredate_1986 VALUES LESS THAN (TO_DATE('1987-01-01','YYYY-MM-DD')),
PARTITION hiredate_1987 VALUES LESS THAN (TO_DATE('1988-01-01','YYYY-MM-DD')),
PARTITION hiredate_max VALUES LESS THAN (MAXVALUE))
;

 


openGauss=# insert into emp_1 select * from emp;
INSERT 0 14
openGauss=#
openGauss=#
openGauss=# select * from emp_1;
empno | ename | job | mgr | hiredate | sal | comm | deptno
-------+--------+-----------+------+---------------------+---------+---------+--------
7369 | SMITH | CLERK | 7902 | 1980-12-17 00:00:00 | 800.00 | | 20
7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 00:00:00 | 1600.00 | 300.00 | 30
7521 | WARD | SALESMAN | 7698 | 1981-02-22 00:00:00 | 1250.00 | 500.00 | 30
7566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975.00 | | 20
7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 00:00:00 | 1250.00 | 1400.00 | 30
7698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850.00 | | 30
7782 | CLARK | MANAGER | 7839 | 1981-06-09 00:00:00 | 2450.00 | | 10
7788 | SCOTT | ANALYST | 7566 | 1987-07-13 00:00:00 | 3000.00 | | 20
7839 | KING | PRESIDENT | | 1981-11-17 00:00:00 | 5000.00 | | 10
7844 | TURNER | SALESMAN | 7698 | 1981-09-08 00:00:00 | 1500.00 | 0.00 | 30
7876 | ADAMS | CLERK | 7788 | 1987-07-13 00:00:00 | 1100.00 | | 20
7900 | JAMES | CLERK | 7698 | 1981-12-03 00:00:00 | 950.00 | | 30
7902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000.00 | | 20
7934 | MILLER | CLERK | 7782 | 1982-01-23 00:00:00 | 1300.00 | | 10
7369 | SMITH | CLERK | 7902 | 1980-12-17 00:00:00 | 800.00 | | 20
7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 00:00:00 | 1600.00 | 300.00 | 30
7521 | WARD | SALESMAN | 7698 | 1981-02-22 00:00:00 | 1250.00 | 500.00 | 30
7566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975.00 | | 20
7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 00:00:00 | 1250.00 | 1400.00 | 30
7698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850.00 | | 30
7782 | CLARK | MANAGER | 7839 | 1981-06-09 00:00:00 | 2450.00 | | 10
7788 | SCOTT | ANALYST | 7566 | 1987-07-13 00:00:00 | 3000.00 | | 20
7839 | KING | PRESIDENT | | 1981-11-17 00:00:00 | 5000.00 | | 10
7844 | TURNER | SALESMAN | 7698 | 1981-09-08 00:00:00 | 1500.00 | 0.00 | 30
7876 | ADAMS | CLERK | 7788 | 1987-07-13 00:00:00 | 1100.00 | | 20
7900 | JAMES | CLERK | 7698 | 1981-12-03 00:00:00 | 950.00 | | 30
7902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000.00 | | 20
7934 | MILLER | CLERK | 7782 | 1982-01-23 00:00:00 | 1300.00 | | 10
(28 rows)

openGauss=#
openGauss=# select * from emp_range;
empno | ename | job | mgr | hiredate | sal | comm | deptno
-------+-------+-----+-----+----------+-----+------+--------
(0 rows)


3、交换分区操作


openGauss=# alter table emp_range exchange partition (hiredate_max) with table emp_1 VERBOSE;
ERROR: tables in ALTER TABLE EXCHANGE PARTITION must have the same number of indexs

错误原因: 表必须有相同数量的索引。

解决办法: 因是测试环境,删除索引。

4、问题处理

openGauss=# select * from pg_indexes where tablename = 'emp_range';
schemaname | tablename | indexname | tablespace | indexdef
------------+-----------+-----------+------------+------------------------------------------------------------------------------------------------------------------
public | emp_range | ind_emp2 | | CREATE INDEX ind_emp2 ON emp_range USING ubtree (empno) WITH (storage_type=USTORE) TABLESPACE pg_default
public | emp_range | ind_emp | | CREATE INDEX ind_emp ON emp_range USING ubtree (hiredate) LOCAL WITH (storage_type=USTORE) TABLESPACE pg_default
(2 rows)

openGauss=#
openGauss=# select * from pg_indexes where tablename = 'emp_1';
schemaname | tablename | indexname | tablespace | indexdef
------------+-----------+-----------+------------+----------
(0 rows)

openGauss=#
openGauss=# drop index ind_emp2;
DROP INDEX
openGauss=# drop index ind_emp;
DROP INDEX

5、交换分区操作


openGauss=# alter table emp_range exchange partition (hiredate_max) with table emp_1 VERBOSE;
ALTER TABLE
openGauss=# openGauss=# select * from emp_range partition (hiredate_1982);
empno | ename | job | mgr | hiredate | sal | comm | deptno
-------+--------+-------+------+---------------------+---------+------+--------
7934 | MILLER | CLERK | 7782 | 1982-01-23 00:00:00 | 1300.00 | | 10
7934 | MILLER | CLERK | 7782 | 1982-01-23 00:00:00 | 1300.00 | | 10
(2 rows)

openGauss=#

标签:00,01,1981,--,partition,emp,hiredate,openGauss,exchange
From: https://www.cnblogs.com/xinxin1222/p/18021800

相关文章

  • Qt QTabWidget显示隐藏tab页方法(setTabVisible)
    QT中QTabWidget在Qt5.15引入了setTabVisible方法低版本实现方法1//TabWidget2classTabWidget:publicQTabWidget3{4Q_OBJECT56public:78classwidgetTab{9public:10QStringtext;11QWidget*w......
  • MogDB 学习笔记之 -- truncate 属于dml语句
    概念描述验证create语句、alter语句、truncate语句、drop语句是属于ddl还是dml测试验证1、环境准备修改log_statement参数miao=#showlog_statement;log_statement---------------none(1row)miao=#ALTERDATABASEmiaoSETlog_statementTOddl;ALTERDATABA......
  • 安装MogHA
    一、关于MogHAMogHA是云和恩墨基于MogDB同步异步流复制技术自研的一款保障数据库主备集群高可用的企业级软件系统(适用于MogDB和openGauss数据库)MogHA能够自主探测故障实现故障转移,虚拟IP自动漂移等特性,使得数据库的故障持续时间从分钟级降到秒级(RPO=0,RTO<30s),确保数据......
  • MogDB 学习笔记之 -- PITR恢复
    概念描述背景信息当数据库崩溃或希望回退到数据库之前的某一状态时,MogDB的即时恢复功能(Point-In-TimeRecovery,简称PITR)可以支持恢复到备份归档数据之后的任意时间点。说明:PITR仅支持恢复到物理备份数据之后的某一时间点。仅主节点可以进行PITR恢复,备机需要进行全量build达......
  • password_encryption_type 和 pg_hba.conf 不匹配导致用户连不上
    问题概述xxx客户新上一套opengauss数据库,在测试中用户输入正确的密码,提示用户密码错误,导致用户被锁问题原因password_encryption_type和pg_hba.conf不匹配导致用户连不上模拟问题因没有opengauss的环境,测试环境选择Mogdb1、准备测试环境,修改password_encryption_type。......
  • java的getResource方法 总结一下 在Java中获取资源的时候,经常用到getResource和getRes
    java的getResource方法总结一下在Java中获取资源的时候,经常用到getResource和getResourceAsStream,本文总结一下这两种获取资源文件的路径差异1.前言在Java中获取资源的时候,经常用到getResource和getResourceAsStream,本文总结一下这两种获取资源文件的路径差异。2.Class.get......
  • 系统科学方法概论第三章读后感
    信息方法是一种研究方法,它运用信息的概念,将系统的运动过程看作是信息的传递和转换过程。这种方法完全撇开系统的具体运动形式,而是关注系统如何通过获取、传递、运用和存储信息来实现其目的。信息方法的特点是以信息为基础,从信息的整个流程进行综合考察,以获得对系统的整体性认识。......
  • oceanbase 社区版安装
    一、环境准备节点类别主机名IPOBSERVERobserver1192.168.3.41OBSERVERobserver2192.168.3.42OBSERVERobserver3192.168.3.43ocpocpserver192.168.3.47中控机obcontrol192.168.3.48二、名词解析中控机:存储Oceanbase数据库安装包和集群配置信......
  • mogdb的一主两备
    一、环境准备节点类别主机名IP主节点mogdb1192.168.3.68备节点1mogdb2192.168.3.69备节点2mogdb3192.168.3.70二、关闭防火墙和透明大页1、修改操作系统配置1)关闭SELINUX修改/etc/selinux/config文件中的“SELINUX”值为“disabled”2)关闭......
  • Codeforces Round 927 (Div. 3)
    CodeforcesRound927(Div.3)A-ThornsandCoins解题思路:出现连续两个障碍之前,所有金币都能拿到。代码:#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;usingpii=pair<ll,ll>;#definefifirst#definesesecondusingi128=__int128_t;......