用这个可以查: select s.sid,s.machine,o.object_name,l.oracle_username,l.locked_mode, 'ALTER SYSTEM KILL SESSION '''||s.sid||', '||s.serial#||''';' Command from v$locked_object l,v$session s,all_objects o where l.session_id=s.sid and l.object_id=o.object_id 可以查看哪台机器哪个用户锁了记录, 其中command是用来杀掉锁住记录的session
******************************************************************************************************************
SELECT A.OBJECT_ID, B.OBJECT_NAME, A.SESSION_ID, A.ORACLE_USERNAME, A.OS_USER_NAME, A.PROCESS, A.LOCKED_MODE FROM V$LOCKED_OBJECT A, DBA_OBJECTS B WHERE A.OBJECT_ID = B.OBJECT_ID;
SELECT T2.USERNAME, T2.SID, T2.SERIAL#, T2.LOGON_TIME FROM V$LOCKED_OBJECT T1, V$SESSION T2 WHERE T1.SESSION_ID = T2.SID ORDER BY T2.LOGON_TIME;
ALTER SYSTEM KILL SESSION 'sid, serial#';
********************************************************************************************************************
session 1: C:/>sqlplus hxg/hxg
SQL> select * from scott.t;
A B C ---------- -------------------- -------------------- 111 aa bb 222 hello world
SQL> update scott.t set b='good' where a=222;
已更新 1 行。
session 2: C:/>sqlplus scott/tiger
SQL> select * from scott.t;
A B C ---------- -------------------- -------------------- 111 aa bb 222 hello world
SQL> update t set b='asdfds' where a=222;
挂起。。。。
session 3: C:/>sqlplus "system/*** as sysdba"
SQL> select sid,serial#,username,status from v$session;
SID SERIAL# USERNAME STATUS ---- ---------- ------------------------------ -------- 146 25 SYS ACTIVE 147 11 SYS INACTIVE 148 2 HXG
INACTIVE 150 5 SCOTT ACTIVE 151 1 ACTIVE 154 1 ACTIVE 159 6 ACTIVE 160 1 ACTIVE 161 1 ACTIVE 162 1 ACTIVE 163 1 ACTIVE
SID SERIAL# USERNAME STATUS ---- ---------- ------------------------------ -------- 164 1 ACTIVE 165 1 ACTIVE 166 1 ACTIVE 167 1 ACTIVE 168 1 ACTIVE 169 1 ACTIVE 170 1 ACTIVE
已选择18行。
SQL> alter system kill session '148,2';
系统已更改。
SQL> select sid,serial#,username,status from v$session;
SID SERIAL# USERNAME STATUS ---- ---------- ------------------------------ -------- 146 25 SYS ACTIVE 147 11 SYS INACTIVE 148 2 HXG
KILLED 150 5 SCOTT INACTIVE 151 1 ACTIVE 154 1 ACTIVE 159 6 ACTIVE 160 1 ACTIVE 161 1 ACTIVE 162 1 ACTIVE 163 1 ACTIVE
SID SERIAL# USERNAME STATUS ---- ---------- ------------------------------ -------- 164 1 ACTIVE 165 1 ACTIVE 166 1 ACTIVE 167 1 ACTIVE 168 1 ACTIVE 169 1 ACTIVE 170 1 ACTIVE
已选择18行。
SQL>