## oracle은 lock이 걸리는 세션을 자동으로 kill하지 않기 때문에 스크립트 이용하여 kill
## 300초 이상 tm lock 잡고 있는 세션 자동으로 kill 하기
## 리눅스 crontab 설정
vi /oracle/tm_lock_autokill.sh
#!/bin/bash
############################################
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=orcl1;
export ORACLE_BASE=/oracle;
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/db_1;
export NLS_LANG=American_America.utf8
export NLS_DATE_FORMAT="DD-MON-YYYY HH24:MI:SS";
export TNS_ADMIN=$ORACLE_HOME/network/admin;
export PATH=$PATH:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch;
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib:/usr/lib
export TMP=/tmp
export TMPDIR=/tmp
############################################
DATE=`date +'%Y%m%d'`
TIME=`date +'%H%M%S'`
LOG_PATH=/oracle/log
USER_NAME='/as sysdba'
FILE_PATH=$LOG_PATH/$DATE'_'$TIME'_TM.log'
sqlplus -S "$USER_NAME" << Eof 2>&1 > $FILE_PATH
set echo off
set linesize 7000
set pages 0
set trimspool on
set head off
set feedback off
set colsep '|'
SELECT A.SID, A.SERIAL#,A.MACHINE,A.LAST_CALL_ET,C.OBJECT_NAME
FROM V\$SESSION A, V\$LOCK B, ALL_OBJECTS C
WHERE A.SID = B.SID
AND B.ID1 = C.OBJECT_ID
AND B.TYPE = 'TM'
--AND C.OBJECT_NAME IN ('테이블명1', '테이블명2')
and A.LAST_CALL_ET > 300;
Eof
FILE_SIZE=$(stat -c %s $FILE_PATH)
if [ $FILE_SIZE == 0 ]
then
rm $FILE_PATH
exit 1
fi
cat $FILE_PATH | while read line
do
sid=`echo $line | cut -d'|' -f1`
serial=`echo $line | cut -d'|' -f2`
sqlplus -S "$USER_NAME" << Eof
set echo off
set pages 0
set trimspool on
set head off
set feedback off
ALTER SYSTEM KILL SESSION '${sid}, ${serial}';
Eof
done
'DBMS > Oracle' 카테고리의 다른 글
Grant 및 role(권한 및 롤) 관리 (0) | 2022.07.19 |
---|---|
sys password 변경시 주의할 점 (0) | 2022.07.14 |
Characterset 관리(변경) (0) | 2022.07.04 |
database 기본정보, 설치된 옵션 (0) | 2022.07.04 |
JOB 관리 (0) | 2022.07.04 |