Querying SQL statements that are executing and executing in Oracle _oracle

Source: Internet
Author: User

Querying the SQL statement that Oracle is executing and the user executing the statement

SELECT b.sid Oracleid,
    b.username login Oracle username,
    b.serial#,
    spid operating system ID,
    paddr,
    sql_text Executing sql ,
    b.machine computer name from
v$process A, v$session B, V$sqlarea c
WHERE a.addr = b.paddr and
  b.sql_hash_value = C.hash_value

The executing SQL statement code given by other netizens

Select A.username, A.sid,b.sql_text, b.sql_fulltext from
 v$session A, V$sqlarea b 
where a.sql_address = B.address 
---Executed
select B.sql_text,b.first_load_time,b.sql_fulltext from
 v$sqlarea b
where B. First_load_time between ' 2016-10-1/09:24:47 ' and
    ' 2016-10-1/09:24:47 ' ORDER by B.first_load_time

(This method benefits a view of SQL that has been executed for a period of time, and Sql_fulltext contains complete SQL statements)

Other

Select Osuser,program,username,schemaname,b.cpu_time,status,b.sql_text from 
v$session A left JOIN v$sql B on A.SQL_ Address=b.address and A.sql_hash_value=b.hash_value ORDER BY b.cpu_time desc 

Select Address, sql_text, piece 
 From V$session, v$sqltext 
where address = sql_address 
 --and machine = < you machine name > 

To view the issuing program of the initiator who is executing SQL

SELECT osuser Computer Login identity,
    program to initiate the request,
    USERNAME login system username,
    SCHEMANAME,
    b.cpu_time spend Cpu time,
    STATUS,
    B.sql_text executes SQL from
v$session a left
JOIN v$sql B on a.sql_address = b.address and
          a.sql_h Ash_value = B.hash_value ORDER by
B.cpu_time DESC

Identify Oracle's current locked object

SELECT l.session_id Sid,
    s.serial#,
    l.locked_mode lock mode,
    l.oracle_username login user,
    l.os_user_name Login machine username,
    s.machine machine name,
    s.terminal end user name,
    o.object_name locked object name,
    s.logon_time login database time from
v$  Locked_object L, all_objects o, v$session s
WHERE l.object_id = o.object_id and
  l.session_id = S.sid
Order by Sid, S.serial#;

Kill off the current lock object can be

Alter system kill session ' Sid, S.serial# ';

Find the first 10 poor performance SQL.

SELECT * FROM (select Parsing_user_id,executions,sorts, 
command_type,disk_reads,sql_text from V$sqlarea 

View the larger running session for IO

SELECT SE.SID,SE.SERIAL#,PR. Spid,se.username,se.status, 
Se.terminal,se.program,se. MODULE, se.sql_address,st.event,st. 
P1text,si.physical_reads, 
si.block_changes from V$session se,v$session_wait St, 
v$sess_io si,v$process PR WHERE St.sid=se.sid and St. 
Sid=si.sid and SE. Paddr=pr. ADDR and Se.sid>6 and St. 
Wait_time=0 and st.event not like '%sql% ' ORDER by Physical_reads DESC

This is the cloud Habitat Community small organized on the query Oracle in the execution and execution of the SQL statements related content, if you have a better way, please comment on the message, thank you

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.