查看oracle数据库中表是否被锁

查出所有被锁住的表

select b.owner TABLEOWNER,b.object_name TABLENAME,c.OSUSER LOCKBY,c.USERNAME LOGINID, c.sid SID, c.SERIAL# SERIAL from v$locked_object a,dba_objects b,v$session c where b.object_id = a.object_id AND a.SESSION_ID =c.sid;
 
通过SID, SERIAL解锁 
alter system kill session 'SID, SERIAL';
 
查看锁表进程SQL语句
 
set pagesize 999
set line180
col ORACLE_USERNAME for a18
col OS_USER_NAME for a18
col OBJECT_NAME  for a24
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;
 
杀掉锁表进程:
alter system kill session '50,63547' immediate; 
 
批量生成语句
SELECT 'alter system kill session '''||sess.sid || ',' || sess.serial#||''' immediate;'  
    from v$locked_object lo,
    dba_objects ao,
    v$session sess
where ao.object_id = lo.object_id and lo.session_id = sess.sid;
posted @ 2021-02-06 08:28  饿昏的猪大大  阅读(784)  评论(0编辑  收藏  举报