首页 > 数据库 >Oracle Trace文件生成及查看 (zz)

Oracle Trace文件生成及查看 (zz)

时间:2023-07-04 13:31:45浏览次数:47  
标签:file set Trace trace SQL ---------- zz sql Oracle


Oracle Trace文件生成及查看 (zz)

1.Trace file简介:

Trace file(追踪文件)是以trc为后续的文本文件,它记录了各种sql操作及所消耗的时间等,根据trace文件我们就可以了解哪些sql导致了系统的性能瓶颈,进而采取恰当的方式调优.

2.怎么生成trace file:

1. 首先用sqlplus登陆Oracle.

show parameter sql_trace

Name          Type        Value

-------------------------------------------

sql_trace     boolean      false

如果value是false表示系统当前不会产生trace文件.采取如下操作让系统产生trace文件:

alter session set sql_trace=true;

或者:alter system set sql_trace=true;

2.执行一些sql语句后.停止产生trace文件.alter session(或system)  set sql_trace=false.

3.trace文件所在的默认路径.SELECT VALUE  FROM V$PARAMETER WHERE NAME = 'user_dump_dest'

我本机的查找结果是:C:\ORACLE\PRODUCT\10.2.0\ADMIN\ORA102\UDUMP.

3.怎么更改trace文件的保存目录:

如果是oracle 11g 以下的版本则:alter system set user_dump_dest = 'd:\oracle\trace';(注意:trace文件就直接生成在trace目录下)

如果是oracle 11g.则alter system set user_diagnostic_dest = 'd:\oracle\trace';(注意:trace文件不会直接生成在trace目录下.trace目录下会生成其他很多目录.

trace文件的具体目录是:d:\oracle\trace\diag\rdbms\orli11r2\orli11r2\trace.其中的orli11r2是SID)

4.怎么查看trace文件:

如果直接看trace文件是很难看懂的.就是下面的样子(我只是随便复制一段):

1319423003070764
 =====================
 PARSING IN CURSOR #2 len=90 dep=1 uid=0 oct=3 lid=0 tim=1319423003070864 hv=673844243 ad='7ecb9458' sqlid='9g485acn2n30m'
 select col#,intcol#,reftyp,stabid,expctoid from refcon$ where obj#=:1 order by intcol# asc
 END OF STMTPARSE #2:c=0,e=56,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,plh=2544153582,tim=1319423003070864
 BINDS #2: Bind#0oacdty=02 mxl=22(22) mxlc=00 mal=00 scl=00 pre=00
   oacflg=08 fl2=0001 frm=00 csi=00 siz=24 off=0 kxs

我们可以用oracle自带的工具TKPROF转化后再查看trace文件.转化后是下面的样子:

SQL ID : 0zzk39z279q41
SELECT version
FROM
product_component_version WHERE product LIKE 'Oracle%'

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        1      0.00       0.00          0          0          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        3      0.00       0.00          0          0          0           1

Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 69 

Rows     Row Source Operation
 -------  ---------------------------------------------------
       1  VIEW  PRODUCT_COMPONENT_VERSION (cr=0 pr=0 pw=0 time=0 us cost=2 size=168 card=2)
       1   SORT UNIQUE (cr=0 pr=0 pw=0 time=0 us cost=2 size=110 card=2)
       1    UNION-ALL  (cr=0 pr=0 pw=0 time=0 us)
       0     FIXED TABLE FULL X$VERSION (cr=0 pr=0 pw=0 time=0 us cost=0 size=55 card=1)
       1     FIXED TABLE FULL X$VERSION (cr=0 pr=0 pw=0 time=0 us cost=0 size=55 car

d=1)

********************************************************************************



To start a SQL trace for the currentsession, execute:

ALTERSESSION SET sql_trace = true;

You can also add an identifier tothe trace file name for later identification:

ALTERSESSION SET sql_trace = true;

ALTERSESSION SET tracefile_identifier = mysqltrace;

[] Stop session trace

To stop SQL tracing for the currentsession, execute:

ALTERSESSION SET sql_trace = false;

[] Tracing other user'ssessions

DBA's can use DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSIONto trace problematic database sessions. Steps:

• Get the SID and SERIAL# for the process you want to trace.
SQL>select sid, serial# from sys.v_$session where ...
       SID   SERIAL#
--------------------
         8     13607
• Enable tracing for your selected process:
SQL>ALTER SYSTEM SET timed_statistics = true;
SQL>execute dbms_system.set_sql_trace_in_session(8, 13607, true);
• Ask user to run just the necessary to demonstrate his problem.
• Disable tracing for your selected process:
SQL>execute dbms_system.set_sql_trace_in_session(8,13607, false);
• Look for trace file in USER_DUMP_DEST:
$cd /app/oracle/admin/oradba/udump
$ls -ltr
total8
-rw-r-----    1 oracle  dba         2764 Mar 30 12:37ora_9294.trc

[] Tracing an entiredatabase

To enable SQL tracing for the entiredatabase, execute:

ALTERSYSTEM SET sql_trace = true SCOPE=MEMORY;

To stop, execute:

ALTERSYSTEM SET sql_trace = false SCOPE=MEMORY;

[] Identifying trace files

Trace output is written to thedatabase's UDUMP directory.

