『壹』 oracle查詢鎖表與解鎖情況提供解決方案
如果發生了鎖等待,我們可能更想知道是誰鎖了表而引起誰的等待
以下的語句可以查詢到誰鎖了表:
復制代碼
代碼如下:
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
以下的語句可以查詢到誰在等待:
復制代碼
代碼如下:
SELECT
/*+
rule
*/
lpad('
',decode(l.xisn
,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,xisn
DESC
解鎖命令:
復制代碼
代碼如下:
alter
system
kill
session
'sid,serial#'
1).
復制代碼
代碼如下:
select
LOCK_INFO.OWNER
||
'.'
||
LOCK_INFO.OBJ_NAME
as
"已鎖物件名稱",
--物件名稱(已經被鎖住)
LOCK_INFO.SUBOBJ_NAME
as
"已鎖子物件名稱",
--
子物件名稱(已經被鎖住)
SESS_INFO.MACHINE
as
"機器名稱",
--
機器名稱
LOCK_INFO.SESSION_ID
as
"會話ID",
--
會話SESSION_ID
SESS_INFO.SERIAL#
as
"會話SERIAL#",
--
會話SERIAL#
SESS_INFO.SPID
as
"OS系統的SPID",
--
OS系統的SPID
(SELECT
INSTANCE_NAME
FROM
V$INSTANCE)
"實例名SID",
--實例名SID
LOCK_INFO.ORA_USERNAME
as
"ORACLE用戶",
--
ORACLE系統用戶名稱
LOCK_INFO.OS_USERNAME
as
"OS用戶",
--
作業系統用戶名稱
LOCK_INFO.PROCESS
as
"進程編號",
--
進程編號
LOCK_INFO.OBJ_ID
as
"對象ID",
--
對象ID
LOCK_INFO.OBJ_TYPE
as
"對象類型",
--
對象類型
SESS_INFO.LOGON_TIME
as
"登錄時間",
--
登錄時間
SESS_INFO.PROGRAM
as
"程式名稱",
--
程式名稱
SESS_INFO.STATUS
as
"會話狀態",
--
會話狀態
SESS_INFO.LOCKWAIT
as
"等待鎖",
--
等待鎖
SESS_INFO.ACTION
as
"動作",
--
動作
SESS_INFO.CLIENT_INFO
as
"客戶資訊"
--
客戶資訊
from
(select
obj.OWNER
as
OWNER,
obj.OBJECT_NAME
as
OBJ_NAME,
obj.SUBOBJECT_NAME
as
SUBOBJ_NAME,
obj.OBJECT_ID
as
OBJ_ID,
obj.OBJECT_TYPE
as
OBJ_TYPE,
lock_obj.SESSION_ID
as
SESSION_ID,
lock_obj.ORACLE_USERNAME
as
ORA_USERNAME,
lock_obj.OS_USER_NAME
as
OS_USERNAME,
lock_obj.PROCESS
as
PROCESS
from
(select
*
from
all_objects
where
object_id
in
(select
object_id
from
v$locked_object))
obj,
v$locked_object
lock_obj
where
obj.object_id
=
lock_obj.object_id)
LOCK_INFO,
(select
SID,
SERIAL#,
LOCKWAIT,
STATUS,
(select
spid
from
v$process
where
addr
=
a.paddr)
spid,
PROGRAM,
ACTION,
CLIENT_INFO,
LOGON_TIME,
MACHINE
from
v$session
a)
SESS_INFO
where
LOCK_INFO.SESSION_ID
=
SESS_INFO.SID
order
by
LOCK_INFO.SESSION_ID;
2).
復制代碼
代碼如下:
select
sql_text
from
v$sqltext
where
address
in
(select
sql_address
from
v$session
where
sid
=
&sid)
order
by
piece;
3).
復制代碼
代碼如下:
ALTER
SYSTEM
KILL
SESSION
'會話ID,會話SERIAL#';
4).
kill
-9
OS系統的SPID
『貳』 oracle資料庫表被鎖了不能操作怎麼辦
首先你要知道表鎖住了是不是正常鎖?因為任何DML語句都會對表加鎖。
你要先查一下是那個會話那個sql鎖住了表,有可能這是正常業務需求,不建議隨便KILL
session,如果這個鎖表是正常業務你把session
kill掉了會影響業務的。
建議先查原因再做決定。
(1)鎖表查詢的代碼有以下的形式:
select
count(*)
from
v$locked_object;
select
*
from
v$locked_object;
(2)查看哪個表被鎖
select
b.owner,b.object_name,a.session_id,a.locked_mode
from
v$locked_object
a,dba_objects
b
where
b.object_id
=
a.object_id;
(3)查看是哪個session引起的
select
b.username,b.sid,b.serial#,logon_time
from
v$locked_object
a,v$session
b
where
a.session_id
=
b.sid
order
by
b.logon_time;
(4)查看是哪個sql引起的
select
b.username,b.sid,b.serial#,c.*
from
v$locked_object
a,v$session
b,v$sql
c
where
a.session_id
=
b.sid
and
b.SQL_ID
=
c.sql_id
and
c.sql_id
=
''
order
by
b.logon_time;
(5)殺掉對應進程
執行命令:alter
system
kill
session'1025,41';
其中1025為sid,41為serial#.
『叄』 oracle 鎖表、解鎖的語句
1.正確方法用 select xxx from table for update; <- 鎖表
直接用update table set xxx的話,只能鎖row
不要commit的意思是不提交該transaction。若commit或rollback,則釋放所有lock資源
2.commit = confirm 確認並提交該次會話中的修改
rollback = cancel 取消該次會話
『肆』 sql資料庫如何解鎖呢
你先查一下你的數據表示不是鎖表了。
select sess.sid,
sess.serial#,
lo.oracle_username,
lo.os_user_name,
ao.object_name,
lo.locked_mode
from v$locked_object lo,
dba_objects ao,
v$session sess
where ao.object_id = lo.object_id and lo.session_id = sess.sid
通過以上sql就可以知道哪個進程、序列,oracle用戶名、操作系統用戶名、表名、鎖表模式幾個欄位
下面一步就是將改鎖表的進程和序列殺掉了,執行下面的語句即可。
alter system kill session '1020,38953' --(1020,就是執行第一步語句得到的sid欄位值,38953就是serial#欄位值)
詳細的請參照:網頁鏈接
『伍』 oracle鎖表多長時間自動解鎖
oracle鎖表不會自動解鎖。根據查詢相關資料顯示,oracle鎖表想要解鎖需要余帶逗,找系統管理員,行敗終止掉你豎賣之前的session,就可以了。會rollback回來。有管理者許可權的話,通過客戶端,一樣可以做到的。
『陸』 orcal資料庫表被鎖了怎麼解鎖
1、在做Oracle監聽程序測試時,發現帳戶已經被鎖定。
『柒』 ORACLE 如何查詢被鎖定表及如何解鎖釋放session
ORACLE
EBS操作某一個FORM界面,或者後台資料庫操作某一個表時發現一直出於"假死"狀態,可能是該表被某一用戶鎖定,導致其他用戶無法繼續操作
復制代碼
代碼如下:--鎖表查詢SQLSELECT
object_name,
machine,
s.sid,
s.serial#
FROM
gv$locked_object
l,
dba_objects
o,
gv$session
s
WHERE
l.object_id
=
o.object_id
AND
l.session_id
=
s.sid;
找到被鎖定的表,解鎖
復制代碼
代碼如下:--釋放SESSION
SQL:
--alter
system
kill
session
'sid,
serial#';
您可能感興趣的文章:mysql
事務處理及表鎖定深入簡析
『捌』 oracle查詢資源佔用,鎖表解鎖
1. 先通過top命令查看產用資廳正源較多的spid號
2.查詢當前耗時的會話ID,扮雹悔用戶名,sqlID等:
select sid,serial#,machine,username,program,sql_hash_value,sql_id,
to_char(logon_time,'yyyy/mm/dd hh24:mi:ss') as login_time from v$session
where paddr in (select addr from v$process where spid in ('5648612','256523'));
3. 如果上一步sql_id或者 hash_value不為空,則可用v$sqlarea查出當前正在使用的sql
select sql_text
from v$sqltext_with_newlines
where hash_value = &hash_value
order by piece;
也可直接使用:
select a.*,b.SQL_TEXT from (
select sid,serial#,machine,username,program,sql_hash_value,sql_id,
to_char(logon_time,'yyyy/mm/dd hh24:mi:ss') as login_time from v$session
where paddr in (select addr from v$process where spid in ('23226'))
) a,v$sql b
where a.sql_id = b.SQL_ID(+)
4.kill佔用大資肆銀源的session
Alter system kill session 'SID,SERIAL#'
解鎖:
1.查詢哪些對象被鎖:
select object_name,machine,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;
2.下面的語句用來殺死一個進程:
alter system kill session '524,1095'; (其中24,111分別是上面查詢出的sid,serial#)
3.再一次查詢目前鎖定的對象,若發現以上方法不能解除鎖定的表,則用以下方法:
3.1 執行下面的語句獲得進程(線程)號:
select spid, osuser, s.program
from v$session s,v$process p
where s.paddr=p.addr and s.sid=524 (524是上面的sid)
『玖』 oracle 表被鎖住 怎麼解鎖
一般先查詢並找到被鎖定的表,解鎖代碼如下:
--釋放SESSION余緩SQL:
--altersystemkillsession'sid,serial#';
ALTERsystem信慎kill豎坦模session'23,1647';
『拾』 查詢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#;
解鎖:ALTER system KILL session 'sid,serial#';
查詢鎖住原因: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 and b.USERNAME='FKPHIS24';