Find the corresponding SQL statement using the PID in the operating system, and find the SQL statement using the pid.

Source: Internet
Author: User

Find the corresponding SQL statement using the PID in the operating system, and find the SQL statement using the pid.
In linux, we generally use the TOP command to view the processes with the largest performance consumption. If oracle is used, we need to query the SQL statements currently executed by the process through the process number, baidu has a lot of SQL statements on the Internet. I usually search through the following method: Find the corresponding SQL statement SID through the PID on the operating system:

SELECT s.sid, p.spid FROM v$session s, v$process p WHERE s.paddr = p.addr  AND  < p.spid = <os pid> 


Then, identify the specific content of the corresponding SQL statement through the SID:
 
SELECT s.sid, s.status, q.sql_text FROM v$session s, v$sqltext q WHERE s.sql_hash_value = q.hash_value AND s.sql_address = q.address AND s.sid = <sid> order by q.piece;

Merge 1
 
SELECT   /*+ ORDERED */         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/


Merge 2:
Select s.Sid, s.Status, q.Sql_TextFrom V$session s, V$sqltext qWhere s.Sql_Hash_Value = q.Hash_Value And s.Sql_Address = q.Address And                        s.Sid In (Select s.Sid                                                                 From V$session s, V$process p                                                                 Where s.Paddr = p.Addr And  p.Spid = '&pid' )Order By q.Piece;


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.