Oracle數據遷移及Oracle全局索引變動爲分區索引

1.在新環境數據庫用戶下執行建須要遷移表的建表語句

 CREATE TABLE "T_TSPS_CONDUCT_AUDITS" (
  "C_ID" VARCHAR2(64 BYTE), 
  "N_PERSON_ID" NUMBER, 
  "C_CODE" VARCHAR2(64 BYTE), 
  "C_NAME" VARCHAR2(64 BYTE), 
  "C_DEPT" VARCHAR2(64 BYTE), 
  "N_LOG_TIME" NUMBER, 
  "C_LOG_TYPE" NUMBER, 
  "C_CONTENT" VARCHAR2(1024 BYTE), 
  "C_RESULT" VARCHAR2(2 BYTE), 
  "C_SN" VARCHAR2(128 BYTE), 
  "N_DEPT_ID" NUMBER, 
  "C_BLACK_FLAG" VARCHAR2(2 BYTE), 
  "C_CREATE_TIME" DATE, 
  "C_IDENTIFIER" VARCHAR2(36 BYTE)
) PARTITION BY RANGE (C_CREATE_TIME)  interval (numtodsinterval (1,'DAY'))
(
 PARTITION audit_p180613 VALUES LESS THAN (TO_DATE('2018-6-13', 'yyyy-mm-dd'))
 );

   COMMENT ON COLUMN "T_TSPS_CONDUCT_AUDITS"."C_ID" IS '主鍵';

   COMMENT ON COLUMN "T_TSPS_CONDUCT_AUDITS"."N_PERSON_ID" IS '人員id';

   COMMENT ON COLUMN "T_TSPS_CONDUCT_AUDITS"."C_CODE" IS '人員編碼';

   COMMENT ON COLUMN "T_TSPS_CONDUCT_AUDITS"."C_NAME" IS '人員姓名';

   COMMENT ON COLUMN "T_TSPS_CONDUCT_AUDITS"."C_DEPT" IS '所屬部門';

   COMMENT ON COLUMN "T_TSPS_CONDUCT_AUDITS"."N_LOG_TIME" IS '日誌上報時間';

   COMMENT ON COLUMN "T_TSPS_CONDUCT_AUDITS"."C_LOG_TYPE" IS '日誌類型 1:網絡2:進程3:外設4:安裝文件5:登錄操做系統10:url日誌類型 11:單流量日誌類型12:批量流量日誌類型';

   COMMENT ON COLUMN "T_TSPS_CONDUCT_AUDITS"."C_CONTENT" IS '操做內容';

   COMMENT ON COLUMN "T_TSPS_CONDUCT_AUDITS"."C_RESULT" IS '0:被禁止,1:成功,2:其它';

   COMMENT ON COLUMN "T_TSPS_CONDUCT_AUDITS"."C_SN" IS '證書sn';

   COMMENT ON COLUMN "T_TSPS_CONDUCT_AUDITS"."N_DEPT_ID" IS '部門id';

   COMMENT ON COLUMN "T_TSPS_CONDUCT_AUDITS"."C_IDENTIFIER" IS '身份證號';

 CREATE UNIQUE INDEX "T_TSPS_CONDUCT_AUDITS_PK" ON "T_TSPS_CONDUCT_AUDITS" ("C_ID");

2.在新服務上創建與老闆數據庫的服務通訊

create public database link lnDblink 
connect to topsec 
identified by manager 
using '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.106.12.71)(PORT=4521)))
(CONNECT_DATA=(SERVICE_NAME=ora11g)))';

解釋:此SQL在新數據庫服務上執行 topsec :老服務數據庫用戶名 manager :老服務數據庫用戶密碼 HOST:老數據庫地址 PORT:老數據庫端口 SERVICE_NAME:老數據庫服務名數據庫

3.遷移數據

insert into T_TSPS_CONDUCT_AUDITS select * from topsec.T_TSPS_CONDUCT_AUDITS@lnDblink;

4.全局索引改成分區索引

a.-- 查詢出指定用戶(TOPSEC_MNHLJ)下,指定表(T_TSPS_CONDUCT_AUDITS) 上的索引網絡

select * from dba_indexes where owner='TOPSEC_MNHLJ' and table_name='T_TSPS_CONDUCT_AUDITS';

b.-- 刪除以上查詢到的索引ide

DROP INDEX "TOPSEC_MNHLJ"."T_TSPS_CONDUCT_AUDITS_PCODE";
DROP INDEX "TOPSEC_MNHLJ"."T_TSPS_CONDUCT_AUDITS_PID";
DROP INDEX "TOPSEC_MNHLJ"."T_TSPS_CONDUCT_AUDITS_INDEX1";

c.-- 刪除主鍵約束後,刪除主鍵對應的索引編碼

ALTER TABLE "TOPSEC_MNHLJ"."T_TSPS_CONDUCT_AUDITS" DROP CONSTRAINT T_TSPS_CONDUCT_AUDITS_PK;
DROP INDEX "TOPSEC_MNHLJ"."T_TSPS_CONDUCT_AUDITS_PK";

d.-- 依次建立所需的分區索引url

CREATE INDEX "TOPSEC_MNHLJ"."IDX_TTCA_CTIME_G" ON "TOPSEC_MNHLJ"."T_TSPS_CONDUCT_AUDITS" ("C_CREATE_TIME", 0) LOCAL NOLOGGING
PARALLEL 8;

CREATE INDEX "TOPSEC_MNHLJ"."T_TSPS_CONDUCT_AUDITS_PID" ON "TOPSEC_MNHLJ"."T_TSPS_CONDUCT_AUDITS" ("N_PERSON_ID") LOCAL NOLOGGING
PARALLEL 8;

CREATE INDEX "TOPSEC_MNHLJ"."T_TSPS_CONDUCT_AUDITS_PK" ON "TOPSEC_MNHLJ"."T_TSPS_CONDUCT_AUDITS" ("C_ID") LOCAL NOLOGGING
PARALLEL 8;

e.-- 取消新建索引上的並行度spa

alter index "TOPSEC_MNHLJ"."IDX_TTCA_CTIME_G" noparallel;
alter index "TOPSEC_MNHLJ"."T_TSPS_CONDUCT_AUDITS_PID" noparallel;
alter index "TOPSEC_MNHLJ"."T_TSPS_CONDUCT_AUDITS_PK" noparallel;

f.-- 查看分區索引是否建立成功操作系統

select * from dba_part_indexes where owner='TOPSEC_MNHLJ' and table_name='T_TSPS_CONDUCT_AUDITS';
相關文章
相關標籤/搜索