当前位置:网站首页>[teacher Zhao Yuqiang] use Oracle's tracking file
[teacher Zhao Yuqiang] use Oracle's tracking file
2022-07-03 05:46:00 【Teacher zhaoyuqiang】

One 、 What is a tracking file ?
The trace file contains a lot of detailed diagnostic and debugging information . Through the interpretation and analysis of tracking files , We can position the problem 、 Analyze and solve problems . From the source of the trace file , Tracking files can be divided into two categories : One is generated intentionally by database operators ; The other is due to an abnormal error , Automatically generated by the database . For the latter category , Only right Oracle The in-house technical support staff are useful , But for us , Most of them don't understand . The former category , That's what we use all the time , Help us analyze 、 Adjust and optimize application performance , Deal with and solve problems .
So where can I find the trace file ? By querying the data dictionary v$diag_info You can determine the storage path of the trace file , As shown below .
select * from v$diag_info;
Entry directory /u01/app/oracle/diag/rdbms/orcl/orcl/trace You can see that trc Trace file for suffix , As shown in the figure below .

Two 、 Naming rules for trace files
The name of a trace file generally consists of the following parts :
- ORACLE_SID
- Fixed character
- Process of server ID Number
- File suffix .trc
- The parts are connected by the following lines .
for example :orcl_mmon_12210.trc, among :“orcl" It is the database in this environment SID,"12210" The server process used to generate the trace file session ID Number . How to know my ORACLE_SID And the server process used by the session ID Well ?
3、 ... and 、 How to determine the trace file ?
For the convenience of demonstration , We give it to an ordinary user scott grant dba Role .
1、 Log in with administration , And conferred scott grant dba Role
[[email protected] ~]$ sqlplus / as sysdba
SQL> grant dba to scott;
Grant succeeded.
SQL>
2、 determine Oracle SID, As shown below . there SID Namely :orcl
SQL> select instance_name from V$instance;
INSTANCE_NAME
----------------
orcl
SQL> 3、 Switch to scott user , And make sure the conversation ID
SQL> conn scott/tiger
Connected.
SQL> select sid from v$mystat where rownum=1;
SID
----------
70
SQL>
4、 According to the conversation ID, Determine the address information of the session
SQL> select paddr from v$session where sid=70;
PADDR
----------------
000000006DAB6588
SQL>
5、 According to the address information of the session , Determine the process number of the operating system
SQL> select spid from v$process where addr='000000006DAB6588';
SPID
------------------------
54685
SQL>
Entry directory /u01/app/oracle/diag/rdbms/orcl/orcl/trace Will find , There is no such thing as 54685 Tracking files for , The reason is that to use the trace file, you need to manually turn on the trace of the session .
6、 Turn on session tracking
SQL> alter session set sql_trace=true;
Session altered.
SQL>
7、 Perform a simple SQL sentence , And check /u01/app/oracle/diag/rdbms/orcl/orcl/trace Catalog , At this point, you can see the generated trace file .
[[email protected] trace]$ pwd
/u01/app/oracle/diag/rdbms/orcl/orcl/trace
[[email protected] trace]$ ls *54685.trc
orcl_ora_54685.trc
[[email protected] trace]$
Four 、 Use trace files to diagnose SQL
According to tracking, for diagnosis SQL Sentences are very useful , Here is a simple example to illustrate .
1、 Do the following SQL sentence
select * from scott.emp where deptno=10;
select * from scott.emp where deptno=20;
select * from scott.emp where deptno=30;These three SQL Check separately 10、20 and 30 Employees of Department . Through observation, we found that , These three SQL except where The parameter values of the condition are different , The other parts are the same . In this way SQL Statements are called “ Repetitive SQL”. If there is a lot of duplication in the database SQL, Will make every time in the execution will be carried out SQL Parsing , And then generate the execution plan . This will affect the performance of the database .
The following is to verify the above conclusion by tracking the file .
2、 Because the tracking of the session was turned on earlier , If tracking is no longer needed , You need to turn it off manually .
SQL> alter session set sql_trace=false;
Session altered.
SQL>
3、 Use tkprof Tools to format trace files
[[email protected] 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.
[[email protected] trace]$ 4、 View the generated a.txt file , As shown below :
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=10It can be seen that although there are three SQL Corresponding SQL ID Dissimilarity , But generated Plan Hash It's the same . This shows the three points SQL The implementation plan is the same . In that case , We can rewrite these three by binding variables SQL. Let these three SQL When a statement is executed , You don't have to generate an execution plan every time . Just reuse the execution plan generated for the first time . To improve performance .

边栏推荐
- chromedriver对应版本下载
- 3dslam with 16 line lidar and octomap
- Azure file synchronization of altaro: the end of traditional file servers?
- Linux登录MySQL出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
- NG Textarea-auto-resize
- [teacher Zhao Yuqiang] redis's slow query log
- Xaml gradient issue in uwp for some devices
- Notepad++ wrap by specified character
- Obtenir et surveiller les journaux du serveur distant
- If function of MySQL
猜你喜欢

Apache+PHP+MySQL环境搭建超详细!!!

Kubernetes resource object introduction and common commands (V) - (configmap)

Method of finding prime number
![[together Shangshui Shuo series] day 7 content +day8](/img/fc/74b12addde3a4d3480e98f8578a969.png)
[together Shangshui Shuo series] day 7 content +day8

How do I migrate my altaro VM backup configuration to another machine?

期末复习(Day5)

How to use source insight

MySQL 5.7.32-winx64 installation tutorial (support installing multiple MySQL services on one host)

Export the altaro event log to a text file

How does win7 solve the problem that telnet is not an internal or external command
随机推荐
Txt document download save as solution
Apache+PHP+MySQL环境搭建超详细!!!
Altaro o365 total backup subscription plan
Niuke JS separator
Btrfs and ext4 - features, strengths and weaknesses
Final review (Day2)
Understand one-way hash function
Explanation of variables, code blocks, constructors, static variables and initialization execution sequence of static code blocks of Ali interview questions
牛客网 JS 分隔符
Latest version of source insight
QT read write excel -- qxlsx insert chart 5
CAD插件的安装和自动加载dll、arx
2022.6.30DAY591
2022.6.30DAY591
Ext4 vs XFS -- which file system should you use
一起上水硕系列】Day 9
ES 2022 正式发布!有哪些新特性?
The request database reported an error: "could not extract resultset; SQL [n/a]; needed exception is org.hibernate.exception.sqlgram"
Altaro set grandfather parent child (GFS) archiving
期末复习(Day2)