Oracle工具——csscan

工具csscan用于检查从一个字符集转换到另一个字符集,数据库中的数据是否会产生丢失、截断等现象。
这个工具很早就出现了,不过由于长久以来牵制到字符集转换的工作不是很多,因此对于这个工具没什么研究,这次需要将ZHS16GBK转换到AL32UTF8,尝试了一下csscan的功能,发现这个工具还是很方便的。

[oracle@dbserver1 bin]$ csscan userid=thams/thams TABLE=libfile722 tochar=AL32UTF8 log=/home/oracle/scan_722
CHARACTER SET Scanner v2.2 : Release 11.2.0.2.0 - Production ON Wed Aug 31 10:54:15 2011
Copyright (c) 1982, 2009, Oracle AND/OR its affiliates.  ALL rights reserved.
CSS-00127: USER thams does NOT have DBA privilege
Scanner TERMINATED unsuccessfully.

错误信息很明显,连接用户不是DBA角色,如果用system用户连接进行这个命令:

[oracle@dbserver1 bin]$ csscan userid=system/oracle TABLE=thams.libfile722 tochar=AL32UTF8 log=/home/oracle/scan_722
CHARACTER SET Scanner v2.2 : Release 11.2.0.2.0 - Production ON Wed Aug 31 10:54:45 2011
Copyright (c) 1982, 2009, Oracle AND/OR its affiliates. ALL rights reserved.
Connected TO:
Oracle DATABASE 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
WITH the Partitioning, Automatic Storage Management, OLAP, DATA Mining
AND REAL Application Testing options
CSS-00107: CHARACTER SET migration utility schema NOT installed
Scanner TERMINATED unsuccessfully.

导致这个错误是由于CSSCAN工具需要在数据库中建立一个CSMIG用户:

[oracle@dbserver1 bin]$ sqlplus / AS sysdba
SQL*Plus: Release 11.2.0.2.0 Production ON Wed Aug 31 10:57:28 2011
Copyright (c) 1982, 2010, Oracle.  ALL rights reserved.
Connected TO:
Oracle DATABASE 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
WITH the Partitioning, Automatic Storage Management, OLAP, DATA Mining
AND REAL Application Testing options
SQL> @?/rdbms/admin/csminst
USER created.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
USER altered.
1 ROW created.
1 ROW updated.
TABLE created.
.
.
.
VIEW created.
VIEW created.
VIEW created.
VIEW created.
GRANT succeeded.
GRANT succeeded.
Disconnected FROM Oracle DATABASE 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
WITH the Partitioning, Automatic Storage Management, OLAP, DATA Mining
AND REAL Application Testing options
[oracle@dbserver1 bin]$ csscan userid=system/oracle TABLE=thams.libfile722 tochar=AL32UTF8 log=/home/oracle/scan_722
CHARACTER SET Scanner v2.2 : Release 11.2.0.2.0 - Production ON Wed Aug 31 10:59:35 2011
Copyright (c) 1982, 2009, Oracle AND/OR its affiliates.  ALL rights reserved.
Connected TO:
Oracle DATABASE 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
WITH the Partitioning, Automatic Storage Management, OLAP, DATA Mining
AND REAL Application Testing options
Enter array fetch buffer SIZE: 1024000 > 4096000
Enter NUMBER OF scan processes TO utilize(1..64): 1 > 
Enumerating TABLE TO scan...
. process 1 scanning THAMS.LIBFILE722[AAAP2KAAAAAB7XYAAA]
Creating DATABASE Scan Summary Report...
Creating Individual Exception Report...
Scanner TERMINATED successfully.

调用csminst.sql脚本创建辅助用户和对象后,再次运行csscan工具,对表中数据进行转换前的扫描。
工具csscan的调用有命令行方式,和交互两种,当命令行没有提供足够的参数,工具会以交互方式获取其他参数。
操作完成后,可以检查对应的日志信息:

