alert log file은 오라클 데이터베이스 운영을 위해서는 꼭 확인해야 하는 가장 기본적인 log file이다.
이 기본적인 alert log file은 이름처럼 꼭 alert을 안줘도 될만한 정보까지도 alerting(?)질을 하곤 하는데,
online redo log size가 너무 작거나 변경량이 많은 경우 그 내용이 너무 많아 관리자들은 확인에 소홀해 지기도 한다.
하지만 꼭 봐야한다!!
아래 기술한 내용은 alert log file을 '날짜|로그' format으로 변경해주는 awk 명령이다.
가끔 장애가 발생하면 연관 서버, 업무들을 시간 순으로 나열할 일이 생기는데 요런 작업을 좀 편하게 해보려고 만들어 봤다.
추가로 alert log file을 external table을 이용해 DB에 loading 하는 것까지 추가한다.
1. awk 명령을 이용해 "시간|로그내용"으로 변경하기
+ alert log file
Fri Jul 29 13:40:01 2011
Thread 1 advanced to log sequence 292352
Current log# 2 seq# 292352 mem# 0: /FS/redo02a.log
Current log# 2 seq# 292352 mem# 1: /FS/redo02b.log
Thread 1 advanced to log sequence 292353
Current log# 3 seq# 292353 mem# 0: /FS/redo03a.log
Current log# 3 seq# 292353 mem# 1: /FS/redo03b.log
Fri Jul 29 13:42:19 2011
Thread 1 advanced to log sequence 292354
Current log# 4 seq# 292354 mem# 0: /FSredo04a.log
Current log# 4 seq# 292354 mem# 1: /FSredo04b.log
Fri Jul 29 13:50:01 2011
Thread 1 advanced to log sequence 292355
Current log# 5 seq# 292355 mem# 0: /FSredo05a.log
Current log# 5 seq# 292355 mem# 1: /FSredo05b.log
Thread 1 advanced to log sequence 292356
Current log# 1 seq# 292356 mem# 0: /FSredo01a.log
Current log# 1 seq# 292356 mem# 1: /FSredo01b.log
Fri Jul 29 13:53:57 2011
Thread 1 advanced to log sequence 292357
Current log# 2 seq# 292357 mem# 0: /FS/redo02a.log
Current log# 2 seq# 292357 mem# 1: /FS/redo02b.log
+ awk 명령을 이용해 날짜와 로그 내용을 병합한다.
$ tail -100 /bdump/alert_SID.log | awk '{if (($5=="2011") && $6 =="") {vdate = $0} else {print vdate,"|", $0} }' | grep 2011 > /fs/app/oracle/product/rdbms/log/alert_test.log
$ cat /fs/app/oracle/product/rdbms/log/alert_test.log
Fri Jul 29 13:42:19 2011 | Thread 1 advanced to log sequence 292354
Fri Jul 29 13:42:19 2011 | Current log# 4 seq# 292354 mem# 0: /FS/redo04a.log
Fri Jul 29 13:42:19 2011 | Current log# 4 seq# 292354 mem# 1: /FS/redo04b.log
Fri Jul 29 13:50:01 2011 | Thread 1 advanced to log sequence 292355
Fri Jul 29 13:50:01 2011 | Current log# 5 seq# 292355 mem# 0: /FS/redo05a.log
Fri Jul 29 13:50:01 2011 | Current log# 5 seq# 292355 mem# 1: /FS/redo05b.log
Fri Jul 29 13:50:01 2011 | Thread 1 advanced to log sequence 292356
Fri Jul 29 13:50:01 2011 | Current log# 1 seq# 292356 mem# 0: /FS/redo01a.log
Fri Jul 29 13:50:01 2011 | Current log# 1 seq# 292356 mem# 1: /FS/redo01b.log
Fri Jul 29 13:53:57 2011 | Thread 1 advanced to log sequence 292357
Fri Jul 29 13:53:57 2011 | Current log# 2 seq# 292357 mem# 0: /FS/redo02a.log
Fri Jul 29 13:53:57 2011 | Current log# 2 seq# 292357 mem# 1: /FS/redo02b.log
Fri Jul 29 14:00:02 2011 | Thread 1 advanced to log sequence 292358
Fri Jul 29 14:00:02 2011 | Current log# 3 seq# 292358 mem# 0: /FS/redo03a.log
Fri Jul 29 14:00:02 2011 | Current log# 3 seq# 292358 mem# 1: /FS/redo03b.log
Fri Jul 29 14:00:02 2011 | Thread 1 advanced to log sequence 292359
Fri Jul 29 14:00:02 2011 | Current log# 4 seq# 292359 mem# 0: /FS/redo04a.log
Fri Jul 29 14:00:02 2011 | Current log# 4 seq# 292359 mem# 1: /FS/redo04b.log
2. 변경된 alert log file을 DB로 loading 하기
+ DB내 directory 정보 확인
SQL> select * from dba_directories;
OWNER DIRECTORY_NAME DIRECTORY_PATH
------------------------------ ------------------------------ -----------------------------------
SYS DATA_PUMP_DIR /fs/app/oracle/product/rdbms/log/
+ external table 만들기
SQL> drop table t_alert_log;
SQL> create table t_alert_log (ldate varchar2(25), text_line varchar2(150))
organization external
(
type oracle_loader
default directory DATA_PUMP_DIR
ACCESS PARAMETERS
(
records delimited by newline
fields terminated by '|'
)
location ('alert_test.log'));
+ 입맛대로 query 하기
SQL> select rownum,a.* from t_alert_log a;
ROWNUM LDATE TEXT_LINE
---------- ------------------------- ------------------------------------------------------------------------
386 Fri Jul 29 13:30:17 2011 Current log# 1 seq# 292351 mem# 0: /FS/redo01a.log
387 Fri Jul 29 13:30:17 2011 Current log# 1 seq# 292351 mem# 1: /FS/redo01b.log
388 Fri Jul 29 13:40:01 2011 Thread 1 advanced to log sequence 292352
389 Fri Jul 29 13:40:01 2011 Current log# 2 seq# 292352 mem# 0: /FS/redo02a.log
390 Fri Jul 29 13:40:01 2011 Current log# 2 seq# 292352 mem# 1: /FS/redo02b.log
391 Fri Jul 29 13:40:01 2011 Thread 1 advanced to log sequence 292353
392 Fri Jul 29 13:40:01 2011 Current log# 3 seq# 292353 mem# 0: /FS/redo03a.log
393 Fri Jul 29 13:40:01 2011 Current log# 3 seq# 292353 mem# 1: /FS/redo03b.log
394 Fri Jul 29 13:42:19 2011 Thread 1 advanced to log sequence 292354
395 Fri Jul 29 13:42:19 2011 Current log# 4 seq# 292354 mem# 0: /FS/redo04a.log
396 Fri Jul 29 13:42:19 2011 Current log# 4 seq# 292354 mem# 1: /FS/redo04b.log
external table의 경우 text file을 loading 한 순서로 보여주므로 log file의 순서대로 보여주게 되나
이 데이터를 다른 table에 옮길경우엔 반드시 rownum을 같이 넘겨여 한다.
안그러면 순서가 뒤죽박죽~ 될 수 있음.