ORACLE CPU high sql query

1, according to the high number of CPU-intensive process to query SQL statement executed this process:

High CPU process numbers:

#首先找到CPU过高的进程号
# top -bn1 是静态找到占用最高的进程
 
[root@localhost ~]# top -bn1 | awk  '{print $1}'  | grep -A2 PID
 
Detailed command:  
  top: top command is commonly used under Linux performance analysis tools, real-time display resource usage status of each process in the system
  -bn1: Show all the process information (top -bn 1 shows all process information, top -n a screen displaying a message for the pipeline call)
   awk  '{print $1}':
    awk is used to extract the main toolbar; 
    {Print $} is to a line. 1 (a record) in a space as the first field delimiter print
 grep -A2 PID: (see the process ID of the first two rows) - A: front how many rows and displaying the matched lines, such as: -A3, matching said display rows and first three rows
 
 
 

 

SQL statement:

 

SELECT  sql_text
FROM  V$sqltext a
WHERE  (a.hash_value, a.address)
IN  ( SELECT  DECODE(sql_hash_value, 0 , prev_hash_value, sql_hash_value),
DECODE(sql_hash_value, 0 ,prev_sql_addr, sql_address)
FROM  v$session b
WHERE  b.paddr = ( SELECT  addr  FROM  v$process c  WHERE  c.spid =  '&pid' ))
ORDER  BY  piece  ASC ;
 
#######
ex:
SELECT  sql_text
FROM  v$sqltext a
WHERE  (a.hash_value, a.address)
IN  ( SELECT  DECODE(sql_hash_value, 0, prev_hash_value, sql_hash_value),
DECODE(sql_hash_value, 0, prev_sql_addr, sql_address)
FROM  v$session b
WHERE  b.paddr = ( SELECT  addr  FROM  v$process c  WHERE  c.spid =  '3515' ))
ORDER  BY  piece  ASC ;
 

 

Guess you like

Origin www.cnblogs.com/JIKes/p/12367369.html