当前位置:网站首页>[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 .

边栏推荐
- How does win7 solve the problem that telnet is not an internal or external command
- Training method of grasping angle in grasping detection
- Explanation of variables, code blocks, constructors, static variables and initialization execution sequence of static code blocks of Ali interview questions
- Latest version of source insight
- [set theory] relational closure (reflexive closure | symmetric closure | transitive closure)
- Btrfs and ext4 - features, strengths and weaknesses
- Exception when introducing redistemplate: noclassdeffounderror: com/fasterxml/jackson/core/jsonprocessingexception
- 期末复习DAY8
- Analysis of the example of network subnet division in secondary vocational school
- Simpleitk learning notes
猜你喜欢

Communication - how to be a good listener?

Redis cannot connect remotely.

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

How does win7 solve the problem that telnet is not an internal or external command

PHP笔记超详细!!!
![[branch and cycle] | | super long detailed explanation + code analysis + a trick game](/img/aa/543d4f0dcbcd664be963579af77ec9.jpg)
[branch and cycle] | | super long detailed explanation + code analysis + a trick game

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

DEX net 2.0 for crawl detection

Deploy crawl detection network using tensorrt (I)

Export the altaro event log to a text file
随机推荐
Latest version of source insight
Win10 install pytullet and test
Altaro requirements for starting from backup on Hyper-V
70 shell script interview questions and answers
Today, many CTOs were killed because they didn't achieve business
Map的扩容机制
"C and pointer" - Chapter 13 function pointer 1: callback function 2 (combined with template to simplify code)
Best practices for setting up altaro VM backups
Kubernetes resource object introduction and common commands (V) - (configmap)
Installing altaro VM backup
The request database reported an error: "could not extract resultset; SQL [n/a]; needed exception is org.hibernate.exception.sqlgram"
期末复习DAY8
Making coco datasets
Crontab command usage
Installation of CAD plug-ins and automatic loading of DLL and ARX
Final review (Day2)
Es 2022 officially released! What are the new features?
How does win7 solve the problem that telnet is not an internal or external command
@Import annotation: four ways to import configuration classes & source code analysis
About debugging the assignment of pagenum and PageSize of the formal parameter pageweb < T > (i.e. page encapsulation generic) in the controller