分类: Oracle
2008-04-21 14:43:43
STEP1、建立表的各个分区的表空间: CREATE TABLESPACE ts_sale1999q1 DATAFILE ‘/u1/oradata/sales/sales1999_q1.dat’ SIZE 100M DEFAULT STORAGE (INITIAL 30m NEXT 30m MINEXTENTS 3 PCTINCREASE 0) CREATE TABLESPACE ts_sale1999q2 DATAFILE ‘/u1/oradata/sales/sales1999_q2.dat’ SIZE 100M DEFAULT STORAGE (INITIAL 30m NEXT 30m MINEXTENTS 3 PCTINCREASE 0) CREATE TABLESPACE ts_sale1999q3 DATAFILE ‘/u1/oradata/sales/sales1999_q3.dat’ SIZE 100M DEFAULT STORAGE (INITIAL 30m NEXT 30m MINEXTENTS 3 PCTINCREASE 0) CREATE TABLESPACE ts_sale1999q4 DATAFILE ‘/u1/oradata/sales/sales1999_q4.dat’ SIZE 100M DEFAULT STORAGE (INITIAL 30m NEXT 30m MINEXTENTS 3 PCTINCREASE 0) STEP2、建立基于分区的表: CREATE TABLE sales (invoice_no NUMBER, ... sale_date DATE NOT NULL ) PARTITION BY RANGE (sale_date) (PARTITION sales1999_q1 VALUES LESS THAN (TO_DATE(‘1999-04-01’,’YYYY-MM-DD’) TABLESPACE ts_sale1999q1, PARTITION sales1999_q2 VALUES LESS THAN (TO_DATE(‘1999-07-01’,’YYYY-MM-DD’) TABLESPACE ts_sale1999q2, PARTITION sales1999_q3 VALUES LESS THAN (TO_DATE(‘1999-10-01’,’YYYY-MM-DD’) TABLESPACE ts_sale1999q3, PARTITION sales1999_q4 VALUES LESS THAN (TO_DATE(‘2000-01-01’,’YYYY-MM-DD’) TABLESPACE ts_sale1999q4 );2 、分区表的扩容:
STEP1、建立表空间: CREATE TABLESPACE ts_sale2000q1 DATAFILE ‘/u1/oradata/sales/sales2000_q1.dat’ SIZE 130M DEFAULT STORAGE (INITIAL 40m NEXT 40m MINEXTENTS 3 PCTINCREASE 0) 其他表空间ts_sale2000q2,ts_sale2000q3,ts_sales2000q4如法炮制。 STEP2、为表添加表空间: ALTER TABLE sales ADD PARTITION sales2000_q1 VALUES LESS THAN (TO_DATE(‘2000-04-01’,’YYYY-MM-DD’) TABLESPACE ts_sale2000q1; 其他分区sales2000_q1,sales2000_q1,sales2000_q1如法炮制。3 、删除不必要的分区:
STEP1、DROP 分区: ALTER TABLE sales DROP PARTION sales1999_q1; ALTER TABLE sales DROP PARTION sales1999_q2; ALTER TABLE sales DROP PARTION sales1999_q3; ALTER TABLE sales DROP PARTION sales1999_q4; STEP2、利用操作系统的工具删除以上表空间占用的文件 (表空间基于裸设备无须次步),UNIX系统为例: oracle$ rm /u1/oradata/sales/sales1999_q1.dat oracle$ rm /u1/oradata/sales/sales1999_q2.dat oracle$ rm /u1/oradata/sales/sales1999_q3.dat oracle$ rm /u1/oradata/sales/sales1999_q4.dat4 、分区的其他操作:
STEP1、按(1)的方法建立两个分区的表空间ts_sales1999q4p1, ts_sales1999q4p2; STEP2、给表添加两个分区sales1999_q4_p1,sales1999_q4_p2; STEP3、分裂分区: ALTER TABLE sales SPLIT PARTITON sales1999_q4 AT TO_DATE (‘1999-11-01’,’YYYY-MM-DD’) INTO (partition sales1999_q4_p1, partition sales1999_q4_p2)5 、查看分区信息:
DBA要查看表的分区信息,可查看数据字典USER_EXTENTS,操作如下: SVRMGRL>SELECT * FROM user_extents WHERE SEGMENT_NAME=’SALES’; SEGMENT_NA PARTITION_ SEGMENT_TYPE TABLESPACE ---------- ------------ --------------- -------------- SALES SALES1999_Q1 TABLE PARTITION TS_SALES1999Q1 SALES SALES1999_Q2 TABLE PARTITION TS_SALES1999Q2 SALES SALES1999_Q3 TABLE PARTITION TS_SALES1999Q3 SALES SALES1999_Q4 TABLE PARTITION TS_SALES1999Q4 SALES SALES2000_Q1 TABLE PARTITION TS_SALES1999Q1 SALES SALES2000_Q2 TABLE PARTITION TS_SALES1999Q2 SALES SALES2000_Q3 TABLE PARTITION TS_SALES1999Q3 SALES SALES2000_Q4 TABLE PARTITION TS_SALES1999Q45 、EXPORT分区:
oracle$ exp sales/sales_password tables=sales:sales1999_q1 rows=Y file=sales1999_q1.dmp oracle$ exp sales/sales_password tables=sales:sales1999_q2 rows=Y file=sales1999_q2.dmp oracle$ exp sales/sales_password tables=sales:sales1999_q3 rows=Y file=sales1999_q3.dmp oracle$ exp sales/sales_password tables=sales:sales1999_q4 rows=Y file=sales1999_q4.dmp6 、IMPORT分区:
STEP1、建立表的1999年的四个表空间和相应的分区,参照(2); STEP2、导入数据: oracle$ imp sales/sales_password FILE =sales1999_q1.dmp TABLES = (sales:sales1999_q1) IGNORE=y oracle$ imp sales/sales_password FILE =sales1999_q2.dmp TABLES = (sales:sales1999_q2) IGNORE=y oracle$ imp sales/sales_password FILE =sales1999_q3.dmp TABLES = (sales:sales1999_q3) IGNORE=y oracle$ imp sales/sales_password FILE =sales1999_q4.dmp TABLES = (sales:sales1999_q4) IGNORE=y