当前位置:网站首页>[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=10
It 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 .
边栏推荐
- 6.23星期四库作业
- @Import annotation: four ways to import configuration classes & source code analysis
- How to install and configure altaro VM backup for VMware vSphere
- Installation du plug - in CAD et chargement automatique DLL, Arx
- Beaucoup de CTO ont été tués aujourd'hui parce qu'il n'a pas fait d'affaires
- [minesweeping of two-dimensional array application] | [simple version] [detailed steps + code]
- [escape character] [full of dry goods] super detailed explanation + code illustration!
- Crontab command usage
- [untitled]
- Skip table: principle introduction, advantages and disadvantages of skiplist
猜你喜欢
Altaro virtual machine replication failed: "unsupported file type vmgs"
How to set up altaro offsite server for replication
[branch and cycle] | | super long detailed explanation + code analysis + a trick game
Why should we rewrite hashcode when we rewrite the equals method?
6.23星期四库作业
Understand one-way hash function
求质数的方法
Classification and discussion of plane grab detection methods based on learning
Configure DTD of XML file
Exception when introducing redistemplate: noclassdeffounderror: com/fasterxml/jackson/core/jsonprocessingexception
随机推荐
【无标题】
Map的扩容机制
[advanced pointer (2)] | [function pointer, function pointer array, callback function] key analysis + code explanation
【无标题】
[minesweeping of two-dimensional array application] | [simple version] [detailed steps + code]
[written examination question analysis] | | get [sizeof and strlen] [pointer and array] graphic explanation + code analysis
Deploy crawl detection network using tensorrt (I)
@Import annotation: four ways to import configuration classes & source code analysis
期末复习(day3)
2022.7.2day594
70 shell script interview questions and answers
Life is a process of continuous learning
[advanced pointer (1)] | detailed explanation of character pointer, pointer array, array pointer
Talk about how to use p6spy for SQL monitoring
Method of finding prime number
Altaro VM backup getting started
"C and pointer" - Chapter 13 advanced pointer int * (* (* (*f) () [6]) ()
[escape character] [full of dry goods] super detailed explanation + code illustration!
@Autowired 导致空指针报错 解决方式
[teacher Zhao Yuqiang] redis's slow query log