Oracle Database를 Archive log mode로 사용하다보면 점차 Archive log가 쌓이게 되는데요.
DB 사용량에 따라서 아주 빠른 속도로 쌓인다면 공간관리를 위해 더이상 필요없는 Archive log는 삭제를 시켜줘야 합니다.
공간관리가 안되면 alert log에 No space left on device 및 ORA-16038 등의 에러가 발생합니다.
Oracle에서 Archive log를 자동으로 삭제해주는 기능은 없기 때문에 관리자가 수동으로 제거해주는 과정이 필요합니다.
하지만 대부분의 경우 단순작업이기 때문에 수동으로 하지 않고, crontab을 이용해 자동화하여 사용중입니다.
나의 환경에 맞게 Archive log 사용공간을 자동관리 할 수 있도록, 같이 스크립트를 만들어 보도록 하겠습니다!
먼저, 나의 환경에서 사용하고 있는 Archive log File의 위치를 확인합니다.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /log/arch
Oldest online log sequence 61
Next log sequence to archive 65
Current log sequence 65
해당 경로의 사용량 확인합니다.
[test:/home/oracle] df -h /log
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 200G 150G 50G 75% /log
[test:/log] du -sh arch
150G arch
archive log 경로에 존재하는 파일 목록
[test:/log/arch] ls |wc -l
591
[test:/log/arch] ls -lrt
-rw-r----- 1 oracle oinstall 136175616 Jan 3 2024 1_3057_1128088630.dbf
-rw-r----- 1 oracle oinstall 154320896 Jan 3 2024 1_3058_1128088630.dbf
-rw-r----- 1 oracle oinstall 136259584 Jan 4 2024 1_3059_1128088630.dbf
...
archive log 경로에 존재하는 archive log File 중에 30일이 지난 File을 정리해보겠습니다.
(백업 주기에 맞게 적절히 설정합니다)
crontab에 등록하기 전에 먼저 ls 명령어로 test겸 확인해보도록 하겠습니다.
사용 명령어: find /경로 -name "파일명" -ctime +경과일수 -exec ls -lrt {} \;
[test:/log/arch] find /log/arch -name "*.dbf" -ctime +30 -exec ls -lrt {} \;
-rw-r----- 1 oracle oinstall 138059776 Jul 25 19:00 ./1_1_1175241114.dbf
-rw-r----- 1 oracle oinstall 139410944 Jul 26 14:00 ./1_2_1175241114.dbf
-rw-r----- 1 oracle oinstall 136185856 Jul 27 06:47 ./1_3_1175241114.dbf
-rw-r----- 1 oracle oinstall 146928128 Jul 28 00:17 ./1_4_1175241114.dbf
...
현재 등록되어 있는 crontab 확인합니다.
[test:/home/oracle] crontab -l
#0,30 * * * * /home/oracle/xxxxxxx.sh
0 0 */3 * * /home/oracle/xxxxxx/script/daily_backup.sh > /oracle/test/script/cron_daily_backup.log 2>&1
crontab 등록을 해줍니다.
먼저 crontab에서 사용 할 archve log 삭제 스크립트 작성합니다.
[o19300:/oracle/arch1] cat /home/oracle/rm_arch.sh
find /oracle/arch1 -name "*.dbf" -ctime +30 -exec rm {} \;
rman target / <<EOF
crosscheck archivelog all;
list expired archivelog all;
delete expired archivelog all;
yes
list archivelog all;
EOF
RMAN을 이용하여 Backup을 하는 경우에는 crosscheck 및 delete expired 까지 완료해주어야 합니다.
삭제 명령어: find /경로 -name "파일명" -ctime +경과일수 -exec rm {} \;
--crontab 등록 포맷
* * * * * command_to_run
- - - - -
| | | | |
| | | | +----- 요일 (0 - 7) (0과 7은 일요일)
| | | +------- 월 (1 - 12)
| | +--------- 일 (1 - 31)
| +----------- 시간 (0 - 23)
+------------- 분 (0 - 59)
--매주 토요일 00시 00분에 수행되도록 추가하는 예시
[test:/home/oracle] crontab -e
#0,30 * * * * /home/oracle/xxxxxxx.sh
0 0 */3 * * /home/oracle/xxxxxx/script/daily_backup.sh > /oracle/test/script/cron_daily_backup.log 2>&1
0 0 * * 6 /home/oracle/rm_arch.sh > /log/arch/rm_arch_$(date +\%Y\%m\%d).log 2>&1
crontab에 등록이 잘 되었는지 확인합니다.
[test:/home/oracle] crontab -l
#0,30 * * * * /home/oracle/xxxxxxx.sh
0 0 */3 * * /home/oracle/xxxxxx/script/daily_backup.sh > /oracle/test/script/cron_daily_backup.log 2>&1
0 0 * * 6 /home/oracle/rm_arch.sh > /log/arch/rm_arch_$(date +\%Y\%m\%d).log 2>&1
이렇게 진행하시면 매주 토요일 자정에 스크립트가 수행되면서
토요일 자정기준 30일이 지난 archive log File이 모두 삭제됩니다.
crontab이 삭제 작업을 진행한 이후의 경로 사용량입니다.
[test:/home/oracle] df -h /log
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 200G 50G 150G 25% /log
[test:/log] du -sh arch
50G arch
[test:/log/arch] ls |wc -l
591
[test:/log/arch] ls -lrt
-rw-r----- 1 oracle oinstall 139260928 Aug 2 2024 1_3594_1128088630.dbf
-rw-r----- 1 oracle oinstall 136173568 Aug 3 2024 1_3595_1128088630.dbf
-rw-r----- 1 oracle oinstall 137176064 Aug 3 2024 1_3596_1128088630.dbf
...
이상입니다.
'OracleDB > Test' 카테고리의 다른 글
ASM Diskgroup, Disk 확인하는 SQL (0) | 2025.04.17 |
---|---|
ORA-19909: datafile XX belongs to an orphan incarnation 발생 (0) | 2024.07.05 |
Pfile/Spfile 차이 (0) | 2023.01.19 |
사용자별 DB 접속 Timeout 설정 (0) | 2023.01.10 |
INBOUND_CONNECT_TIMEOUT 설정 (0) | 2023.01.10 |