Find the appropriate SQL statement by using the PID on the operating system

Source: Internet
Author: User

Linux platform, we generally through the top command to see the most performance-consuming process, if the see is Oracle, then we need to pass the process number, query the process currently executing SQL statements, Baidu Online has a lot of SQL, I generally find by the following way:find the SID of the corresponding SQL statement by using the PID on the operating system:
SELECT S.sid, p.spid from V$session S, v$process p WHERE s.paddr = p.addr and    


It then finds the specific contents 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 One
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 ')) OR DER by Piece asc/


Merge two:
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 = ' & ;p ID ') Order by q.piece;


Find the appropriate SQL statement by using the PID on the operating system

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.