如何檢視死鎖時在執行的SQL語句

2021-04-24 13:37:35 字數 3412 閱讀 9599

指令碼一,查出鎖的關係,誰把誰鎖主了

set serveroutput on

declare

mes varchar2(2000);

tmp_id1 number(22);

tmp_id2 number(22);

lk_sid    number(22);

tmp_mac varchar2(64);

fl boolean;

begin

fl:=false;

for c1 in (select sid,serial#,machine,lockwait

from v$session

where lockwait is not null) loop

fl:=true;

mes:='sid:'||to_char(c1.sid)||','||c1.machine||'is be locked by sid ';

select id1,id2 into tmp_id1,tmp_id2

from v$lock where sid=c1.sid and kaddr=c1.lockwait;

for c2 in (select sid    lk_sid   from  v$lock where sid!=c1.sid and id1=tmp_id1 and  id2=tmp_id2 and block='1') loop

select machine into tmp_mac from v$session where sid=c2.lk_sid;

dbms_output.put_line(mes||to_char(c2.lk_sid)||' '||tmp_mac);

end loop;

end loop;

if not fl then

dbms_output.put_line('目前系統中沒有互鎖現象');

end if;

end;

/第二,相應的sid最近執行的sql

set verify off

column a.username format a10

column c.sql_text format a64

accept sid prompt 'please enter the sid '

select a.username, c.sql_text

from v$session a, v$sqltext c

where a.sid=&sid and

c.hash_value = a.sql_hash_value and

c.address = a.sql_address

order by c.piece

/首先檢視alert.log檔案,查詢ora-60錯誤,其中指明了詳細日誌

檔案的路徑。

alert.log在background_dump_dest引數指定的目錄下

deadlock日誌檔案在user_dump_dest引數指定的目錄下

select username,default_tablespace from user_users;

select * from user_role_privs;

select * from user_sys_privs;

select * from user_tab_privs;

select * from user_tables;

select object_name,object_id from user_objects

where instr(object_name,'log')>0;

select object_name,created from user_objects where object_name=upper

('&table_name');

select * from user_sequences;

select view_name from user_views;

select member from v$logfile;

select version from product_component_version

where substr(product,1,6)='oracle';

用系統管理員,檢視當前資料庫

有幾個使用者連線:

sql> select username,sid,serial# from v$session;

如果要停某個連線用

sql> alter system kill session 'sid,serial#';

如果這命令不行,找它unix的程序數

sql> select pro.spid from v$session ses,v$process pro where ses.sid=21

and ses.paddr=pro.addr;

說明:21是某個連線的sid數

然後用 kill 命令殺此程序號。

select column_name,comments from dict_columns where

table_name='user_indexes';

select column_name,comments from dict_columns where upper(table_name)

='v$session';

如何檢視最大會話數?

select * from v$parameter where name like 'proc%';

select * from v$license;

select *  from  user_errors;

select * from v$instance;

select a.sid,spid,status,substr(a.program,1,40)

prog,a.terminal,osuser,value/60/100 value

from v$session a,v$process b,v$sesstat c

where c.statistic#=11 and c.sid=a.sid and a.paddr=b.addr order by

value desc;

select * from v$sqltext where address = 'c0000001e0b4a160';

select sql_text, piece, hash_value

from v$sqltext

where  address = 'c0000001e0b4a160'

order by hash_value, piece;

select * from v$sqlarea where address = (select sql_address from

v$session where sid = :1);

檢視死鎖的SQL語句

use master go declare spid int,bl int declare s cur cursor for select 0 blocked from select from sysprocesses where blocked 0 a where not exists selec...

SQL SERVER 檢視死鎖和阻塞的SQL語句

檢視死鎖 select t1.resource type 資源鎖定型別 db name resource database id as 資料庫名,t1.resource associated entity id 鎖定物件,t1.request mode as等待者請求的鎖定模式,t1.request...

Oracle檢視正在執行的sql

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