The default name for a trace filesis INSTANCE_PID_ora_TRACEID.trc where:

  • INSTANCE is the name of the Oracle instance,
  • PID is the operating system process ID (V$PROCESS.OSPID); and
  • TRACEID is a character string of your choosing.

[] Size of trace files

The trace file size is limited bythe parameter MAX_DUMP_FILE_SIZE. The unit of this parameter, if you don'tspecify the K or M option, is in OS block size.

Be sure this parameter is set to avalue high enough for your purpose (e.g. some MB). Of course this depends onthe amount and complexitiy of statements which have to be run while tracing. Ifthis value is set too low, possibly the dump file size limit will be reachedbefore the execution of the crucial statements and the trace file will beclosed before the interesting parts can be recorded in it.

On the other hand, when thisparameter is set to UNLIMITED (default value), if the program to be traced isworking forth and forth and the trace mode is not finished, the trace file cangrow without limit which means until the associated file system or disk isfull. A DBA can stop the trace of a session using the DBMS_MONITOR (10g andup), DBMS_SYSTEM or DBMS_SUPPORT package.

[] Formatting output

Trace output is quite unreadable.However, Oracle provides a utility, called TKProf,that can be used to format trace output.

 



标签:file,set,Trace,trace,SQL,----------,zz,sql,Oracle
From: https://blog.51cto.com/u_16156420/6619702

相关文章

  • 2012年中国县级市面积排行(截止到2012年7月31日) (zz.IS2120@BG57IV3)
    2012年中国县级市面积排行(截止到2012年7月31日)//z2013-02-1813:12:[email protected][T146,L2083,R63,V2084]说明:1、以下数据由宜居城市研究室统计整理,统计时间截止到2012年7月31日,与县级市同级的县、旗等不计算入内;2、以下面积均指陆地面积,不包括海域面积,入榜县......
  • bpftune oracle linux 试用体验
    今天有测试bpftune与Rockylinux的集成,发现构建是可以成功的,但是运行会有问题(提示不支持,应该用过修改可以解决),为了更好的测试,自己跑了一个oraclelinux虚拟机跑下环境搭建通过utm+oraclelinux8.8,还是比较简单的ios下载地址:链接:https://pan.baidu.com/s/1L6ZB-2_......
  • Oracle中类似于isql或osql的命令行工具
    sqlplususer/passwd@server_name@filenameserver_name是配置在tnsname.ora中,也可以用netmanager配置APLOI2=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=fitwsnydb1d.nam.nsroot.net)(PORT=1523)))(CONNECT_DATA=......
  • python连接Oracle数据库实现数据查询并导入MySQL数据库
    1.项目背景由于项目需要连接第三方Oracle数据库,并从第三方Oracle数据库中查询出数据并且显示,而第三方的Oracle数据库是Oracle11的数据库。而django4.1框架支持支持Oracle数据库服务器19c及以上版本,需要7.0或更高版本的cx_OraclePython驱动;django3.2支持Oracle数据库......
  • Dozzle 获取远程主机容器日志
    Dozzle项目Dozzle是一个小巧且轻量级的应用程序,具有基于Web的界面,用于监视Docker日志。它不会存储任何日志文件,仅用于实时监视容器日志。项目地址:https://github.com/amir20/dozzle生成证书1、生成CA(根证书)私钥和自签名证书:opensslreq-x509-nodes-newkeyrsa:4096-ke......
  • oracle 中的常用exception
    1、异常的优点如果没有异常,在程序中,应当检查每个命令的成功还是失败,如BEGINSELECT...--checkfor’nodatafound’errorSELECT...--checkfor’nodatafound’errorSELECT...--checkfor’nodatafound’error这......
  • Oracle修改表列名与顺序的解决方案 (sql 修改列名)
    Oracle10g修改表列名与顺序的解决方案-下面介绍通过修改数值字典的方法修改表的列名:假设在SCOTT帐号下有HB_TEST表:----------------------------------------------------------------------目的:调换STU_ID和STU_NAME的顺序;并把STU_ID改为S_ID;SQL>SELECT*FRO......
  • oracle 表查询变慢的原因-项目
     1)     abovesqldidfulltablescanitexecuted37timeandtookaround10minDELETEFROMPF_LIQUDATION_DETAILS_EODWHEREPORTFOLIOID=:B2ANDASOFDATE=:B1 WeneedtolookattheindexesforthesePF_*tablesandaddindexessothatwecanreducethe......
  • 记录一下Oracle排序 将空值排在最后面
    select*fromtableorderbyxxx(字段)desc 今天在写Oracle排序的时候突然发现,Oracle默认将null值放最上面使用nullsfirst或者nullslast语法Nullsfirst和nullslast是OracleOrderby支持的语法如果Orderby中指定了表达式Nullsfirst则表示null值的记录将排在最前( ......
  • OGG-02912 Patch 17030189 is required on your Oracle mining database for trail fo
    Therewillbeascript"prvtlmpg.plb"undergghomedirectory[oracle@OGGR2-1ogg]$ls-lrtprvtlmpg.plb-rw-r-----1oracleoinstall9487May272015prvtlmpg.plb[oracle@OGGR2-1ogg]$pwd/ogg[oracle@OGGR2-1ogg]$Logintothedatabaseand......