天天看點

oracle 字元集掃描工具Character Set Scanner

CSSCAN(Character Set Scanner utility)是Oracle提供的一個用于檢查字元集轉換過程中可能會出現的資料丢失或者損壞的情況。也可以單獨的掃描某些表某些列能否進行字元集轉換,并且能夠并行掃描以加快掃描速度。

提問:這個字元集掃描器的作用是什麼呢?

回答:查找出在做字元集轉換後,哪些内容無法轉換需要單獨處理,也就是确定并報告在資料轉換過程中會出現的異常問題。

csscan工具檢測完成之後,會報告如下三種類型的異常:

1)lossy conversions(有耗損的轉換)

2)exceeded column length(超出的列長度)

3)convertible or exceptional data in the data dictionary(資料字典中可轉換或者有異常的資料)

再提問:什麼時候使用這個工具?

再回答:如果您像我一樣,需求是從WE8ISO8859P1字元集更新到AL32UTF8字元集,那麼,第一步就需要使用這個工具給您的寶貝資料庫做一個全面的“體檢”了。

2.安裝csscan

$ which csscan

/u01/app/oracle/product/11.2.0/db_1/bin/csscan

2)這個工具是二進制檔案。

3)如果需要重新安裝,可以在下面這個連結得到安裝媒體。

http://www.oracle.com/technology/software/tech/globalization/index.html

1)第一步,以sys使用者登陸,建立所需的CSMIG使用者和資料字典對象。這個步驟是必要條件的,否則工具無法使用。

$ sqlplus / as sysdba

SQL> @?/rdbms/admin/csminst.sql

SQL> exit;

2)“實操”目标:對目前資料庫做“不留死角”的檢驗。

首先,需要以具有SYSDBA權限的使用者登入操作;其次就是對這個工具的一些參數要有所了解。

注意,這裡為了使用具有SYSDBA權限的使用者操作采用了一個小技巧,如果不知道的話,可能會比較郁悶。

Shell下的小技巧是:userid="'"sys/sys as sysdba"'",隻有這樣使用才能順利的執行。也可以把它放到參數檔案中。

(1)如果使用參數檔案,文法如下

$cd /home/oracle

$ vi csscan.par

userid="sys/sys as sysdba" full=y fromchar=we8iso8859p1 tochar=AL32UTF8 log=check.log capture=y array=1000000 process=4

$ csscan parfile=csscan.par

舉例:

userid="sys/sys as sysdba" full=y fromchar=ZHS16CGB231280 tochar=AL32UTF8 log=check.log capture=y array=1000000 process=1

(2)如果是在Shell下直接操作,就得用到上面提到的小技巧了。另外這裡我為了提高速度,使用了4個并行(process=4)

$ csscan userid="'"sys/sys as sysdba"'" full=y fromchar=WE8ISO8859P1 tochar=AL32UTF8 log=check.log capture=y array=1000000 process=4

下面是我測試的運作結果:

(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

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