Oracle 11.2.0.4 数据泵expdp导出含CLOB字段(basicfile)的表超级慢的问题
Tags: basicfileCLOBexpdpOraclesecurefile数据泵
简介
在 11.2.0.4 上 expdp导出含有CLOB字段的大表时会非常慢,而且可能会发生ora-01555错误。该错误的解决办法见:https://www.xmmup.com/oracleshujubengexpdpdaochubaoora-01555heora-22924.html#ke_neng_yuan_yin_er ,但是导出仍然会很慢,解决办法只能是重建表,然后修改存储属性STORE AS securefile
,再进行导出才会解决慢的问题。
Oracle 11g专门针对LOB字段的新特性securefile,这是在11g推出的新的LOB存储模式,之前的版本都是以basicfile方式存储LOB字段,securefile于basicfile相比,对LOB的读取和写入操作的效率均有明显提高,但却需要占用更多的磁盘空间,但也多的有限,基本可以忽略不计。在11g版本,默认的LOB存储模式还是basicfile,如果使用securefile,需要在建表的时候指定或者数据库securefile相关的参数才可以,个人建议LOB都以securefile存储。
启用SecureFiles 存储
使用DB_SECUREFILE 初始化参数,数据库管理员(DBA) 可确定SecureFiles 的使用情况,其中有效值为:
• ALWAYS :尝试将所有LOB 创建为SecureFile LOB,但是仅可将自动段空间管理(ASSM) 表空间外的任何 LOB 创建为BasicFile LOB
• FORCE:强制将所有LOB 创建为SecureFile LOB
• PERMITTED:允许创建SecureFiles (默认值)
• NEVER:禁止创建SecureFiles
• IGNORE :禁止创建SecureFiles ,并忽略使用SecureFiles 选项强制创建BasicFiles 而导致的任何错误
如果指定了NEVER,则任何指定为SecureFiles 的LOB 均被创建为BasicFiles。如果对BasicFiles 使用任何SecureFiles 特定的存储选项和功能(如压缩、加密和取消重复),则会导致异常错误。将对任何未指定的存储选项使用BasicFiles 默认值。如果指定了ALWAYS ,则系统中创建的所有LOB 均会被创建为SecureFiles 。必须在ASSM 表空间中创建LOB ,否则会发生错误。将忽略所有指定的BasicFiles 存储选项。可以使用
ALTER SYSTEM 命令更改所有存储的SecureFiles 默认值,如幻灯片中所示。也可以通过单击“Server (服务器)”选项卡中的“Initialization Parameters (初始化参数)”链接来使用Enterprise Manager 设置参数。
修改参数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | SQL> show parameter db_securefile NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_securefile string PERMITTED SQL> alter system set db_securefile=xxxxxx; alter system set db_securefile=xxxxxx * ERROR at line 1: ORA-00096: invalid value XXXXXX for parameter db_securefile, must be from among FORCE, IGNORE, ALWAYS, PERMITTED, NEVER SQL> alter system set db_securefile=ALWAYS; System altered. SQL> show parameter db_securefile NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_securefile string ALWAYS SQL> |
Evaluate the following command:
SQL>ALTER SYSTEM SET db_securefile = 'IGNORE';
What is the impact of this setting on the usage of SecureFiles?
A. It forces BasicFiles to be created even if the SECUREFILE option is specified to create the LOB.
B. It forces SecureFiles to be created even if the BASICFILE option is specified to create the LOB.
C. It does not allow the creation of SecureFiles and generates an error if the SECUREFILE option is
specified to create the LOB.
D. It ignores the SECUREFILE option only if a Manual Segment Space Management tablespace is used and creates a BasicFile.
Answer: A
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | [oracle@oarac1 ~]$ expdp \'/ AS SYSDBA\' directory=D1 dumpfile=TEST.dmp EXCLUDE=STATISTICS tables="LHRLOGY"."LHRAFLOW_XXTABCDLOG" CLUSTER=N COMPRESSION=ALL Export: Release 11.2.0.4.0 - Production on Sun Nov 27 09:55:34 2022 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Starting "SYS"."SYS_EXPORT_TABLE_01": "/******** AS SYSDBA" directory=D1 dumpfile=TEST.dmp EXCLUDE=STATISTICS tables=LHRLOGY.LHRAFLOW_XXTABCDLOG CLUSTER=N COMPRESSION=ALL Estimate in progress using BLOCKS method... Processing object type TABLE_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 56.92 GB Processing object type TABLE_EXPORT/TABLE/TABLE Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX Processing object type TABLE_EXPORT/TABLE/TRIGGER . . exported "LHRLOGY"."LHRAFLOW_XXTABCDLOG" 11.25 GB 31961861 rows Master table "SYS"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SYS.SYS_EXPORT_TABLE_01 is: /data/TEST.dmp Job "SYS"."SYS_EXPORT_TABLE_01" successfully completed at Sun Nov 27 10:33:39 2022 elapsed 0 00:38:04 |
获取表结构:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | SQL> set long 9999 SQL> SQL> SELECT DBMS_METADATA.GET_DDL(U.OBJECT_TYPE, U.OBJECT_NAME,U.owner) 2 FROM DBA_OBJECTS U WHERE U.OBJECT_TYPE IN ('TABLE', 'INDEX', 'PROCEDURE', 'FUNCTION','PACKAGE','TRIGGER') 3 AND U.OBJECT_NAME='LHRAFLOW_XXTABCDLOG' 4 AND U.owner='LHRLOGY'; DBMS_METADATA.GET_DDL(U.OBJECT_TYPE,U.OBJECT_NAME,U.OWNER) -------------------------------------------------------------------------------- CREATE TABLE "LHRLOGY"."LHRAFLOW_XXTABCDLOG" ( "REQUESTID" NUMBER(*,0), "SIGNDOCIDS" VARCHAR2(1000), "SIGNWORKFLOWIDS" VARCHAR2(1000), "RECEIVEDPERSONS" CLOB, "ISMOBILE" CHAR(1), "TMPHANDWRITTENSIGN" NUMBER(*,0), "SPEECHATTACHMENT" NUMBER(*,0), "RECEIVEDPERSONIDS" CLOB, "REMARKLOCATION" VARCHAR2(1000), "ISSUBMITDIRECT" CHAR(1), "REMARKQUOTE" CLOB, "FULLTEXTANNOTATION" VARCHAR2(1000), "SPEECHATTACHMENTE9" VARCHAR2(1000), "UUID" VARCHAR2(100), "REMARK" CLOB, "HANDWRITTENSIGN" VARCHAR2(300), "OPERATORSUB" NUMBER(*,0), "OPERATORJOB" NUMBER(*,0), "ISROBOTNODE" CHAR(1), "SECLEVEL" VARCHAR2(10) ) SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 1016709120 NEXT 516096 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "LHRLOGY" LOB ("RECEIVEDPERSONS") STORE AS BASICFILE ( TABLESPACE "LHRLOGY" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 516096 NEXT 516096 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) LOB ("RECEIVEDPERSONIDS") STORE AS BASICFILE ( TABLESPACE "LHRLOGY" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 516096 NEXT 516096 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) LOB ("REMARKQUOTE") STORE AS BASICFILE ( TABLESPACE "LHRLOGY" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) LOB ("REMARK") STORE AS BASICFILE ( TABLESPACE "LHRLOGY" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) |
表的大小:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | SQL> set line 1000 SQL> SELECT 2 (SELECT trunc(SUM(S.BYTES)/1024/1024/1024) 3 FROM DBA_SEGMENTS S 4 WHERE S.OWNER = UPPER('LHRLOGY') AND 5 (S.SEGMENT_NAME = UPPER('LHRAFLOW_XXTABCDLOG'))) as tbsize_g, 6 (SELECT trunc(SUM(S.BYTES)/1024/1024/1024) 7 FROM DBA_SEGMENTS S, DBA_LOBS L 8 WHERE S.OWNER = UPPER('LHRLOGY') AND 9 (L.SEGMENT_NAME = S.SEGMENT_NAME AND L.TABLE_NAME = UPPER('LHRAFLOW_XXTABCDLOG') AND L.OWNER = UPPER('LHRLOGY'))) as lobsize_g, 10 (SELECT trunc(SUM(S.BYTES)/1024/1024/1024) 11 FROM DBA_SEGMENTS S, DBA_INDEXES I 12 WHERE S.OWNER = UPPER('LHRLOGY') AND 13 (I.INDEX_NAME = S.SEGMENT_NAME AND I.TABLE_NAME = UPPER('LHRAFLOW_XXTABCDLOG') AND INDEX_TYPE = 'LOB' AND I.OWNER = UPPER('LHRLOGY'))) as lobindexsize_g , 14 (select count(*) from LHRLOGY.LHRAFLOW_XXTABCDLOG) 15 FROM DUAL; TBSIZE_G LOBSIZE_G LOBINDEXSIZE_G (SELECTCOUNT(*)FROMLHRLOGY.LHRAFLOW_XXTABCDLOG) ---------- ---------- -------------- ----------------------------------------------- 15 41 0 31961861 |
可见,表才15g,但是clob字段就41g。
重新建立临时表,将STORE AS BASICFILE
修改为STORE AS securefile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | CREATE TABLE "LHRLOGY"."TEST" ( "REQUESTID" NUMBER(*,0), "WORKFLOWID" NUMBER(*,0), "SIGNWORKFLOWIDS" VARCHAR2(1000), "RECEIVEDPERSONS" CLOB, "ISMOBILE" CHAR(1), "TMPHANDWRITTENSIGN" NUMBER(*,0), "SPEECHATTACHMENT" NUMBER(*,0), "RECEIVEDPERSONIDS" CLOB, "REMARKLOCATION" VARCHAR2(1000), "ISSUBMITDIRECT" CHAR(1), "REMARKQUOTE" CLOB, "FULLTEXTANNOTATION" VARCHAR2(1000), "SPEECHATTACHMENTE9" VARCHAR2(1000), "UUID" VARCHAR2(100), "REMARK" CLOB, "HANDWRITTENSIGN" VARCHAR2(300), "OPERATORSUB" NUMBER(*,0), "OPERATORJOB" NUMBER(*,0), "ISROBOTNODE" CHAR(1), "SECLEVEL" VARCHAR2(10) ) SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 1016709120 NEXT 516096 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "LHRLOGY" LOB ("RECEIVEDPERSONS") STORE AS securefile ( TABLESPACE "LHRLOGY" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 516096 NEXT 516096 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) LOB ("RECEIVEDPERSONIDS") STORE AS securefile ( TABLESPACE "LHRLOGY" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 516096 NEXT 516096 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) LOB ("REMARKQUOTE") STORE AS securefile ( TABLESPACE "LHRLOGY" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) LOB ("REMARK") STORE AS securefile ( TABLESPACE "LHRLOGY" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)); |
然后导入数据:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | [oracle@oarac1 ~]$ impdp \'/ AS SYSDBA\' directory=D1 dumpfile=LHRAFLOW_XXTABCDLOG.dmp FULL=Y CLUSTER=N table_exists_action=APPEND REMAP_TABLE=LHRLOGY.LHRAFLOW_XXTABCDLOG:LHRLOGY.TEST1 Import: Release 11.2.0.4.0 - Production on Sun Nov 27 11:50:31 2022 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SYS"."SYS_IMPORT_FULL_05" successfully loaded/unloaded Starting "SYS"."SYS_IMPORT_FULL_05": "/******** AS SYSDBA" directory=D1 dumpfile=LHRAFLOW_XXTABCDLOG.dmp FULL=Y CLUSTER=N table_exists_action=APPEND REMAP_TABLE=LHRLOGY.LHRAFLOW_XXTABCDLOG:LHRLOGY.TEST1 Processing object type TABLE_EXPORT/TABLE/TABLE Processing object type TABLE_EXPORT/TABLE/TABLE_DATA ^C Import> status Job: SYS_IMPORT_FULL_05 Operation: IMPORT Mode: FULL State: EXECUTING Bytes Processed: 0 Current Parallelism: 1 Job Error Count: 0 Dump File: /data/LHRAFLOW_XXTABCDLOG.dmp Worker 1 Status: Process Name: DW00 State: EXECUTING Object Schema: LHRLOGY Object Name: LHRAFLOW_XXTABCDLOG Object Type: TABLE_EXPORT/TABLE/TABLE_DATA Completed Objects: 1 Completed Rows: 19,864,843 Completed Bytes: 12,089,455,616 Percent Done: 62 Worker Parallelism: 1 Import> status Job: SYS_IMPORT_FULL_05 Operation: IMPORT Mode: FULL State: EXECUTING Bytes Processed: 0 Current Parallelism: 1 Job Error Count: 0 Dump File: /data/LHRAFLOW_XXTABCDLOG.dmp Worker 1 Status: Process Name: DW00 State: EXECUTING Object Schema: LHRLOGY Object Name: LHRAFLOW_XXTABCDLOG Object Type: TABLE_EXPORT/TABLE/TABLE_DATA Completed Objects: 1 Completed Rows: 21,615,289 Completed Bytes: 12,089,455,616 Percent Done: 67 Worker Parallelism: 1 Import> |
等待导入完成后,然后继续进行导出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | [oracle@oarac1 ~]$ expdp \'/ AS SYSDBA\' directory=D1 dumpfile=TEST.dmp EXCLUDE=STATISTICS tables="LHRLOGY"."TEST" CLUSTER=N COMPRESSION=ALL Export: Release 11.2.0.4.0 - Production on Sun Nov 27 11:55:34 2022 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Starting "SYS"."SYS_EXPORT_TABLE_01": "/******** AS SYSDBA" directory=D1 dumpfile=TEST.dmp EXCLUDE=STATISTICS tables=LHRLOGY.TEST CLUSTER=N COMPRESSION=ALL Estimate in progress using BLOCKS method... Processing object type TABLE_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 56.92 GB Processing object type TABLE_EXPORT/TABLE/TABLE Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX Processing object type TABLE_EXPORT/TABLE/TRIGGER . . exported "LHRLOGY"."TEST" 11.25 GB 31961861 rows Master table "SYS"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SYS.SYS_EXPORT_TABLE_01 is: /data/TEST.dmp Job "SYS"."SYS_EXPORT_TABLE_01" successfully completed at Sun Nov 27 12:02:39 2022 elapsed 0 00:06:04 |
可见,速度提升很快。
DataPump Export (EXPDP) Is Taking Long time To Export Tables With BASICFILES (Doc ID 1595380.1)
APPLIES TO:
Oracle Database - Enterprise Edition - Version 11.2.0.3 to 12.1.0.2 [Release 11.2 to 12.1]
Oracle Database Cloud Schema Service - Version N/A and later
Oracle Database Exadata Cloud Machine - Version N/A and later
Oracle Database Exadata Express Cloud Service - Version N/A and later
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Information in this document applies to any platform.
SYMPTOMS
Datapump export is taking more than the double time after a database upgrade from 10.2.0.4 to 11.2.0.3
In our example, one table with a LOB column takes more than 18 hours. The rest of the objects are exported within 30 mins.
Here is the current size of the table with a blob column based on the output of the export..
. . exported "
CHANGES
Database was upgraded from 10.2.0.4.0 to 11.2.0.3.0
CAUSE
Testing internally made clear that a huge decrease in time could be achieved by transform of BasicFiles into SecureFiles even if the parallel option is still not usable.
The export of big table with clob (as SecureFile) doesn't still work in parallel. The confirmation is received from DEV in Bug 19345593 - EXPORT OF CLOB AD SECUREFILE NOT DONE IN PARALLEL, closed as not a bug due to: exporting a table with LOBs is still something that Data Pump does not allow to use parallel DML (PDML). It is being worked at and looking to fix it in 12.2 release. The unpublished documentation Bug 21256503 : DATAPUMP CAN'T USE PARALLEL DML FOR SECUREFILE LOBS, was created in order to correct 11gR2 Utilities documentation with this information.
SOLUTION
In our internal testing, the time for the export was reduced from 30 minutes to 6 minutes for 20 GB of data.
Basicfiles: 20.53 GB 8752 rows => 10:38:17 - 11:09:32 around 30 minutes
Securefiles: 20.53 GB 8752 rows => 14:30:51 - 14:36:41 around 6 minutes
The solution is transform the table to SecureFiles and then redo the export process
Here is the output of the DDL using SecureFiles: (example)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | CREATE TABLE <TABLE_NAME> ( "<COLUMN1>" CHAR(36 BYTE) DEFAULT (' ') NOT NULL ENABLE, "<COLUMN2>" BLOB, "<COLUMN3>" DATE, "<COLUMN4>" VARCHAR2(254 BYTE) ) SEGMENT CREATION IMMEDIATE PCTFREE 30 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 114688 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "<TABLESPACE_NAME>" LOB ("<COLUMN2>") STORE AS securefile (tablespace "<TABLESPACE_NAME>" cache STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)); |
The idea is do an export, recreate the table using SecureFiles and then do an import.
Note: Online redefinition can be used to change a lob from BasicFile to SecureFiles as decribed in Note 728758.1 - HOW TO ONLINE CONVERT TO/FROM SECUREFILES FROM/TO BASICFILES.
REFERENCES
BUG:17518284 - EXPDP IS TAKING A LOT OF TIME AFTER UPGRADED FROM 10.2.0.4 TO 11.2.0.3
NOTE:728758.1 - HOW TO ONLINE CONVERT TO/FROM SECUREFILES FROM/TO BASICFILES
HOW TO ONLINE CONVERT TO/FROM SECUREFILES FROM/TO BASICFILES (Doc ID 728758.1)
APPLIES TO:
Oracle Database - Enterprise Edition - Version 12.2.0.1 to 12.2.0.1 [Release 12.2]
Oracle Database - Enterprise Edition - Version 11.1.0.6 to 11.2.0.2 [Release 11.1 to 11.2]
Oracle Database - Enterprise Edition - Version 11.2.0.3 to 11.2.0.3 [Release 11.2]
Oracle Database Cloud Schema Service - Version N/A and later
Oracle Database Exadata Cloud Machine - Version N/A and later
Information in this document applies to any platform.
GOAL
This note will demonstrate how to convert BasicFiles to SecureFiles and SecureFiles to BasicFiles
SOLUTION
The following reference discusses conversion TO Securefiles FROM BasicFIles ...
Oracle Database SecureFiles and Large Objects Developer's Guide 11g Release 1 (11.1) Part Number B28393-03
4 Using Oracle SecureFiles
Example 4-1 Example of Online Redefinition
The reverese of the method may be used to convert from SecureFiles
The following example is a modified version of the example from the above reference
Convert to SecureFiles from Basicfiles
connect / as sysdba
create user pm identified by pm;
GRANT EXECUTE ON DBMS_REDEFINITION TO pm;
GRANT ALTER ANY TABLE TO pm;
GRANT DROP ANY TABLE TO pm;
GRANT LOCK ANY TABLE TO pm;
GRANT CREATE ANY TABLE TO pm;
GRANT SELECT ANY TABLE TO pm;
GRANT CREATE SESSION TO pm;
ALTER USER pm QUOTA UNLIMITED ON
--Privileges required to perform cloning of dependent objects.
GRANT CREATE ANY TRIGGER TO pm;
GRANT CREATE ANY INDEX TO pm;
CONNECT pm/pm
-- CREATE OUR TABLE TO BE CONVERTED TO SECUREFILE
CREATE TABLE cust (
c_id NUMBER PRIMARY KEY,
c_zip NUMBER,
c_name VARCHAR(30) DEFAULT NULL,
c_lob CLOB
);
-- INSERT A ROW INTO THIS TABLE
INSERT INTO cust VALUES (1, 94065, 'hhh', 'ttt');
COMMIT;
-- CREATE OUR 'INTERIM' TABLE
CREATE TABLE cust_int (
c_id NUMBER NOT NULL,
c_zip NUMBER,
c_name VARCHAR(30) DEFAULT NULL,
c_lob CLOB
) LOB(c_LOB) STORE AS SECUREFILE (NOCACHE FILESYSTEM_LIKE_LOGGING);
-- START THE REDEFINITION
DECLARE
col_mapping VARCHAR2(1000);
BEGIN
-- map all the columns in the interim table to the original table
col_mapping := 'c_id c_id , '|| 'c_zip c_zip , '|| 'c_name c_name, '|| 'c_lob c_lob';
DBMS_REDEFINITION.START_REDEF_TABLE('pm', 'cust', 'cust_int', col_mapping);
END;
/
-- COPY THE CONSTRAINTS FROM OUR ORIGINAL TABLE ... TO THE INTERIM TABLE
DECLARE
error_count pls_integer := 0;
BEGIN
DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS('pm', 'cust', 'cust_int', dbms_redefinition.cons_orig_params, TRUE,TRUE,TRUE,FALSE, error_count);
DBMS_OUTPUT.PUT_LINE('errors := ' || TO_CHAR(error_count));
END;
/
-- KEEPS THE INTERIM TABLE SYNCHRONIZED WITH THE ORIGINAL TABLE.
BEGIN
DBMS_REDEFINITION.SYNC_INTERIM_TABLE('pm', 'cust', 'cust_int');
END;
/
-- FINISH OUR REDEFINITION WHICH WILL SWAP THE ORIGINAL TABLE AND THE INTERIM TABLE
EXEC DBMS_REDEFINITION.FINISH_REDEF_TABLE('pm', 'cust', 'cust_int');
-- DROP THE INTERIM TABLE (THE FORMER ORIGINAL TABLE)
DROP TABLE cust_int;
-- TRY TO INSERT A ROW INTO OUR NEW SECUREFILE TABLE TO PROVE THAT THE PRIMARY KEY WAS PROPERLY MOVED
INSERT INTO cust VALUES(1, 94065, 'hhh', 'ttt');
-- VERIFY THAT OUR NEW TABLE IS NOW USING SecureFiles
SELECT SECUREFILE FROM USER_LOBS WHERE TABLE_NAME = 'CUST';
Convert to Basicfiles from SecureFiles
-- CREATE OUR 'INTERIM' TABLE
-- NOTE: no SecureFile option and no primary key
CREATE TABLE cust_int (
c_id NUMBER,
c_zip NUMBER,
c_name VARCHAR(30) DEFAULT NULL,
c_lob CLOB
);
-- START THE REDEFINITION
DECLARE
col_mapping VARCHAR2(1000);
BEGIN
-- map all the columns in the interim table to the original table
col_mapping := 'c_id c_id , '|| 'c_zip c_zip , '|| 'c_name c_name, '|| 'c_lob c_lob';
DBMS_REDEFINITION.START_REDEF_TABLE('pm', 'cust', 'cust_int', col_mapping);
END;
/
-- COPY THE CONSTRAINTS FROM OUR ORIGINAL TABLE ... TO THE INTERIM TABLE
DECLARE
error_count pls_integer := 0;
BEGIN
DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS('pm', 'cust', 'cust_int', dbms_redefinition.cons_orig_params, TRUE,TRUE,TRUE,FALSE, error_count);
DBMS_OUTPUT.PUT_LINE('errors := ' || TO_CHAR(error_count));
END;
/
-- KEEPS THE INTERIM TABLE SYNCHRONIZED WITH THE ORIGINAL TABLE.
BEGIN
DBMS_REDEFINITION.SYNC_INTERIM_TABLE('pm', 'cust', 'cust_int');
END;
/
-- FINISH OUR REDEFINITION WHICH WILL SWAP THE ORIGINAL TABLE AND THE INTERIM TABLE
EXEC DBMS_REDEFINITION.FINISH_REDEF_TABLE('pm', 'cust', 'cust_int');
-- DROP THE INTERIM TABLE (THE FORMER ORIGINAL TABLE)
DROP TABLE cust_int;
-- TRY TO INSERT A ROW INTO OUR NEW SECUREFILE TABLE TO PROVE THAT THE PRIMARY KEY WAS PROPERLY MOVED
INSERT INTO cust VALUES(1, 94065, 'hhh', 'ttt');
-- VERIFY THAT OUR NEW TABLE IS NOW USING BasicFIles
SELECT SECUREFILE FROM USER_LOBS WHERE TABLE_NAME = 'CUST';
总结
1、若是11.2.0.4,目前只能重建表,若是表本身或CLOB字段很大,那重建的过程还需要再三斟酌是否会影响业务