[oracle@dbserver1 bin]$ more /home/oracle/scan_722.err 
DATABASE Scan Individual Exception Report
[DATABASE Scan Parameters]
Parameter                      VALUE                                           
------------------------------ ------------------------------------------------
CSSCAN Version                 v2.1                                            
Instance Name                  fhacdb1                                         
DATABASE Version               11.2.0.2.0                                      
Scan TYPE                      Selective TABLES                                
Scan CHAR DATA?                YES                                             
DATABASE CHARACTER SET         ZHS16GBK                                        
FROMCHAR                       ZHS16GBK                                        
TOCHAR                         AL32UTF8                                        
Scan NCHAR DATA?               NO                                              
Array fetch buffer SIZE        4096000                                         
NUMBER OF processes            1                                               
Capture convertible DATA?      NO                                              
------------------------------ ------------------------------------------------
[DATA Dictionary individual exceptions]
[Application DATA individual exceptions]
USER  : THAMS
TABLE : LIBFILE722
COLUMN: F4
TYPE  : VARCHAR2(42)
NUMBER OF Exceptions         : 1         
MAX Post Conversion DATA SIZE: 45        
ROWID              Exception TYPE      SIZE Cell DATA(FIRST 30 bytes)     
------------------ ------------------ ----- ------------------------------
AAAP2KAAAAAB+u0AAE exceed COLUMN SIZE    45 巡视台湾兼理学政陕西道监察御史
------------------ ------------------ ----- ------------------------------
[oracle@dbserver1 bin]$ more /home/oracle/scan_722.out 
CHARACTER SET Scanner v2.2 : Release 11.2.0.2.0 - Production ON Wed Aug 31 10:59:35 2011
Copyright (c) 1982, 2009, Oracle AND/OR its affiliates.  ALL rights reserved.
Connected TO:
Oracle DATABASE 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
WITH the Partitioning, Automatic Storage Management, OLAP, DATA Mining
AND REAL Application Testing options
Enter array fetch buffer SIZE: 1024000 > 
Enter NUMBER OF scan processes TO utilize(1..64): 1 > 
Enumerating TABLE TO scan...
. process 1 scanning THAMS.LIBFILE722[AAAP2KAAAAAB7XYAAA]
Creating DATABASE Scan Summary Report...
Creating Individual Exception Report...
Scanner TERMINATED successfully.
[oracle@dbserver1 bin]$ more /home/oracle/scan_722.txt 
DATABASE Scan Summary Report
TIME Started  : 2011-08-31 10:59:48
TIME Completed: 2011-08-31 10:59:50
Process ID         TIME Started       TIME Completed
---------- -------------------- --------------------
         1  2011-08-31 10:59:49  2011-08-31 10:59:49
