一、建HASH分区 特点: hash:a)分区中数据量一致,每个分区承担的业务几乎压力是相同的,采用hash运算,运行速度相对于range要慢一些; b)不可以进行分区备份,因为顺序都是凌乱的; range a)分区中数据量无法一致,随着数量的差异,每个分区承担的业务压力不同; b)可以进行部分分区备份,保证活跃数据安全,进行数据的滚动更新 CREATE TABLE SALES_DATA ( TICKET_NO NUMBER, SALE_YEAR INT NOT NULL, SALE_MONTH INT NOT NULL, SALE_DAY INT NOT NULL) PARTITION BY HASH(SALE_YEAR) PARTITIONS 8 STORE IN (TBS1,TBS2,TBS3,TBS4); 查看分区表、表分区、select总数量 插入值 再查看分区表、表分区、select总数量 增加表分区 alter table SALES_data add partition tablespace tbs5; tablespace tbs5 是指定表分区存放在tbs5的表空间里 报错: ERROR at line 1: ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired 有会话占用资源,应该是表被锁了,需要重启数据库 关掉数据库,重新启动,报错: SQL> startup nomount ORA-00845: MEMORY_TARGET not supported on this system SQL>create pfile from spfile;-->创建pfile文件 数据库启动成功 增加表分区成2 二、创建list分区 CREATE TABLE b2c_orders_parts (serial_id NUMBER(10,0), goods_id NUMBER(10,0),unit_price NUMBER(12,2), quantity NUMBER(12,2),subtotal NUMBER(12,2), city varchar2(30), create_date date) PARTITION BY list (city) (PARTITION p_bj VALUES ('BEIJING'), PARTITION p_sh VALUES ('SHANGHAI'), PARTITION p_gd VALUES ('GUANGDONG'), PARTITION p_ln VALUES ('LIAONING'), PARTITION p_sd VALUES ('SHANDONG'), PARTITION p_other VALUES (DEFAULT)); 查看分区表、表分区、select总数量 插入值 再查看分区表、表分区、select总数量功 三、创建复合分区 CREATE TABLE ords (ordid NUMBER, orderdate DATE, productid NUMBER,quantity NUMBER) PARTITION BY RANGE(orderdate) SUBPARTITION BY HASH(productid) SUBPARTITIONS 8 STORE IN (tbs1,tbs2,tbs3,tbs4) (PARTITION q2009 VALUES LESS THAN(to_date('2010-01-01','yyyy-mm-dd')) ,PARTITION q2010 VALUES LESS THAN(to_date('2011-01-01','yyyy-mm-dd')) ,PARTITION q2011 VALUES LESS THAN(to_date('2012-01-01','yyyy-mm-dd')) ,PARTITION q2012 VALUES LESS THAN(to_date('2013-01-01','yyyy-mm-dd'))); 查询第一层表分区情况,DBA_tab_partitions SELECT TABLE_OWNER,TABLE_NAME,PARTITION_NAME,TABLESPACE_NAME,HIGH_VALUE,INTERVAL FROM DBA_TAB_PARTITIONS WHERE TABLE_NAME='ORDS' ; 查询第二层表分区情况,dba_tab_subpartitions 数量和存储情况以这个为主 SELECT TABLE_OWNER,TABLE_NAME,PARTITION_NAME,SUBPARTITION_NAME,TABLESPACE_NAME FROM DBA_TAB_SUBPARTITIONS WHERE TABLE_NAME='ORDS'; 四、创建间隔分区 CREATE TABLE SALES_INTERVAL PARTITION BY RANGE (time_id) INTERVAL (NUMTOYMINTERVAL(1,'month')) STORE IN (tbs1,tbs2,tbs3,tbs4) ( PARTITION P1 values less than (TO_DATE('1-1-2002','dd-mm-yyyy')), PARTITION P2 values less than (TO_DATE('1-1-2003','dd-mm-yyyy')), PARTITION P3 values less than (TO_DATE('1-1-2004','dd-mm-yyyy'))) AS SELECT * FROM SH.SALES WHERE TIME_ID < TO_DATE('1-1-2004','dd-mm-yyyy'); 问题: ERROR at line 1: ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
这个报错我是通过重启数据库解决的,请问老师还有没有其他解决方法?
|