查詢Oracle正在執行的sql語句及執行該語句的用戶
SELECT b.sid oracleID, b.username 登錄Oracle用戶名, b.serial#, spid 操作系統ID, paddr, sql_text 正在執行的SQL, b.machine 計算機名 FROM v$process a, v$session b, v$sqlarea c WHERE a.addr = b.paddr AND b.sql_hash_value = c.hash_value
其它網友給出的正在執行的sql語句代碼
select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXT from v$session a, v$sqlarea b where a.sql_address = b.address ---執行過的 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
(此方法好處可以查看某一時間段執行過的sql,並且 SQL_FULLTEXT 包含了完整的 sql 語句)
其他
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 > order by address, piece
查看正在執行sql的發起者的發放程序
SELECT OSUSER 電腦登錄身份, PROGRAM 發起請求的程序, USERNAME 登錄系統的用戶名, SCHEMANAME, B.Cpu_Time 花費cpu的時間, STATUS, B.SQL_TEXT 執行的sql 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
查出oracle當前的被鎖對象
SELECT l.session_id sid, s.serial#, l.locked_mode 鎖模式, l.oracle_username 登錄用戶, l.os_user_name 登錄機器用戶名, s.machine 機器名, s.terminal 終端用戶名, o.object_name 被鎖對象名, s.logon_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掉當前的鎖對象可以為
alter system kill session 'sid, s.serial#‘;
查找前十條性能差的sql.
SELECT * FROM (select PARSING_USER_ID,EXECUTIONS,SORTS, COMMAND_TYPE,DISK_READS,sql_text FROM v$sqlarea order BY disk_reads DESC )where ROWNUM<10 ;
查看占io較大的正在運行的session
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
以上就是小編整理的關於查詢Oracle中正在執行和執行過的SQL語句的相關內容,如果你有更好的方法,請評論留言,謝謝