字符集问题的初步探讨(七)----关于字符集更改的内部操作
2024-07-21 02:06:49
供稿:网友
原文链接:
http://www.eygle.com/special/nls_character_set_07.htm
前面我们提到,通过修改props$的方式更改字符集在oracle7之后是一种极其危险的方式,应该尽量避免。
我们又知道,通过alter database character set更改字符集虽然安全可靠,但是有严格的子集和超集的约束,实际上我们很少能够
用到这种方法。
实际上oracle还存在另外一种更改字符集的方式.
如果你注意过的话,在oracle的alert<sid>.log文件中,你可能看到过这样的日志信息:
alter database character set internal_convert zhs16gbkupdating character set in controlfile to zhs16gbk sys.snap$ (rel_query) - clob representation altered sys.metastylesheet (stylesheet) - clob representation altered sys.external_tab$ (param_clob) - clob representation altered xdb.xdb$resource (sys_nc00027$) - clob representation altered odm.odm_pmml_dtd (dtd) - clob representation altered oe.warehouses (sys_nc00003$) - clob representation altered pm.online_media (sys_nc00042$) - clob representation altered pm.online_media (sys_nc00062$) - clob representation altered pm.online_media (product_text) - clob representation altered pm.online_media (sys_nc00080$) - clob representation altered pm.print_media (ad_sourcetext) - clob representation altered pm.print_media (ad_finaltext) - clob representation alteredcompleted: alter database character set internal_convert zhs1
在这里面,我们看到这样一条重要的,oracle非公开的命令:
alter database character set internal_convert/ internal_use zhs16gbk
这个命令是当你选择了使用典型方式创建了种子数据库以后,oracle会根据你选择的字符集设置,把当前种子数据库的字符集更改为期望字符
集,这就是这条命令的作用.
在使用这个命令时,oracle会跳过所有子集及超集的检查,在任意字符集之间进行强制转换,所以,使用这个命令时你必须十分小心,你必须
清楚这一操作会带来的风险.
我们之前讲过的内容仍然有效,你可以使用csscan扫描整个数据库,如果在转换的字符集之间确认没有严重的数据损坏,或者你可以使用有效
的方式更改,你就可以使用这种方式进行转换.
我们来看一下具体的操作过程及oracle的内部操作:
这是alert.log文件中的记录信息:
tue oct 19 16:26:30 2004
database characterset is zhs16gbk
replication_dependency_tracking turned off (no async multimaster replication found)
completed: alter database open
tue oct 19 16:27:07 2004
alter database character set internal_use zhs16cgb231280
updating character set in controlfile to zhs16cgb231280
tue oct 19 16:27:15 2004
thread 1 advanced to log sequence 118
current log# 2 seq# 118 mem# 0: /opt/oracle/oradata/primary/redo02.log
tue oct 19 16:27:15 2004
arc0: evaluating archive log 3 thread 1 sequence 117
arc0: beginning to archive log 3 thread 1 sequence 117
creating archive destination log_archive_dest_1: '/opt/oracle/oradata/primary/archive/1_117.dbf'
arc0: completed archiving log 3 thread 1 sequence 117
tue oct 19 16:27:20 2004
completed: alter database character set internal_use zhs16cgb231280
shutting down instance: further logons disabled
shutting down instance (immediate)
license high water mark = 1
tue oct 19 16:29:06 2004
alter database close normal
...
...
格式化10046跟踪文件,得到以下信息(摘要):
alter session set events '10046 trace name context forever,level 12'alter database character set internal_use zhs16cgb231280call count cpu elapsed disk query current rows------- ------ -------- ---------- ---------- ---------- ---------- ----------parse 1 0.00 0.00 0 0 0 0execute 1 4.88 6.04 910 16825 18099 0fetch 0 0.00 0.00 0 0 0 0------- ------ -------- ---------- ---------- ---------- ---------- ----------total 2 4.88 6.04 910 16825 18099 0misses in library cache during parse: 1optimizer goal: chooseparsing user id: syselapsed times include waiting on following events: event waited on times max. wait total waited ---------------------------------------- waited ---------- ------------ control file sequential read 4 0.00 0.00 control file parallel write 2 0.05 0.08 log file sync 2 0.08 0.08 sql*net message to client 1 0.00 0.00 sql*net message from client 1 18.06 18.06********************************************************************************....update col$ set charsetid = :1 where charsetform = :2....update argument$ set charsetid = :1 where charsetform = :2....update collection$ set charsetid = :1 where charsetform = :2....update attribute$ set charsetid = :1 where charsetform = :2....update parameter$ set charsetid = :1 where charsetform = :2....update result$ set charsetid = :1 where charsetform = :2....update partcol$ set spare1 = :1 where charsetform = :2....update subpartcol$ set spare1 = :1 where charsetform = :2....update props$ set value$ = :1 where name = :2....update "sys"."kotad$" set sys_nc_rowinfo$ = :1 where sys_nc_oid$ = :2....update seq$ set increment$=:2,minvalue=:3,maxvalue=:4,cycle#=:5,order$=:6, cache=:7,highwater=:8,audit$=:9,flags=:10 where obj#=:1....update kopm$ set metadata = :1, length = :2 where name='db_fdo'....alter database close normal
此处生成的日志你可以在这里下载(供参考):
http://www.eygle.com/special/primary_ora_13730.zip
http://www.eygle.com/special/primary_ora_13730.tkf.log
我们看到这个过程和之前alter database character set操作的内部过程是完全相同的,也就是说internal_use提供的帮助就是使
oracle数据库绕过了子集与超集的校验.
这一方法在某些方面是有用处的,比如测试;应用于产品环境大家应该格外小心,除了你以外,没有人会为此带来的后果负责:
结语(我们不妨再说一次):
对于dba来说,有一个很重要的原则就是:不要把你的数据库置于危险的境地!
这就要求我们,在进行任何可能对数据库结构发生改变的操作之前,先做有效的备份,很多dba没有备份的操作中得到了惨痛的教训。
本文作者:
eygle,oracle技术关注者,来自中国最大的oracle技术论坛itpub.
www.eygle.com是作者的个人站点.你可通过[email protected]来联系作者.欢迎技术探讨交流以及链接交换.
原文出处:
http://www.eygle.com/special/nls_character_set_07.htm