Oracle工具——csscan

東北胖子發表於2016-03-12

工具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則是最終的彙總資訊。

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/2317695/viewspace-2056303/,如需轉載,請註明出處,否則將追究法律責任。

相關文章