字符集扫描工具Csscancsscan的全称是Character Set Scanner。顾名思义,此工具是用来对字符集进行扫描,来获取当转换字符集时可能发生的数据丢失。
The Csscan tool analyzes the code points in the database and verifies that they are known in the source the database characterset and known in the target database characterset.
一、安装Csscan
oracle软件安装好会自带Csscan工具, 存放路径位于$ORACLE_HOME/bin/csscan 。
Csscan工具需要用到CSMIG用户,可以通过执行 $ORACLE_HOME/rdbms/admin下的脚本csminst.sql来生成CSMIG用户和相关数据字典对象。
1、修改csminst.sql脚本
CSMIG默认的表空间是SYSTEM,可以通过修改脚本中的内容来指定表空间:
The default tablespace is SYSTEM, if you plan to run csscan against a big database then we advice to create a separate tablespace and change the $ORACLE_HOME/rdbms/admin/csminst.sql script to use this tablespace.
Modify the following statement in csminst.sql to assign your preferred tablespace to CSMIG instead of SYSTEM:
alter user csmig default tablespace SYSTEM
/
下面的授权并不需要,在11.2 和10.2.0.5版本的Csminst.sqlw会被删除掉。可以手工把它删掉,或者忽略相关的"ORA-22930 directory does not exist" 报错。
The amount of space needed depends mainly on the amount of exceptions found ( convertible and/or lossy data) and is impossible to predict upfront. It's useful to use on the first run of csscan a tablespace that is limited in size to avoid any disk space issues.
The Csminst.sql file is doing two grants to SYSTEM
grant READ on directory log_file_dir to system
/
grant READ on directory data_file_dir to system
/
2、执行csminst.sql脚本
下面执行脚本csminst.sql来生成CSMIG用户和相关数据字典对象,执行之前最好先备份一份:
[[email protected] admin]$ echo $ORACLE_SID
cicutedb
[[email protected] admin]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 - Production on Mon Jun 16 10:55:40 2014
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> set TERMOUT ON
SQL> set ECHO ON
SQL> spool csminst.log
SQL> @?/rdbms/admin/csminst.sql
Csscan实际使用中不会登录csmig用户,可以把csmig锁定:
The password for the CSMIG user will be asked when running the csminst.sql script, this can be anything and we suggest to lock the CSMIG account . The actual csmig login is not used by Csscan.
SQL> conn / as sysdba
SQL> alter user csmig account lock;
最后检查安装日志:
Check the csminst.log for errors.
3、验证csscan是否能正常使用
使用如下命令来验证:
[[email protected] admin]$ csscan TABLE='(SYS.SQL_VERSION$)' FROMCHAR=US7ASCII TOCHAR=US7ASCII LOG=instchkc CAPTURE=N PROCESS=1 ARRAY=1024000
Character Set Scanner v2.1 : Release 10.2.0.3.0 - Production on Mon Jun 16 10:59:33 2014
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Username: xiezq
Password:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Enumerating table to scan...
. process 1 scanning SYS.SQL_VERSION$[AAAAIEAABAAAA/5AAA]
Creating Database Scan Summary Report...
Creating Individual Exception Report...
Scanner terminated successfully.
当看到“Scanner terminated successfully.”时,表明csscan已安装成功。
参考Oracle Support:Installing and configuring Csscan in 10g and 11g (Database Character Set Scanner) (Doc ID 745809.1)