[ Oracle tablespaces check ]
#!/bin/ksh
#
# TABLESPACE 사용량 점검을 위한 스크립트
#
LOG_DIR="/APP/script/log"
LOG_FILE_NAME="chk_tablespace.log"
LOG_FILE="$LOG_DIR/$LOG_FILE_NAME"
# data backup
DATA_FILE="$LOG_DIR/tablespace_`date '+%Y%m%d'`.txt"
if [ -f "$DATA_FILE" ] ; then
mv "$DATA_FILE" "$LOG_DIR/tablespace_`date '+%Y%m%d%H%M'`.txt"
fi
echo [`date '+%Y-%m-%d %H:%M:%S'`] Started to check tablespace >> "$LOG_FILE"
echo [`date '+%Y-%m-%d %H:%M:%S'`] >> "$LOG_FILE"
su - oraium -c "sqlplus -S user1/xxxxxxxx@XE @/APP/script/chk_tablespace.sql" >> "$LOG_FILE"
RV="`echo $?`"
echo [`date '+%Y-%m-%d %H:%M:%S'`] Return Value = $RV >> "$LOG_FILE"
echo [`date '+%Y-%m-%d %H:%M:%S'`] Stopped to check tablespace >> "$LOG_FILE"
echo >> "$LOG_FILE"
# data removal for greater than 30
/bin/find /APP/script/log -mtime +30 -exec rm -f {} \; > /dev/null 2>&1
2. chk_tablespace.sql
-- header가 display되지 않고 데이터만 display
set heading off
-- pagesize의 default는 14이며 그대로 하면 14줄마다 1줄씩 공백이 생기는 현상 방지
set pagesize 1000
-- linesize도 record 길이만큼 지정하여 아래로 구분되지 않도록 방지
set linesize 300
-- 명령이 display되지 않도록 함
set echo off
-- 조회 결과가 화면에 나오지 않도록 함
set term off
column spoolname new_value spoolname
select '/APP/script/log/tablespace_' || to_char(sysdate, 'YYYYMMDD') || '.txt' spoolname from dual;
-- data가 들어가는 화일 이름을 지정
--spool /tmp/test.txt
spool &spoolname
---- 쿼리 시작 ---
set serveroutput on;
select substr(a.tablespace_name,1,30) || ',' || to_char(round(sum(a.total1)/1024/1024,1)) || ',' || to_char(round(sum(a.total1)/1024/1024,1)-round(sum(a.sum1)/1024/1024,1)) || ',' || to_char(round(sum(a.sum1)/1024/1024,1)) || ',' || to_char(round((round(sum(a.total1)/1024/1024,1)-round(sum(a.sum1)/1024/1024,1))/round(sum(a.total1)/1024/1024,1)*100,2))
from (select tablespace_name, 0 total1, sum(bytes) sum1, max(bytes) MAXB, count(bytes) cnt
from dba_free_space
group by tablespace_name
union
select tablespace_name, sum(bytes) total1,0,0,0
from dba_data_files
group by tablespace_name
) a
group by a.tablespace_name
order by tablespace_name;
spool off
exit;
No comments:
Post a Comment