【csscan】字符集扫描工具csscan“实操式”品味

最近一直在做的国际化项目要求数据库字符集使用AL32UTF8,因此带了了一个疑问:目前正在服役的WE8ISO8859P1字符集生产数据库中的核心数据能否完好无损的迁移到这套新字符集数据库库中呢?Oracle同学已经为我们想好怎么解决这个问题了,方法就是使用Oracle自带的字符集扫描工具csscan对原库进行一次全面的字符集转换科目的“体检”。
借此机会记录一下这个工具的使用过程和注意事项,供你我参考。

1.简单介绍一下csscan这个工具
csscan工具全程大名:Character Set Scanner(字符集扫描工具)。

提问:这个字符集扫描器的作用是什么呢?
回答:查找出在做字符集转换后,哪些内容无法转换需要单独处理,也就是确定并报告在数据转换过程中会出现的异常问题。

csscan工具检测完成之后,会报告如下三种类型的异常:
1)lossy conversions
2)exceeded column length
3)convertible or exceptional data in the data dictionary
关于csscan更详细的介绍请大家自行参考下面这个Metalink文章
MetaLink <124721.1> : 'Migrating an Applications Installation to a New Character Set.' 124721.1>

再提问:什么时候使用这个工具?
再回答:如果您像我一样,需求是从WE8ISO8859P1字符集升级到AL32UTF8字符集,那么,第一步就需要使用这个工具给您的宝贝数据库做一个全面的“体检”了。

2.安装csscan
1)在数据库安装完成之后就会自带这个工具。此工具的存放路径如下:
ora10g@secDB /home/oracle$ which csscan
/oracle/app/oracle/product/10.2.0/db_1/bin/csscan

2)这个工具是二进制文件,如果您像我一样好奇,可以使用Linux的strings命令查看一下这个工具,您会发现一些有趣的信息(自己尝试吧)。
$ strings csscan

3)如果需要重新安装,可以在下面这个链接得到安装介质。
http://www.oracle.com/technology/software/tech/globalization/index.html

3.“实操式”使用csscan现在开始,请大家打起精神。
1)第一步,以sys用户登陆,创建所需的 CSMIG用户和 数据字典对象。这个步骤是必要条件的,否则工具无法使用。
ora10g@secDB /home/oracle$ sqlplus / as sysdba
SQL> @?/rdbms/admin/csminst.sql
SQL> exit;

2)“实操”目标:对目前数据库做“不留死角”的检验。
首先,需要以具有SYSDBA权限的用户登录操作;其次就是对这个工具的一些参数要有所了解。
下面的记录是在我的测试环境下演示的效果。
注意,这里为了使用具有SYSDBA权限的用户操作采用了一个小技巧,如果不知道的话,可能会比较郁闷。
Shell下的小技巧是:userid="'"sys/sys as sysdba"'",只有这样使用才能顺利的执行。也可以把它放到参数文件中。
(1)如果使用参数文件,语法如下
ora10g@secDB /home/oracle$ cat csscan.par
userid="sys/sys as sysdba" full=y fromchar=we8iso8859p1 tochar=AL32UTF8 log=check.log capture=y array=1000000 process=4
ora10g@secDB /home/oracle$ csscan parfile=csscan.par

(2)如果是在Shell下直接操作,就得用到上面提到的小技巧了。另外这里我为了提高速度,使用了4个并行(process=4)
ora10g@secDB /home/oracle$ csscan userid="'"sys/sys as sysdba"'" full=y fromchar=WE8ISO8859P1 tochar=AL32UTF8 log=check.log capture=y array=1000000 process=4


Character Set Scanner v2.1 : Release 10.2.0.3.0 - Production on Sat Sep 19 18:53:09 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options

Enumerating tables to scan...

. process 1 scanning SYS.WRH$_SQLSTAT[AAADeWAADAAAD9JAAA]
. process 4 scanning SYS.WRI$_ADV_PARAMETERS[AAAA54AADAAAAMZAAA]
 ---- 这里省略N多的提示信息 ----
. process 3 scanning SYS.WRH$_TABLESPACE_STAT[AAADV7AADAAAFsxAAA]
. process 2 scanning SYS.STREAMS$_APPLY_SPILL_MSGS_PART[AAAB/wAADAAAAlxAAA]

Creating Database Scan Summary Report...

Creating Individual Exception Report...

Scanner terminated successfully.

