Oracle查询锁表用户 释放被锁的表SQL 及超时120S的SQL 误删表还原

--查看被锁的表
SELECT object_name, machine, s.sid, s.serial# ,o.OWNER
FROM gv$locked_object l, dba_objects o, gv$session s 
WHERE l.object_id = o.object_id 
AND l.session_id = s.sid
and o.OWNER='JC02_LOAN';




--释放SESSION SQL: 
--alter system kill session 'sid, serial#'; 

ALTER system kill session '44, 19193'; 


---查询SQL超时120s的
select 'ALTER system kill session '''||s.sid||','||s.serial# ||''';',s.machine,s.username,s.program,s.sid,s.serial#,a.sql_id,s.status,'OS id: '||p.spid "OS ID",s.event,'call_et: '||s.last_call_et,'wait time: '|| wait_time
 "Wait_time",a.sql_text,s.sql_hash_value,s.state
from v$session s,v$process p,v$sqlarea a
 where s.paddr = p.addr
and s.sql_hash_value = a.hash_value(+)
and s.type = 'USER'
and s.status = 'ACTIVE'

and s.last_call_et > 120 ;

--修改用户秘密

alter user system identified by values 'tiger';

--还原误删的表

flashback table SYS_ACL to before drop;

select 'flashback table ' || r.original_name || ' to before drop rename to '|| r.original_name ||'; ' ,r.*
  from recyclebin r
 where r.type = 'TABLE'
   and to_char(to_date(r.droptime, 'yyyy-MM-dd hh24:mi:ss'), 'yyyy-MM-dd') =
       '2015-04-20'


create tablespace jypt datafile 'D:\oracle\product\10.2.0\oradata\jieyue\jypt.dbf ' size 100m autoextend on next 10m;
create user jypt identified by password default tablespace jypt;
grant dba to jypt;


#create tablespace loan datafile '\u01\app\oracle\oradata\sales\jieyue\loan.dbf ' size 100m autoextend on next 10m;
#create user loan identified by loan default tablespace loan;
#grant dba to loan;

你可能感兴趣的:(oralce)