oracle-锁表处理

经常遇到锁表的处理,记录下,需要项目经理给出数据库ip地址,实例名称及数据库用户

##具体用户jw_user的锁表查询:
set pagesize 199 linesize 3000;
col OWNER for a14;
col ORACLE_USERNAME for a10;
col MACHINE for a30;
col OBJECT_NAME for a30;
col OS_USER_NAME for a20;
col  PROGRAM for a20;
SELECT B.ORACLE_USERNAME,A.OBJECT_NAME, B.OS_USER_NAME, B.LOCKED_MODE, C.MACHINE,C.PROGRAM,C.STATUS FROM ALL_OBJECTS A,V$LOCKED_OBJECT B,SYS.GV_$SESSION C
WHERE ( A.OBJECT_ID = B.OBJECT_ID ) AND (B.PROCESS = C.PROCESS ) AND B.ORACLE_USERNAME=upper('jw_user') ORDER BY 1,2;

锁表直接得出kill命令如下:
set head off;
set echo off;
set termout off;
set feedback off;
set newpage none;
spool /home/oracle/kill_all_session.sql
SELECT 'alter system kill session ' ||''''||C.SID||','||C.SERIAL#||''''||' immediate;' FROM ALL_OBJECTS A,V$LOCKED_OBJECT B,SYS.GV_$SESSION C WHERE ( A.OBJECT_ID = B.OBJECT_ID ) AND (B.PROCESS = C.PROCESS ) and A.OWNER =upper('jw_user') ORDER BY 1;
spool off;
! sed -ri '/SYS@/d' /home/oracle/kill_all_session.sql
@/home/oracle/kill_all_session.sql

你可能感兴趣的:(OracleDB,运维,oracle,sql)