(3)看到上面的信息,就表示执行成功了。完成之后会在当前目录下生成如下三个文件
ora10g@secDB /home/oracle$ ls -l check*
-rw-r--r-- 1 oracle oinstall 7.1K Sep 19 18:53 check.log.err
-rw-r--r-- 1 oracle oinstall  61K Sep 19 18:53 check.log.out
-rw-r--r-- 1 oracle oinstall 8.7K Sep 19 18:53 check.log.txt

(4)您可以使用vi编辑器进行查看
ora10g@secDB /home/oracle$ vi check.log.err check.log.out check.log.txt

(5)就上面的三个文件一一解释一下:
check.log.err文件是Database Scan Individual Exception Report,记录着我们非常关心的哪些数据会在转换之后出问题。需要重点关注这个文件。
check.log.out文件就是记录了上面在终端上能看到的所有内容,用来检查命令是否正常执行完成。
check.log.txt文件是Database Scan Summary Report,对整个检验结果给出一个列表式的Report。

三个文件的具体内容我就不在这里展示了,以您自己的检验结果为准。

(6)这里我们将对数据库做一个全面的分析,如果您只是想对具体的某个表进行分析,可以使用下面的方法
ora10g@secDB /home/oracle$ csscan system/sys table=SEC.DEMO tochar=AL32UTF8 array=4096000 process=4 suppress=100 lcsd=y;


Character Set Scanner v2.1 : Release 10.2.0.3.0 - Production on Sat Sep 19 19:11:23 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options

Enumerating table to scan...

. process 1 scanning SEC.DEMO[AAADI/AAHAAAnoRAAA]

Creating Database Scan Summary Report...

Creating Individual Exception Report...

Scanner terminated successfully.

不指定log参数,会默认生成如下三个文件
ora10g@secDB /home/oracle$ ls -l scan*
-rw-r--r-- 1 oracle oinstall 1.5K Sep 19 19:11 scan.err
-rw-r--r-- 1 oracle oinstall  529 Sep 19 19:11 scan.out
-rw-r--r-- 1 oracle oinstall 6.4K Sep 19 19:11 scan.txt

4.【附】联机参考
使用“csscan help=y”或“csscan -help”命令可以得到csscan使用方法参考
ora10g@secDB /home/oracle$ csscan help=y

ora10g@secDB /home/oracle$ csscan -help


Character Set Scanner v2.1 : Release 10.2.0.3.0 - Production on Sat Sep 19 17:32:12 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


You can let Scanner prompt you for parameters by entering the CSSCAN
command followed by your username/password:

  Example: CSSCAN SYSTEM/MANAGER

Or, you can control how Scanner runs by entering the CSSCAN command
followed by various parameters. To specify parameters, you use keywords:

  Example: CSSCAN SYSTEM/MANAGER FULL=y TOCHAR=utf8 ARRAY=1024000 PROCESS=3

Keyword    Default Prompt Description
---------- ------- ------ -------------------------------------------------
USERID             yes    username/password
FULL       N       yes    scan entire database
USER               yes    owner of tables to be scanned
TABLE              yes    list of tables to scan
COLUMN             yes    list of columns to scan
EXCLUDE                   list of tables to exclude from scan
TOCHAR             yes    new database character set name
FROMCHAR                  current database character set name
TONCHAR                   new national character set name
FROMNCHAR                 current national character set name
ARRAY      1024000 yes    size of array fetch buffer
PROCESS    1       yes    number of concurrent scan process
MAXBLOCKS                 split table if block size exceed MAXBLOCKS
CAPTURE    N              capture convertible data
SUPPRESS                  maximum number of exceptions logged for each table
FEEDBACK                  report progress every N rows
BOUNDARIES                list of column size boundaries for summary report
LASTRPT    N              generate report of the last database scan
LOG        scan           base file name of report files
PARFILE                   parameter file name
PRESERVE   N              preserve existing scan results
LCSD       N       no     enable language and character set detection
LCSDDATA   LOSSY   no     define the scope of the detection
HELP       N              show help screen (this screen)
QUERY      N              select clause to scan subset of tables or columns
---------- ------- ------ -------------------------------------------------
Scanner terminated successfully.


5.小结
Oracle的问题要用Oracle的方法去解决!
Oracle提供给我们很多类似csscan的实用小工具,每一个工具都是针对特定需求,均是一把好手--存在即合理。
“善用佳软”,大家慢慢体会吧。

-- The End --

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/519536/viewspace-615093/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/519536/viewspace-615093/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值