檢視鎖定項:表鎖定、行鎖定等,如下**
select /*+ rule */ s.username,
decode(l.type,'tm','table lock',
'tx','row lock',
null) lock_level,
o.owner,o.object_name,o.object_type,
s.sid,s.serial#,s.terminal,s.machine,s.program,s.osuser
from v$session s,v$lock l,dba_objects o
where l.sid = s.sid
and l.id1 = o.object_id(+)
and s.username is not null
解鎖語句如下
alter system kill session'sid,serial';
1.查出鎖定object的session的資訊以及被鎖定的object名
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# ;
--2.查出鎖定表的session的sid, serial#,os_user_name, machine name, terminal和執行的語句
--比上面那段多出sql_text和action
select l.session_id sid, s.serial#, l.locked_mode, l.oracle_username, s.user#,
l.os_user_name,s.machine, s.terminal,a.sql_text, a.action
from v$sqlarea a,v$session s, v$locked_object l
where l.session_id = s.sid
and s.prev_sql_addr = a.address
order by sid, s.serial#;
--3.查出鎖定表的sid, serial#,os_user_name, machine_name, terminal,鎖的type,mode
select s.sid, s.serial#, s.username, s.schemaname, s.osuser, s.process, s.machine,
s.terminal, s.logon_time, l.type
from v$session s, v$lock l
where s.sid = l.sid
and s.username is not null
order by sid;
這個語句將查詢到資料庫中所有的dml語句產生的鎖,還可以發現,
任何dml語句其實產生了兩個鎖,乙個是表鎖,乙個是行鎖。
殺鎖命令
alter system kill session 'sid,serial#'
select /*+ rule */ s.username,
decode(l.type,'tm','table lock',
'tx','row lock',
null) lock_level,
o.owner,o.object_name,o.object_type,
s.sid,s.serial#,s.terminal,s.machine,s.program,s.osuser
from v$session s,v$lock l,dba_objects o
where l.sid = s.sid
and l.id1 = o.object_id(+)
and s.username is not null
合併鎖定項及批量匯出語句方法如下:
set echo on -------是否顯示執行的命令內容
set feedback off --------是否顯示* rows selected
set heading off --------是否顯示欄位名稱
set verify off ---------是否顯示替代變數被替代前後的語句。
set trimspool on --------去字段空格
set pagesize 1000 --------頁面大小
set linesize 50 --------盡量根據需要來定,生成檔案大小
define fil='d:\exp.txt'
prompt * * * spooling to &fil
spool on
spool &fil
select 'alter system kill session ',''''||trim(t2.sid)||','||trim(t2.serial#)||''';'
from v$locked_object t1,v$session t2 where t1.session_id=t2.sid order by t2.logon_time;//該部分只查詢出sid和serial#值;
spool off
如果想知道鎖用了哪個回滾段,還可以關聯到v$rollname,其中xidusn就是回滾段的usn
col user_name format a10
col owner format a10
col object_name format a10
col object_type format a10
select /*+ rule */ lpad(' ',decode(l.xidusn ,0,3,0))||l.oracle_username user_name,
o.owner,o.object_name,o.object_type,s.sid,s.serial#
from v$locked_object l,dba_objects o,v$session s
where l.object_id=o.object_id
and l.session_id=s.sid
order by o.object_id,xidusn desc
Oracle資料庫解鎖
該指令碼是用來檢驗系統中誰在鎖表 select a.sid,b.serial decode a.type,mr media recovery rt redo thread un user name tx transaction tm dml ul pl sql user lock dx distri...
oracle資料庫表解鎖
我們常常在運算元據庫時會遇到 某個dml操作可能等待很久沒有反應 遇到這種情況多半是因為表被鎖住了,那麼如何解鎖呢?檢視哪個表被鎖 select sess.sid,sess.serial lo.oracle username,lo.os user name,ao.object name,lo.loc...
關於oracle資料庫解鎖
microsoft windows 版本 10.0.14393 c 2016 microsoft corporation。保留所有權利。c windows system32 sqlplus nolog sql plus release 10.2.0.1.0 production on 星期日 7月 ...