关闭ORACLE的TRACE文件
(2017-03-24 15:55:42)
标签:
it |
分类: ORACLE |
-
SQL> ! ps -ef | grep smon
-
oracle 766348 1 0 14:29:34 - 0:02 ora_smon_testdb -
oracle 398618 128480 0 16:51:16 pts/3 0:00 /usr/bin/bash -c ps -ef | grep smon -
oracle 157498 398618 0 16:51:16 pts/3 0:00 grep smon -
-
SQL> oradebug setospid 766348
-
Oracle pid: 30, Unix process pid: 766348, image: oracle@sxffdb2
(SMON)
-
SQL> oradebug tracefile_name
-
/u01/oracle/admin/testdb/bdump/testdb_smon_766348.trc
-
SQL> ! ls -ltr
/u01/oracle/admin/testdb/bdump/testdb_smon_766348.trc
-
-rw-r-----
1 oracle oinstall 1471 Aug 01 16:51 /u01/oracle/admin/testdb/bdump/testdb_smon_766348.trc -
-
SQL> ! rm -rf
/u01/oracle/admin/testdb/bdump/testdb_smon_766348.trc
-
-
SQL> oradebug close_trace
-
Statement processed.
-
SQL> ! ls -ltr
/u01/oracle/admin/testdb/bdump/testdb_smon_766348.trc
-
ls: 0653-341 The file
/u01/oracle/admin/testdb/bdump/testdb_smon_766348.trc does not
exist.
-
-
SQL> oradebug event 10046 trace name context forever,level
1;
-
Statement processed.
-
SQL> ! ls -ltr
/u01/oracle/admin/testdb/bdump/testdb_smon_766348.trc
-
-rw-r-----
1 oracle oinstall 651 Aug 01 16:53 /u01/oracle/admin/testdb/bdump/testdb_smon_766348.trc
清理打开的TRC文件:
-
[oracle@testdb bdump]$ ls
-ltr
testdb_smon_766348.trc
-
-rw-r-----
1 oracle oinstall 1766052 Aug 01 17:25 testdb_smon_766348.trc -
[oracle@sxffdb2 bdump]$ cat /dev/null > testdb_smon_766348.trc
--代替rm
-
[oracle@sxffdb2 bdump]$ ls -ltr testdb_smon_766348.trc
-
-rw-r-----
1 oracle oinstall 10 Aug 01 17:26 testdb_smon_766348.trc - [oracle@testdb bdump]$
较全面的步骤
一.
SYS@dave2(db2)> oradebug
help
1.1 TRACEFILE_NAME
command
This command prints the name of the
current trace file e.g.
SQL>oradebug
tracefile_name
For example
This command does not work on
Windows 2000 (Oracle 9.2)
1.2 UNLIMIT command
To remove the limitation on the size
of the trace file use
SQL>oradebug unlimit
1.3 FLUSH command
To flush the current contents of the
trace buffer to the trace file use
SQL>oradebug flush
1.4 CLOSE_TRACE command
To close the current trace file
use
SQL>oradebug
close_trace
二.
如果是系统的进程ID,可以使用oradebug setospid
id.
如果是根据Oracle ID,可以使用oradebug
setorapid id 来追踪。
2.1 查询进程ID
可以查询Linux系统的pid或是oracle自己的pid:
SYS@dave2(db2)> select
a.username,a.sid ,a.serial#,b.spid
USERNAME
---------- ---------- ----------
------------
SYS
查询spid
SYS@dave2(db2)> select pid,spid,username from
v$process;
--------- ------------
----------
v$process 下的pid 是Oracle 的ID。spid
是系统的ID。
2.2 设定追踪
SYS@dave2(db2)> oradebug setospid
27028
Oracle pid: 18, Unix process pid:
27028, image: oracledave2@db2
或者使用,他们是一样的:
SYS@dave2(db2)> oradebug
setorapid 18
Unix process pid: 27028, image:
oracledave2@db2
2.3
具体使用,可以参考:
SYS@dave2(db2)> oradebug
dumplist
EVENTS
TRACE_BUFFER_ON
TRACE_BUFFER_OFF
HANGANALYZE
LATCHES
PROCESSSTATE
SYSTEMSTATE
INSTANTIATIONSTATE
REFRESH_OS_STATS
.......
CONTEXTAREA
AWR_FLUSH_TABLE_OFF
ASHDUMP
MMON_TEST
SYS@dave2(db2)>
2.3.1 获得系统状态
如果为了获取全面一点的信息,可以使用Level
10。
SYS@dave2(db2)> oradebug setospid
27028
Oracle pid: 18, Unix process pid:
27028, image: oracledave2@db2
SYS@dave2(db2)> oradebug
unlimit
Statement processed.
SYS@dave2(db2)> oradebug dump
systemstate 10
Statement processed.
SYS@dave2(db2)> oradebug
TRACEFILE_NAME
/u01/app/oracle/admin/dave2/udump/dave2_ora_27028.trc
SYS@dave2(db2)> oradebug
close_trace
Statement processed.
[oracle@db2 ~]$ tail -50
/u01/app/oracle/admin/dave2/udump/dave2_ora_27028.trc
Dump of memory from 0x2E207970 to
0x2E207AF4
2E207970 00000000 00000000 00000000
00000000
2E207AF0
00000000
NO DETACHED BRANCHES.
NO DETACHED NETWORK
CONNECTIONS.
CLEANUP STATE OBJECTS:
----------------------------------------
SO: 0x2e03465c, type: 1, owner:
(nil), flag: INIT/-/-/0x00
(cleanup state object) description:
instance enqueue anchor state
latch: 0x2000502c
SO: 0x2e0346a0, type: 1, owner:
(nil), flag: INIT/-/-/0x00
(cleanup state object) description:
switchable channel handle anch
latch: 0x200059cc
----------------------------------------
SO: 0x2e0346e4, type: 1, owner:
(nil), flag: INIT/-/-/0x00
(cleanup state object) description:
TT shared object cleanup SO
latch: 0x2000dc98
----------------------------------------
SO: 0x2e034728, type: 1, owner:
(nil), flag: INIT/-/-/
(cleanup state object) description:
SS shared object cleanup
latch:
END OF SYSTEM
*** 2011-06-04
05:28:17.
Received ORADEBUG command
'TRACEFILE_NAME' from process Unix process pid: 27042,
*** 2011-06-04
05:32:21.241
Received ORADEBUG command
'close_trace' from process Unix process pid: 27042,
image:
[oracle@db2 ~]$
关于hanganalyze 参考:
2.3.2
SYS@dave2(db2)> oradebug setospid
27028
Oracle pid: 18, Unix process pid:
27028, image: oracledave2@db2
-- 注意,这里必须是Oracle 的进程
SYS@dave2(db2)> oradebug dump
processstate 10
Statement processed.
SYS@dave2(db2)> oradebug
TRACEFILE_NAME
/u01/app/oracle/admin/dave2/udump/dave2_ora_27028.trc
SQL> oradebug setospid
3188
2.3.3 获得进程的错误信息状态
SYS@dave2(db2)> oradebug dump
errorstack
3;
Statement processed.
SYS@dave2(db2)> oradebug
TRACEFILE_NAME
/u01/app/oracle/admin/dave2/udump/dave2_ora_27028.trc
三.
3.1 Trace a session SQL
3.1.1 使用DBMS_SYSTEM包
SQL>select a.username,a.sid
,a.serial#,b.spid from v$session a,v$process b
USERNAME
------------------------------
---------- ---------- -------------------- ---------- ----------
-------
SCOTT
--开启对该进程的trace,记录在trace文件中:
执行SQL> execute
dbms_system.set_sql_trace_in_session(143,6,true);
--关闭追踪
执行SQL> execute
dbms_system.set_sql_trace_in_session(143,6,false);
3.1.2使用oradebug
SQL> oradebug setospid
3260
SQL> oradebug event 10046 trace
name context forever,level 4
-- 取消追踪使用
SQL>
oradebug event 10046 trace name context off
已处理的语句
(此步是针对oradebug
event 10046 trace name context forever,level 4 的,
oradebug event 10046 trace name context off这步不执行,
而退出SQLPLUS 即SQL> EXIT;或SQL> oradebug close_trace时TRC日志仍在写入,
可重新登陆执行oradebug setospid SPID号,
再SQL>oradebug event 10046 trace name context forever,level [0-10],
再执行SQL>oradebug event 10046 trace name context off
就不会再写入日志)
3.1.3 Tracing errors use oradebug
例如要追踪能造成ORA-0094/952错误的会话,
SQL> oradebug event 942 trace name errorstack level 3
SQL> oradebug event 952 trace name errorstack level 3
四.
关于Events,
http://www.eygle.com/digest/2008/04/oracle_internal_events_introdu.html
Events可以在Instance一级Enabled,主要是在init.ora文件中做操作:
(1) 用一个冒号隔开
(2) 两个Events分开写
instance级别event:
enable:
Disable:
Session 级别Event:
--Enable:
--Disable:
Oradebug
--Process中Enable:
SQL>oradebug event event trace name context forever, level
level
--进程中Enable:
SQL>oradebug setorapid 8(pid进程号)
SQL>oradebug event event trace name context forever, level
level
SQL>oradebug event event trace name context off
Session Events:
--Enable:
--Disable:
SQL>oradebug session_event event trace name context off
使用DBMS_SYSTEM.SETEV包来实现Enable和Disable
先从V$session视图中获得SID和Serial#
--Enable:
SQL>execute dbms_system.set_ev(sid,serial#,event,level,
'')
SQL>execute dbms_system.set_ev (9,29,10046,8,'');
--Disable则将level改为0
SQL> execute dbms_system.set_ev (9,29,10046,0,'');
五.
From:
http://www.juliandyke.com/Diagnostics/Tools/ORADEBUG/Introduction.html
5.1 DUMP command
To perform a dump use
SQL>oradebug dump dumpname level
For example for a level 4 dump of the library cache use
SQL>oradebug setmypid
SQL>oradebug dump library_cache 4
5.2 EVENT command
To set an event in a process use
SQL>oradebug event event trace name context forever, level
level
For example to set event 10046, level 12 in Oracle process 8
use
SQL>oradebug setorapid 8
SQL>oradebug event 10046 trace name context forever, level
12
5.3 SESSION_EVENT command
To set an event in a session use
SQL>oradebug session_event event trace name context forever,
level level
For example
SQL>oradebug session_event 10046 trace name context forever,
level 12
5.4 DUMP SGA
To dump the fixed SGA use
SQL>oradebug dumpsga
5.5 DUMPVAR
To dump an SGA variable use
SQL>oradebug dumpvar sga variable_name
e.g.
SQL>oradebug dumpvar sga kcbnhb
5.6 PEEK
To peek memory locations use
SQL>oradebug peek address length
where address can be decimal or hexadecimal and length is in
bytes
For example
SQL>ORADEBUG PEEK 0x20005F0C 12
returns 12 bytes starting at location 0x20005f0c
5.7 POKE
To poke memory locations use
SQL>ORADEBUG POKE address length value
where address and value can be decimal or hexadecimal and length is
in bytes
For Example
SQL>ORADEBUG POKE 0x20005F0C 4 0x46495845
SQL>ORADEBUG POKE 0x20005F10 4 0x44205349
SQL>ORADEBUG POKE 0x20005F14 2 0x5A45
5.8 IPC
To dump information about operating system shared memory and
semaphores configuration use the command
SQL>ORADEBUG IPC
This command does not work on Windows NT or Windows 2000 (Oracle
9.2)
On Solaris, similar information can be obtained using the operating
system command
5.9 Dumping the SGA
In some versions it is possible to dump the entire SGA to a
file
Freeze the instance using
SQL>oradebug ffbegin
Dump the SGA to a file using
SQL>oradebug sgatofile directory
Unfreeze the instance using
SQL>oradebug ffresumeinst
参考blog.csdn.net/tianlesoftware/article/details/6525628