今天把DataStage导一个大表,一不小心把表给锁住了........
其实解锁并不复杂,用PL/SQL可以很方便解锁,可以用两种方式得到目前被锁住的表。第一种是,直接从,Tools->Session里面查看,里面有很多的Session和进程,下面有一个Lock的Tab,选中那个Tab,然后一条一条地去上面Session,如果Lock这一栏有数据,就说明被锁住了,在Objec_Name里面可以看到表名。
如果是自己的表,可以得到Sid和Serial#,接着执行以下语句就可以解锁:
alter system kill session 'sid,serial#';
第二种方法是用语句得到详细的被锁住的表的信息,语句如下:
SELECT 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.osuserFROM v$session s,v$lock l,dba_objects oWHERE l.sid = s.sidAND l.id1 = o.object_id(+)AND s.username is NOT Null
----以上为引用,下面是自己的方法
查看表是否锁住
select * from dba_lock a where a.lock_id1 in (select t.object_id from dba_objects t where t.object_name = 'B_F_GL_BASE_STDC_AMT_ACC_A')SELECT 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.STATUS, s.terminal, s.machine, s.program, s.osuser, s.LOGON_TIME, l.BLOCK 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 and l.BLOCK=1 --是否是死锁--查询谁锁定,谁等待SELECT 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;果发生了锁等待,我们可能更想知道是谁锁了表而引起谁的等待以上的语句可以查询到谁锁了表,而谁在等待。以上查询结果是一个树状结构,如果有子节点,则表示有等待发生。如果想知道锁用了哪个回滚段,还可以关联到V$rollname,其中xidusn就是回滚段的USN找出谁锁定的记录,kill掉就行了。 -----------------------Oracle杀死死锁进程
先查看哪些表被锁住了:1获得sidselect 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;##########2获得sid,serialselect 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_time3杀alter system kill session 'sid,serial';如果有ora-00031错误,则在后面加immediate;alter system kill session '29,5497' immediate;--杀数据库进程(数据库服务器的机子)SELECT a.username, c.spid AS os_process_id, c.pid AS oracle_process_id FROM v$session a, v$process c WHERE c.addr = a.paddr and a.sid ='1392' and a.serial# ='10858';