oracle 查詢鎖和 正在執行的SQL

2021-09-22 18:37:01 字數 4575 閱讀 2574

查詢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 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#;

栗子:

select s.machine         sourse_host,

p.spid pid,

l.session_id sid,

s.serial#,

l.locked_mode,

l.oracle_username,

s.user#,

l.os_user_name,

s.terminal,

a.sql_text,

a.action

from v$sqlarea a, v$session s, v$locked_object l, sys.v_$process p

where l.session_id = s.sid

and s.prev_sql_addr = a.address

and s.paddr = p.addr

order by sid, s.serial#;

kill掉當前的鎖物件:

alter system kill session 'sid, s.serial#『;
查詢當前正在執行的事務:

select s.sid,  

s.serial#,

s.event,

a.sql_text,

a.sql_fulltext,

s.username,

s.status,

s.machine,

s.terminal,

s.program,

a.executions,

s.sql_id,

p.spid,

a.direct_writes

from (select * from v$session where status = 'active') s

left join v$sqlarea a

on s.sql_id = a.sql_id

inner join v$process p

on s.paddr = p.addr

檢視oracle 資料庫中的長事務:

with transaction_details as  

( select inst_id

, ses_addr

, sysdate - start_date as diff

from **$transaction

) select s.username

, to_char(trunc(t.diff))

|| ' days, '

|| to_char(trunc(mod(t.diff * 24,24)))

|| ' hours, '

|| to_char(trunc(mod(t.diff * 24 * 60,24)))

|| ' minutes, '

|| to_char(trunc(mod(t.diff * 24 * 60 * 60,60)))

|| ' seconds' as transaction_duration

, s.program

, s.terminal

, s.status

, s.sid

, s.serial#

from **$session s

, transaction_details t

where s.inst_id = t.inst_id

and s.saddr = t.ses_addr

order by t.diff desc

查詢長事務sql

with ltr as ( 

select to_char(sysdate,'yyyymmddhh24miss') tm,

s.sid,

s.sql_id,

s.sql_child_number,

s.prev_sql_id,

xid,

to_char(t.start_date,'yyyymmddhh24miss') start_time,

e.type,e.block,

e.ctime,

decode(e.ctime, 0, (sysdate - t.start_date) * 3600*24, e.ctime) el_second

-- q.sql_text

from v$transaction t, v$session s,v$transaction_enqueue e

where t.start_date <= sysdate - interval '100' second /*查詢開始多少秒的事務*/

and t.addr = s.taddr

--and s.sql_child_number = q.child_number(+)

--and s.sql_id = q.sql_id(+) and s.prev_sql_id = q.sql_id(+)

and t.addr = e.addr(+) )

select ltr.* , (select q1.sql_text from v$sql q1 where ltr.prev_sql_id = q1.sql_id(+)

and rownum = 1) prev_sql_text ,

(select q1.sql_text from v$sql q1 where ltr.sql_id = q1.sql_id(+)

and ltr.sql_child_number = q1.child_number(+)) sql_text

from ltr ltr;

檢視表操作的sql語句

select *

from v$sql

where hash_value in (select from_hash

from v$object_dependency

where to_owner = 』table owner』

and to_name = 』marketorder』);

檢視sql對應的繫結引數

select

s.sql_text,

b.name,b.position,b.dup_position,

b.value_string

from v$sql s, v$sql_bind_capture b

where s.hash_value=b.hash_value;

查詢Oracle正在執行的sql

查詢oracle正在執行的sql語句及執行該語句的使用者 select b.sid oracleid,b.username 登入oracle使用者名稱,b.serial spid 作業系統id,paddr,sql text 正在執行的sql,b.machine 計算機名 from v process...

查詢Oracle正在執行和執行過的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...

查詢Oracle正在執行和執行過的SQL語句

正在執行的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 執行過的sql select b.sql text,b.firs...