关于前端:如何使用Oracle跟踪文件

8次阅读

共计 1592 个字符,预计需要花费 4 分钟才能阅读完成。

为了演示跟踪文件的不便,因而咱们给一个普通用户 scott 授予 dba 的角色。

1、应用治理登录,并授予 scott 授予 dba 的角色

[oracle@oracle12c ~]$ sqlplus / as sysdba
SQL> grant dba to scott;
Grant succeeded.
SQL>

2、确定 Oracle SID,如下所示。这里的 SID 就是:orcl

SQL> select instance_name from V$instance;

INSTANCE_NAME

orcl
SQL>

3、切换到 scott 用户,并确定会话 ID

SQL> conn scott/tiger
Connected.
SQL> select sid from v$mystat where rownum=1;

   SID

70
SQL>

4、依据会话 ID,确定会话的地址信息

SQL> select paddr from v$session where sid=70;

PADDR

000000006DAB6588
SQL>

5、依据会话的地址信息,确定操作系统的过程号

SQL> select spid from v$process where addr=’000000006DAB6588′;

SPID

54685
SQL>

     进入页游目录 /u01/app/oracle/diag/rdbms/orcl/orcl/trace 会发现,此时并不存在蕴含 54685 的跟踪文件,起因是要应用跟踪文件须要手动开启会话的跟踪。

6、开启会话的跟踪

SQL> alter session set sql_trace=true;
Session altered.
SQL>

7、执行一条简略的 SQL 语句,并查看 www.sangpi.com/u01/app/oracle/diag/rdbms/orcl/orcl/trace 目录,这时候就能够看到生成的跟踪文件。

[oracle@oracle12c trace]$ pwd
/u01/app/oracle/diag/rdbms/orcl/orcl/trace
[oracle@oracle12c trace]$ ls *54685.trc
orcl_ora_54685.trc
[oracle@oracle12c trace]$

8、执行上面的的 SQL 语句

select * from scott.emp where deptno=10;
select * from scott.emp where deptno=20;
select * from scott.emp where deptno=30;

9、因为后面开启了会话的跟踪,如果不再须要进行跟踪了,须要手动敞开一下。

SQL> alter session set sql_trace=false;
Session altered.
SQL>

10、应用 tkprof 工具格式化跟踪文件

[oracle@oracle12c trace]$ tkprof orcl_ora_54685.trc /home/oracle/a.txt sys=no sort=fchela
TKPROF: Release 12.2.0.1.0 – Development on Mon Jun 28 10:37:48 2021
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
[oracle@oracle12c trace]$

11、查看生成的 a.txt 页游文件,如下所示:

SQL ID: 1mvxd868z75nf Plan Hash: 3956160932
select *
from scott.emp where deptno=30
SQL ID: 2nbac4n9hnzth Plan Hash: 3956160932
select *
from scott.emp where deptno=20
SQL ID: 062r5atccuyv4 Plan Hash: 3956160932
select *
from scott.emp where deptno=10

正文完
 0