一.查看数据库锁,诊断锁的来源及类型
Select object_id,session_id,locked_mode From v$locked_object;
或者:
Select b.owner,b.object_name,l.session_id,l.locked_mode
From v$locked_object l, dba_objects b
Where b.object_id=l.object_id
二.找出serial#值
Select t2.username,t2.sid,t2.serial#,t2.logon_time,t2.OSUSER, t2.MACHINE,t2.PROGRAM,t2.MODULE,t2.LOGON_TIME,t2.STATE From v$locked_object t1,v$session t2 Where t1.session_id=t2.sid Order by t2.logon_time;
三.KILL session
Alter system Kill session 'sid,serial#'
==========================================================================================================================
select * from v$locked_object a,dba_objects b
where b.object_id=a.OBJECT_ID
==========================================================================================================================
一、处理过程
1.通过查找出已被锁定的数据库表及相关的sid、serial#及spid:
select object_name as 对象名称,s.sid,s.serial#,p.spid as 系统进程号
from v$locked_object l , dba_objects o , v$session s , v$process p
where l.object_id=o.object_id and l.session_id=s.sid and s.paddr=p.addr;
2.在数据库中灭掉相关session:
alter system kill session 'sid,serial#';
--sid及serial#为第一步查出来的数据
3.从系统中灭掉与该session对应的进程:
kill -9 spid;
--spid为第一步中查出来的系统进程号
经过以上操作之后重新对之前锁定的对象进行操作应该就可以了。
二、使用了相关表的基本介绍
V$LOCKED_OBJECT中的列说明:
XIDUSN:回滚段号
XIDSLOT:槽号
XIDSQN:序列号
OBJECT_ID:被锁对象ID
SESSION_ID:持有锁的sessionID
ORACLE_USERNAME:持有锁的Oracle 用户名
OS_USER_NAME:持有锁的操作系统 用户名
PROCESS:操作系统进程号
LOCKED_MODE:锁模式
dba_objects的列说明(网上找的,懒得翻译了^_^)
OWNER
Username of the owner of the object
OBJECT_NAME
Name of the object
SUBOBJECT_NAME
Name of the sub-object (for example,partititon)
OBJECT_ID
Object number of the object
DATA_OBJECT_ID
Object number of the segment which contains the object
OBJECT_TYPE
Type of the object
CREATED
Timestamp for the creation of the object
LAST_DDL_TIME
Timestamp for the last DDL change (including GRANT and REVOKE) to the object
TIMESTAMP
Timestamp for the specification of the object
STATUS
Status of the object
TEMPORARY
Can the current session only see data that it place in this object itself?
GENERATED
Was the name of this object system generated?
SECONDARY
Is this a secondary object created as part of icreate for domain indexes?
v$session的说明
V$SESSION是基础信息视图,用于找寻用户SID或SADDR
常用列:
SID:SESSION标识
SERIAL#:如果某个SID又被其它的session使用的话则此数值自增加(当一个SESSION结束,另一个SESSION开始并使用了同一个SID)。
AUDSID:审查session ID唯一性,确认它通常也用于当寻找并行查询模式
USERNAME:当前session在oracle中的用户名。
STATUS:这列用来判断session状态是:
Achtive:正执行SQL语句(waiting for/using a resource)
Inactive:等待操作(即等待需要执行的SQL语句)
Killed:被标注为删除
v$process视图
v$process视图包含当前系统Oracle运行的所有进程信息。常被用于将Oracle或服务进程的操作系统进程ID与数据库session之间建立联系。
常用列:
ADDR:进程对象地址
PID:oracle进程ID
SPID:操作系统进程ID
本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2011-09/43885.htm