---------- -------------------- --------------------
[DATABASE SIZE]
Tablespace                           Used            Free           Total       Expansion
------------------------- --------------- --------------- --------------- ---------------
SYSTEM                            581.81M         118.19M         700.00M            .00K
SYSAUX                            521.38M          78.63M         600.00M            .00K
UNDOTBS1                            7.44M      20,699.56M      20,707.00M            .00K
TEMP                                 .00K            .00K            .00K            .00K
USERS                           1,930.38M         139.88M       2,070.25M            .00K
LOB_AU2M                        8,176.13M   1,937,423.88M   1,945,600.00M         212.00K
LOB_AU8M                       10,074.69M     501,925.31M     512,000.00M            .00K
DATA_ARCHIVE                    5,332.06M   1,018,667.94M   1,024,000.00M            .00K
LOB_AU32M                       4,772.38M     507,227.63M     512,000.00M            .00K
LOB_AU64M                       4,548.38M     507,451.63M     512,000.00M            .00K
------------------------- --------------- --------------- --------------- ---------------
Total                          35,944.63M   4,493,732.63M   4,529,677.25M         212.00K
[DATABASE Scan Parameters]
Parameter                      VALUE                                           
------------------------------ ------------------------------------------------
CSSCAN Version                 v2.1                                            
Instance Name                  fhacdb1                                         
DATABASE Version               11.2.0.2.0                                      
Scan TYPE                      Selective TABLES                                
Scan CHAR DATA?                YES                                             
DATABASE CHARACTER SET         ZHS16GBK                                        
FROMCHAR                       ZHS16GBK                                        
TOCHAR                         AL32UTF8                                        
Scan NCHAR DATA?               NO                                              
Array fetch buffer SIZE        4096000                                         
NUMBER OF processes            1                                               
Capture convertible DATA?      NO                                              
------------------------------ ------------------------------------------------
[Scan Summary]
SOME CHARACTER TYPE application DATA are NOT convertible TO the NEW CHARACTER SET
[DATA Dictionary Conversion Summary]
DATA Dictionary TABLES:
Datatype                    Changeless      Convertible       Truncation            Lossy
--------------------- ---------------- ---------------- ---------------- ----------------
VARCHAR2                             0                0                0                0
CHAR                                 0                0                0                0
LONG                                 0                0                0                0
VARRAY                               0                0                0                0
--------------------- ---------------- ---------------- ---------------- ----------------
Total                                0                0                0                0
Total IN percentage              0.000%           0.000%           0.000%           0.000%
XML CSX Dictionary TABLES:
Datatype                    Changeless      Convertible       Truncation            Lossy
--------------------- ---------------- ---------------- ---------------- ----------------
VARCHAR2                             0                0                0                0
CHAR                                 0                0                0                0
LONG                                 0                0                0                0
VARRAY                               0                0                0                0
--------------------- ---------------- ---------------- ---------------- ----------------
Total                                0                0                0                0
Total IN percentage              0.000%           0.000%           0.000%           0.000%
[Application DATA Conversion Summary]
Datatype                    Changeless      Convertible       Truncation            Lossy
--------------------- ---------------- ---------------- ---------------- ----------------
VARCHAR2                       222,683           28,308                1                0
CHAR                                 0                0                0                0
LONG                                 0                0                0                0
VARRAY                               0                0                0                0
--------------------- ---------------- ---------------- ---------------- ----------------
Total                          222,683           28,308                1                0
Total IN percentage             88.721%          11.278%           0.000%           0.000%
[Distribution OF Convertible, Truncated AND Lossy DATA BY TABLE]
DATA Dictionary TABLES:
USER.TABLE                                    Convertible       Truncation            Lossy
---------------------------------------- ---------------- ---------------- ----------------
---------------------------------------- ---------------- ---------------- ----------------
XML CSX Dictionary TABLES:
USER.TABLE                                    Convertible       Truncation            Lossy
---------------------------------------- ---------------- ---------------- ----------------
---------------------------------------- ---------------- ---------------- ----------------
Application DATA:
USER.TABLE                                    Convertible       Truncation            Lossy
---------------------------------------- ---------------- ---------------- ----------------
THAMS.LIBFILE722                                   28,308                1                0
---------------------------------------- ---------------- ---------------- ----------------
[Distribution OF Convertible, Truncated AND Lossy DATA BY COLUMN]
DATA Dictionary TABLES:
USER.TABLE|COLUMN                             Convertible       Truncation            Lossy
---------------------------------------- ---------------- ---------------- ----------------
---------------------------------------- ---------------- ---------------- ----------------
XML CSX Dictionary TABLES:
USER.TABLE|COLUMN                             Convertible       Truncation            Lossy
---------------------------------------- ---------------- ---------------- ----------------
---------------------------------------- ---------------- ---------------- ----------------
Application DATA:
USER.TABLE|COLUMN                             Convertible       Truncation            Lossy
---------------------------------------- ---------------- ---------------- ----------------
THAMS.LIBFILE722|F11                                4,648                0                0
THAMS.LIBFILE722|F2                                 4,643                0                0
THAMS.LIBFILE722|F3                                 4,648                0                0
THAMS.LIBFILE722|F46                                  222                0                0
THAMS.LIBFILE722|F6                                 4,312                0                0
THAMS.LIBFILE722|F7                                   565                0                0
THAMS.LIBFILE722|TITLE                              4,642                0                0
---------------------------------------- ---------------- ---------------- ---------------
[Indexes TO be Rebuilt]
USER.INDEX ON USER.TABLE(COLUMN)                                                         
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------

工具csscan会生成三个日志,一个err记录错误信息,比如这个例子中,一个列的长度需要变长,否则无法容纳数据长度的扩展;一个log记录操作步骤;而txt则是最终的汇总信息。

This entry was posted in ORACLE and tagged , . Bookmark the permalink.

One Response to Oracle工具——csscan

Leave a Reply

Your email address will not be published. Required fields are marked *