标签云
asm恢复 bbed bootstrap$ dul In Memory kcbzib_kcrsds_1 kccpb_sanity_check_2 MySQL恢复 ORA-00312 ORA-00607 ORA-00704 ORA-00742 ORA-01110 ORA-01555 ORA-01578 ORA-01595 ORA-08103 ORA-600 2131 ORA-600 2662 ORA-600 3020 ORA-600 4000 ORA-600 4137 ORA-600 4193 ORA-600 4194 ORA-600 16703 ORA-600 kcbzib_kcrsds_1 ORA-600 KCLCHKBLK_4 ORA-15042 ORA-15196 ORACLE 12C oracle dul ORACLE PATCH Oracle Recovery Tools oracle加密恢复 oracle勒索 oracle勒索恢复 oracle异常恢复 Oracle 恢复 ORACLE恢复 ORACLE数据库恢复 oracle 比特币 OSD-04016 YOUR FILES ARE ENCRYPTED 勒索恢复 比特币加密文章分类
- Others (2)
- 中间件 (2)
- WebLogic (2)
- 操作系统 (103)
- 数据库 (1,769)
- DB2 (22)
- MySQL (77)
- Oracle (1,610)
- Data Guard (52)
- EXADATA (8)
- GoldenGate (24)
- ORA-xxxxx (166)
- ORACLE 12C (72)
- ORACLE 18C (6)
- ORACLE 19C (15)
- ORACLE 21C (3)
- Oracle 23ai (8)
- Oracle ASM (69)
- Oracle Bug (8)
- Oracle RAC (54)
- Oracle 安全 (6)
- Oracle 开发 (28)
- Oracle 监听 (29)
- Oracle备份恢复 (592)
- Oracle安装升级 (97)
- Oracle性能优化 (62)
- 专题索引 (5)
- 勒索恢复 (86)
- PostgreSQL (30)
- pdu工具 (6)
- PostgreSQL恢复 (9)
- SQL Server (32)
- SQL Server恢复 (13)
- TimesTen (7)
- 达梦数据库 (3)
- 达梦恢复 (1)
- 生活娱乐 (2)
- 至理名言 (11)
- 虚拟化 (2)
- VMware (2)
- 软件开发 (39)
- Asp.Net (9)
- JavaScript (12)
- PHP (2)
- 小工具 (22)
-
最近发表
- 2025年的Oracle 8.0.5数据库恢复
- ORA-600 kokiasg1故障分析(obj$中核心字典序列全部被恶意删除)
- ORA-00756 ORA-10567故障数据0丢失恢复
- 数据库文件变成32k故障恢复
- tcp连接过多导致监听TNS-12532 TNS-12560 TNS-00502错误
- 文件系统格式化MySQL数据库恢复
- .sstop勒索加密数据库恢复
- 解决一次硬件恢复之后数据文件0kb的故障恢复case
- Error in invoking target ‘libasmclntsh19.ohso libasmperl19.ohso client_sharedlib’问题处理
- ORA-01171: datafile N going offline due to error advancing checkpoint
- linux环境oracle数据库被文件系统勒索加密为.babyk扩展名溯源
- ORA-600 ksvworkmsgalloc: bad reaper
- ORA-600 krccfl_chunk故障处理
- Oracle Recovery Tools恢复案例总结—202505
- ORA-600 kddummy_blkchk 数据库循环重启
- 记录一次asm disk加入到vg通过恢复直接open库的案例
- CHECKDB 发现了 N 个分配错误和 M 个一致性错误
- 达梦数据库dm.ctl文件异常恢复
- Oracle Recovery Tools修复ORA-00742、ORA-600 ktbair2: illegal inheritance故障
- 可能是 tempdb 空间用尽或某个系统表不一致故障处理
分类目录归档:Oracle
使用dul恢复asm中数据
大家都知道新版本的odu可以在asm不启动的情况下挖数据文件,其实在新版本的dul中,也可以绕过asm挖数据文件,而且操作起来更加方便.
环境准备
SQL> select * from v$version; BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod PL/SQL Release 10.2.0.1.0 - Production CORE 10.2.0.1.0 Production TNS for Linux: Version 10.2.0.1.0 - Production NLSRTL Version 10.2.0.1.0 - Production --查询asm disk SQL> select group_number,DISK_NUMBER,PATH 2 from v$asm_disk where group_number<>0; GROUP_NUMBER DISK_NUMBER PATH ------------ ----------- -------------------- 1 0 /dev/raw/raw2 1 1 /dev/raw/raw3 SQL> conn chf/xifenfei Connected. --创建测试表 SQL> create table t_xifenfei 2 as 3 select object_id,object_name from dba_objects where rownum<10; Table created. SQL> select * from t_xifenfei; OBJECT_ID OBJECT_NAME ---------- -------------------------------- 44 I_USER1 28 CON$ 15 UNDO$ 29 C_COBJ# 3 I_OBJ# 25 PROXY_ROLE_DATA$ 39 I_IND1 51 I_CDEF2 9 rows selected. --数据文件 SQL> select name from v$datafile; NAME ---------------------------------------------------------------------- +XIFENFEI/asm10g/datafile/system.256.786578479 +XIFENFEI/asm10g/datafile/undotbs1.258.786578481 +XIFENFEI/asm10g/datafile/sysaux.257.786578481 +XIFENFEI/asm10g/datafile/users.259.786578481 +XIFENFEI/asm10g/datafile/xff.265.786578851 --关闭数据库 SQL> shutdown immediate; ORA-01031: insufficient privileges SQL> conn / as sysdba Connected. SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> exit Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options --关闭asm [oracle@xifenfei home]$ export ORACLE_SID=+ASM [oracle@xifenfei home]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jun 22 00:18:18 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options SQL> shutdown immediate ASM diskgroups dismounted ASM instance shutdown SQL> exit Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options [oracle@xifenfei home]$ ps -ef|grep ASM oracle 18885 10980 0 00:18 pts/0 00:00:00 grep ASM [oracle@xifenfei home]$ ps -ef|grep ora_ oracle 18887 10980 0 00:18 pts/0 00:00:00 grep ora_
初始化参数配置
[oracle@xifenfei dul]$ vi init.dul db_block_size=8192 control_file = control.dul dc_segments=100000 osd_word_size = 32 osd_big_endian_flag=false osd_dba_file_bits=10 osd_c_struct_alignment=32 osd_file_leader_size=1 osd_word_size = 32 dc_columns=2000000 dc_tables=10000 dc_objects=1000000 dc_users=400 dc_segments=100000 control_file = control.dul db_block_size=8192 export_mode=false compatible=10 BUFFER=10485760
控制文件配置
[oracle@xifenfei dul]$ more control.dul disk /dev/raw/raw2 disk /dev/raw/raw3 0 1 +XIFENFEI/asm10g/datafile/system.256.786578479 1 2 +XIFENFEI/asm10g/datafile/undotbs1.258.786578481 2 3 +XIFENFEI/asm10g/datafile/sysaux.257.786578481 4 4 +XIFENFEI/asm10g/datafile/users.259.786578481 6 5 +XIFENFEI/asm10g/datafile/xff.265.786578851
使用dul恢复表测试
--启动dul [oracle@xifenfei dul]$ ./dul Data UnLoader: 10.2.0.5.13 - Internal Only - on Thu Jun 21 23:49:46 2012 with 64-bit io functions Copyright (c) 1994 2012 Bernard van Duijnen All rights reserved. Strictly Oracle Internal Use Only DUL: Warning: Recreating file "dul.log" Disk group XIFENFEI, dul group_cid 0 Discovered disk /dev/raw/raw2 as diskgroup XIFENFEI, disk number 0 size 784 Mb File1 starts at 2, dul_disk_cid 0 Discovered disk /dev/raw/raw3 as diskgroup XIFENFEI, disk number 1 size 7059 Mb without File1 meta data, dul_disk_cid 1 DUL: Warning: Dictionary cache DC_ASM_EXTENTS is empty DUL: Error: Filedir block not allocated, file does not exist DUL: Error: Could not load asm meta data for group XIFENFEI file 9 Oracle data file size 503324672, block size 8192 Found db_id = 123111609 Found db_name = ASM10G Oracle data file size 26222592, block size 8192 Oracle data file size 251666432, block size 8192 Oracle data file size 5251072, block size 8192 --加载数据字典 DUL> bootstrap; Probing file = 1, block = 377 . unloading table BOOTSTRAP$ DUL: Warning: block number is non zero but marked deferred trying to process it anyhow 57 rows unloaded DUL: Warning: Dictionary cache DC_BOOTSTRAP is empty Reading BOOTSTRAP.dat 57 entries loaded Parsing Bootstrap$ contents DUL: Warning: Recreating file "dict.ddl" Generating dict.ddl for version 10 OBJ$: segobjno 18, file 1 block 121 TAB$: segobjno 2, tabno 1, file 1 block 25 COL$: segobjno 2, tabno 5, file 1 block 25 USER$: segobjno 10, tabno 1, file 1 block 89 Running generated file "@dict.ddl" to unload the dictionary tables . unloading table OBJ$ 50806 rows unloaded . unloading table TAB$ 1560 rows unloaded . unloading table COL$ 54822 rows unloaded . unloading table USER$ 57 rows unloaded Reading USER.dat 57 entries loaded Reading OBJ.dat 50806 entries loaded and sorted 50806 entries Reading TAB.dat 1560 entries loaded Reading COL.dat 54822 entries loaded and sorted 54822 entries Reading BOOTSTRAP.dat 57 entries loaded DUL: Warning: Recreating file "dict.ddl" Generating dict.ddl for version 10 OBJ$: segobjno 18, file 1 block 121 TAB$: segobjno 2, tabno 1, file 1 block 25 COL$: segobjno 2, tabno 5, file 1 block 25 USER$: segobjno 10, tabno 1, file 1 block 89 TABPART$: segobjno 266, file 1 block 2121 INDPART$: segobjno 271, file 1 block 2161 TABCOMPART$: segobjno 288, file 1 block 2297 INDCOMPART$: segobjno 293, file 1 block 2345 TABSUBPART$: segobjno 278, file 1 block 2217 INDSUBPART$: segobjno 283, file 1 block 2257 IND$: segobjno 2, tabno 3, file 1 block 25 ICOL$: segobjno 2, tabno 4, file 1 block 25 LOB$: segobjno 2, tabno 6, file 1 block 25 COLTYPE$: segobjno 2, tabno 7, file 1 block 25 TYPE$: segobjno 181, tabno 1, file 1 block 1297 COLLECTION$: segobjno 181, tabno 2, file 1 block 1297 ATTRIBUTE$: segobjno 181, tabno 3, file 1 block 1297 LOBFRAG$: segobjno 299, file 1 block 2393 LOBCOMPPART$: segobjno 302, file 1 block 2425 UNDO$: segobjno 15, file 1 block 105 TS$: segobjno 6, tabno 2, file 1 block 57 PROPS$: segobjno 96, file 1 block 721 Running generated file "@dict.ddl" to unload the dictionary tables . unloading table OBJ$ DUL: Warning: Recreating file "OBJ.ctl" 50806 rows unloaded . unloading table TAB$ DUL: Warning: Recreating file "TAB.ctl" 1560 rows unloaded . unloading table COL$ DUL: Warning: Recreating file "COL.ctl" 54822 rows unloaded . unloading table USER$ DUL: Warning: Recreating file "USER.ctl" 57 rows unloaded . unloading table TABPART$ 72 rows unloaded . unloading table INDPART$ 80 rows unloaded . unloading table TABCOMPART$ 0 rows unloaded . unloading table INDCOMPART$ 0 rows unloaded . unloading table TABSUBPART$ 0 rows unloaded . unloading table INDSUBPART$ 0 rows unloaded . unloading table IND$ 2213 rows unloaded . unloading table ICOL$ 3618 rows unloaded . unloading table LOB$ 528 rows unloaded . unloading table COLTYPE$ 1688 rows unloaded . unloading table TYPE$ 1885 rows unloaded . unloading table COLLECTION$ 551 rows unloaded . unloading table ATTRIBUTE$ 7051 rows unloaded . unloading table LOBFRAG$ 1 row unloaded . unloading table LOBCOMPPART$ 0 rows unloaded . unloading table UNDO$ 21 rows unloaded . unloading table TS$ 7 rows unloaded . unloading table PROPS$ 27 rows unloaded Reading USER.dat 57 entries loaded Reading OBJ.dat 50806 entries loaded and sorted 50806 entries Reading TAB.dat 1560 entries loaded Reading COL.dat 54822 entries loaded and sorted 54822 entries Reading TABPART.dat 72 entries loaded and sorted 72 entries Reading TABCOMPART.dat 0 entries loaded and sorted 0 entries Reading TABSUBPART.dat 0 entries loaded and sorted 0 entries Reading INDPART.dat 80 entries loaded and sorted 80 entries Reading INDCOMPART.dat 0 entries loaded and sorted 0 entries Reading INDSUBPART.dat 0 entries loaded and sorted 0 entries Reading IND.dat 2213 entries loaded Reading LOB.dat 528 entries loaded Reading ICOL.dat 3618 entries loaded Reading COLTYPE.dat 1688 entries loaded Reading TYPE.dat 1885 entries loaded Reading ATTRIBUTE.dat 7051 entries loaded Reading COLLECTION.dat 551 entries loaded Reading BOOTSTRAP.dat 57 entries loaded Reading LOBFRAG.dat 1 entries loaded and sorted 1 entries Reading LOBCOMPPART.dat 0 entries loaded and sorted 0 entries Reading UNDO.dat 21 entries loaded Reading TS.dat 7 entries loaded Reading PROPS.dat 27 entries loaded Database character set is ZHS16GBK Database national character set is AL16UTF16 --恢复表 DUL> unload table chf.t_xifenfei; . unloading table T_XIFENFEI 9 rows unloaded
验证恢复数据库
[oracle@xifenfei dul]$ ll CHF_T_XIFENFEI* -rw-r--r-- 1 oracle oinstall 269 Jun 22 00:26 CHF_T_XIFENFEI.ctl -rw-r--r-- 1 oracle oinstall 134 Jun 22 00:26 CHF_T_XIFENFEI.dat [oracle@xifenfei dul]$ more CHF_T_XIFENFEI.ctl load data CHARACTERSET UTF8 infile 'CHF_T_XIFENFEI.dat' insert into table "CHF"."T_XIFENFEI" fields terminated by whitespace ( "OBJECT_ID" CHAR(2) enclosed by X'22' ,"OBJECT_NAME" CHAR(16) enclosed by X'22' ) [oracle@xifenfei dul]$ more CHF_T_XIFENFEI.dat "20" "ICOL$" "44" "I_USER1" "28" "CON$" "15" "UNDO$" "29" "C_COBJ#" "3" "I_OBJ#" "25" "PROXY_ROLE_DATA$" "39" "I_IND1" "51" "I_CDEF2"
spfile被覆盖导致ORA-600[kmgs_parameter_update_timeout_1]
数据库出现如下错误ORA-00600[kmgs_parameter_update_timeout_1]
Thu Jun 21 17:42:45 BEIST 2012 alter tablespace TS_TAB_WG_SYSMGR_01 add datafile '/dev/rvgoradata3_1_01' Thu Jun 21 17:42:58 BEIST 2012 Completed: alter tablespace TS_TAB_WG_SYSMGR_01 add datafile '/dev/rvgoradata3_1_01' Thu Jun 21 17:45:31 BEIST 2012 System State dumped to trace file /oracle/app/oracle/admin/bomc3/bdump/bomc3_mmon_19530138.trc Thu Jun 21 17:45:42 BEIST 2012 Errors in file /oracle/app/oracle/admin/bomc3/bdump/bomc3_mmon_19530138.trc: ORA-00600: internal error code, arguments: [kmgs_parameter_update_timeout_1], [1565], [], [], [], [], [], [] ORA-01565: error in identifying file '/dev/rvgoradata3_1_01' ORA-27086: unable to lock file - already in use IBM AIX RISC System/6000 Error: 13: Permission denied Additional information: 8 Additional information: 18874484 Thu Jun 21 17:45:49 BEIST 2012 Errors in file /oracle/app/oracle/admin/bomc3/bdump/bomc3_dbw0_18874484.trc: ORA-00600: internal error code, arguments: [ksprcvsp1], [0], [0], [], [], [], [], [] Thu Jun 21 17:45:52 BEIST 2012 Errors in file /oracle/app/oracle/admin/bomc3/bdump/bomc3_dbw0_18874484.trc: ORA-00600: internal error code, arguments: [kmgs_parameter_update_timeout_1], [600], [], [], [], [], [], [] ORA-00600: internal error code, arguments: [ksprcvsp1], [0], [0], [], [], [], [], [] Thu Jun 21 17:45:53 BEIST 2012 Errors in file /oracle/app/oracle/admin/bomc3/bdump/bomc3_dbw0_18874484.trc: ORA-00600: internal error code, arguments: [kmgs_parameter_update_timeout_1], [600], [], [], [], [], [], [] ORA-00600: internal error code, arguments: [ksprcvsp1], [0], [0], [], [], [], [], [] Thu Jun 21 17:45:53 BEIST 2012 DBW0: terminating instance due to error 471 Instance terminated by DBW0, pid = 18874484
通过这个错误可以看出大概:TS_TAB_WG_SYSMGR_01增加数据文件/dev/rvgoradata3_1_01成功后,然后mmon启动收集统计信息,读取spfile文件信息出错.最后dbw进程读取spfile文件出错,使得dbwn进程终止,从而数据库abort掉.通过这些信息,初步怀疑是增加数据文件的时候,错误的把spfile文件的裸设备作为一个新数据文件增加到数据库中,导致spfile被覆盖,从而出现mmon和dbwn访问spfile出错.
找出证据
如果spfile使用裸设备而且文件名是dev/rvgoradata3_1_01,那很可能是通过init_SID.ora中的spfile项实现,查找该文件内容果然发现
[zwq_acc1:/home/xifenfei]cat initbomc3.ora spfile='/dev/rvgoradata3_1_01'
通过这些可以确定是用户增加数据文件时,错误的把spfile文件当中新的控制问及爱你增加到相关表空间中导致该问题.
解决办法
1.如果有备份spfile文件,使用备份spfile文件
2.如果有pfile文件,使用pfile创建spfile
3.如果上面两个都没有,那么使用alert中相关信息创建pfile文件然后创建spfile
实现trigger集中记录所有库ddl操作
今天客户说了一个我感觉有意思的需求:在一个库上的一张表记录所有库的ddl操作,实现方式:在一个库上建立表和触发器,其他库上通过dblink+同义词+触发器实现ddl操作记录到远程的表中.他当时写了一个触发器,但是有错误,想让我协助解决.在我们的一起努力下,解决了该触发器在dblink同义词的库上出错的问题.我这里测试使用的是10g的库做为存储所有库的ddl记录的库,11g库做为一个通过dblink插入ddl操作记录的库.
在10g数据库库中操作
1.创建记录ddl操作表
SQL> conn chf/xifenfei Connected. SQL> create table t_ddl_audit( 2 db_name varchar2(30), 3 login_user varchar2(30), 4 ddl_time date, 5 ip_address varchar2(20), 6 audsid varchar2(20), 7 schema_user varchar2(30), 8 schema_object varchar2(40), 9 login_tool varchar2(40), 10 os_user varchar2(40), 11 ddl_sql varchar2(4000)); Table created.
2.创建触发器
SQL> create or replace trigger tri_ddl_audit 2 before ddl on database 3 declare 4 n number; 5 str_stmt varchar2(4000); 6 sql_text ora_name_list_t; 7 l_trace number; 8 v_module varchar2(50); 9 v_action varchar2(50); 10 str_session v$session%rowtype; 11 begin 12 n := ora_sql_txt(sql_text); 13 for i in 1 .. n loop 14 str_stmt := substr(str_stmt || sql_text(i), 1, 3000); 15 end loop; 16 dbms_application_info.READ_MODULE(v_module, v_action); 17 INSERT INTO chf.t_ddl_audit 18 (db_name, 19 login_user, 20 ddl_time, 21 ip_address, 22 audsid, 23 schema_user, 24 schema_object, 25 login_tool, 26 os_user, 27 ddl_sql) 28 VALUES 29 (sys_context('USERENV', 'db_name'), 30 ora_login_user, 31 SYSDATE, 32 sys_context('USERENV', 'IP_ADDRESS'), 33 userenv('SESSIONID'), 34 ora_dict_obj_owner, 35 ora_dict_obj_name, 36 v_module, 37 sys_context('userenv', 'os_user'), 38 str_stmt); 39 exception 40 when no_data_found then 41 null; 42 end; 43 / Trigger created.
3.测试触发器
SQL> conn chf/xifenfei Connected. SQL> create table t_xff as select * from dba_tables where rownum=1; Table created. SQL> select db_name,login_user,ddl_sql from t_ddl_audit; DB_NAME LOGIN_USER ------------------------------ ------------------------------ DDL_SQL ----------------------------------------------------------------- XFF CHF create table t_xff as select * from dba_tables where rownum=1
在11g数据库中操作
1.创建dblink和同义词
SQL> create database link "ora10g_dblink" 2 connect to chf 3 identified by "xifenfei" 4 using 'ora10g'; Database link created. SQL> create synonym t_ddl_audit for t_ddl_audit@ora10g_dblink; Synonym created.
2.第一次创建触发器
SQL> create or replace trigger tri_ddl_audit 2 before ddl on database 3 declare 4 n number; 5 str_stmt varchar2(4000); 6 sql_text ora_name_list_t; 7 l_trace number; 8 v_module varchar2(50); 9 v_action varchar2(50); 10 str_session v$session%rowtype; 11 begin 12 n := ora_sql_txt(sql_text); 13 for i in 1 .. n loop 14 str_stmt := substr(str_stmt || sql_text(i), 1, 3000); 15 end loop; 16 dbms_application_info.READ_MODULE(v_module, v_action); 17 INSERT INTO t_ddl_audit 18 (db_name, 19 login_user, 20 ddl_time, 21 ip_address, 22 audsid, 23 schema_user, 24 schema_object, 25 login_tool, 26 os_user, 27 ddl_sql) 28 VALUES 29 (sys_context('USERENV', 'db_name'), 30 ora_login_user, 31 SYSDATE, 32 sys_context('USERENV', 'IP_ADDRESS'), 33 userenv('SESSIONID'), 34 ora_dict_obj_owner, 35 ora_dict_obj_name, 36 v_module, 37 sys_context('userenv', 'os_user'), 38 str_stmt); 39 exception 40 when no_data_found then 41 null; 42 end; 43 / Trigger created.
3.测试触发器
SQL> create table t_xff as select * from dba_objects where rownum<10; create table t_xff as select * from dba_objects where rownum<10 * ERROR at line 1: ORA-00604: error occurred at recursive SQL level 1 ORA-02070: database does not support in this context ORA-06512: at line 15
出现ORA-02070错误,估计是类此sys_context(‘userenv’, ‘os_user’)导致。
4.第二次创建触发器
SQL> create or replace trigger tri_ddl_audit 2 before ddl on database 3 declare 4 n number; 5 str_stmt varchar2(4000); 6 sql_text ora_name_list_t; 7 l_trace number; 8 v_module varchar2(50); 9 v_action varchar2(50); 10 v_db_name varchar2(50); 11 v_ip_addr varchar2(50); 12 v_os varchar2(50); 13 v_session_id varchar2(50); 14 str_session v$session%rowtype; 15 begin 16 n := ora_sql_txt(sql_text); 17 for i in 1 .. n loop 18 str_stmt := substr(str_stmt || sql_text(i), 1, 3000); 19 end loop; 20 dbms_application_info.READ_MODULE(v_module, v_action); 21 v_db_name :=sys_context('USERENV', 'db_name'); 22 v_ip_addr :=sys_context('USERENV', 'IP_ADDRESS'); 23 v_os:=sys_context('userenv', 'os_user'); 24 v_session_id:=userenv('SESSIONID'); 25 INSERT INTO t_ddl_audit 26 (db_name, 27 login_user, 28 ddl_time, 29 ip_address, 30 audsid, 31 schema_user, 32 schema_object, 33 login_tool, 34 os_user, 35 ddl_sql) 36 VALUES 37 (v_db_name, 38 ora_login_user, 39 SYSDATE, 40 v_ip_addr, 41 v_session_id, 42 ora_dict_obj_owner, 43 ora_dict_obj_name, 44 v_module, 45 v_os, 46 str_stmt); 47 exception 48 when no_data_found then 49 null; 50 end; 51 / Trigger created.
5.继续测试触发器
SQL> drop table t3; drop table t3 * ERROR at line 1: ORA-00604: error occurred at recursive SQL level 1 ORA-02069: global_names parameter must be set to TRUE for this operation ORA-06512: at line 23
根据ORA-02069,查询资料发现是通过dblink插入数据使用了变量和常量的方式混合使用导致该错误,修改触发器全部使用变量方式
6.第三次创建触发器
SQL> create or replace trigger tri_ddl_audit 2 before ddl on database 3 declare 4 n number; 5 str_stmt varchar2(4000); 6 sql_text ora_name_list_t; 7 l_trace number; 8 v_module varchar2(50); 9 v_action varchar2(50); 10 v_db_name varchar2(50); 11 v_ip_addr varchar2(50); 12 v_os varchar2(50); 13 v_session_id varchar2(50); 14 v_loginuser varchar2(50); 15 v_obj_name varchar2(50); 16 v_owner varchar2(50); 17 str_session v$session%rowtype; 18 begin 19 n := ora_sql_txt(sql_text); 20 for i in 1 .. n loop 21 str_stmt := substr(str_stmt || sql_text(i), 1, 3000); 22 end loop; 23 dbms_application_info.READ_MODULE(v_module, v_action); 24 v_db_name :=sys_context('USERENV', 'db_name'); 25 v_ip_addr :=sys_context('USERENV', 'IP_ADDRESS'); 26 v_os:=sys_context('userenv', 'os_user'); 27 v_session_id:=userenv('SESSIONID'); 28 v_loginuser:= ora_login_user; 29 v_owner:=ora_dict_obj_owner; 30 v_obj_name:=ora_dict_obj_name; 31 INSERT INTO t_ddl_audit 32 (db_name, 33 login_user, 34 ddl_time, 35 ip_address, 36 audsid, 37 schema_user, 38 schema_object, 39 login_tool, 40 os_user, 41 ddl_sql) 42 VALUES 43 (v_db_name, 44 v_loginuser, 45 SYSDATE, 46 v_ip_addr, 47 v_session_id, 48 v_owner, 49 v_obj_name, 50 v_module, 51 v_os, 52 str_stmt); 53 exception 54 when no_data_found then 55 null; 56 end; 57 / Trigger created.
7.测试触发器
SQL> create table t_xff11 as select * from dba_tables where rownum<10; Table created. SQL> select db_name,login_user,ddl_sql from t_ddl_audit; DB_NAME LOGIN_USER ------------------------------ ------------------------------ DDL_SQL ----------------------------------------------------------------- ora11g CHF create table t_xff11 as select * from dba_tables where rownum<10 XFF CHF create table t_xff as select * from dba_tables where rownum=1
补充说明
这个方案个人感觉是一个实验室中的方案,在实际的生成环境中很难应用上
1.trigger记录ddl操作本身效率不高
2.如果某个库不能访问存储ddl操作的表的数据库,将导致该数据库所有ddl操作hang住,从而可能使得该数据库hang住的风险.