当前位置:网站首页>[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 .
边栏推荐
- Btrfs and ext4 - features, strengths and weaknesses
- 3dslam with 16 line lidar and octomap
- Together, Shangshui Shuo series] day 9
- [set theory] relational closure (reflexive closure | symmetric closure | transitive closure)
- Installing altaro VM backup
- How does win7 solve the problem that telnet is not an internal or external command
- [teacher Zhao Yuqiang] redis's slow query log
- Final review (Day5)
- Beaucoup de CTO ont été tués aujourd'hui parce qu'il n'a pas fait d'affaires
- Why should we rewrite hashcode when we rewrite the equals method?
猜你喜欢
Exception when introducing redistemplate: noclassdeffounderror: com/fasterxml/jackson/core/jsonprocessingexception
Export the altaro event log to a text file
为什么网站打开速度慢?
6.23星期四库作业
PHP笔记超详细!!!
Gan network thought
大二困局(复盘)
About debugging the assignment of pagenum and PageSize of the formal parameter pageweb < T > (i.e. page encapsulation generic) in the controller
Latest version of source insight
2022.DAY592
随机推荐
Redhat7 system root user password cracking
今天很多 CTO 都是被幹掉的,因為他沒有成就業務
JS implements the problem of closing the current child window and refreshing the parent window
期末复习(Day2)
Altaro o365 total backup subscription plan
redis 无法远程连接问题。
Final review (day3)
Export the altaro event log to a text file
Altaro VM backup getting started
Azure file synchronization of altaro: the end of traditional file servers?
[together Shangshui Shuo series] day 7 content +day8
Complete set of C language file operation functions (super detailed)
Configure DTD of XML file
[function explanation (Part 1)] | | knowledge sorting + code analysis + graphic interpretation
Beaucoup de CTO ont été tués aujourd'hui parce qu'il n'a pas fait d'affaires
How to use source insight
Final review (Day6)
Talk about how to use p6spy for SQL monitoring
ninja: build stopped: subcommand failed.
卷积神经网络CNN中的卷积操作详解