【ARCHIVELOG】怎樣統計歸檔日誌更準確

xysoul_雲龍發表於2017-07-18


下午做一個歸檔日誌歷史記錄的一些資訊,發現兩個檢視 v$archived_log  另一個是 V$log_history 

下面我們先看下官方說明:

v$archived_log   也就是這個檢視顯示的是控制檔案中的資訊,如果歸檔日誌已經刪除,name列將顯示為空

點選(此處)摺疊或開啟

  1. V$ARCHIVED_LOG displays archived log information from the control file, including archive log names. An archive log record is inserted after the online redo log is successfully archived or cleared (name column is NULL if the log was cleared). If the log is archived twice, there will be two archived log records with the same THREAD#, SEQUENCE#, and FIRST_CHANGE#, but with a different name. An archive log record is also inserted when an archive log is restored from a backup set or a copy and whenever a copy of a log is made with the RMAN COPY command.

v$log_history   這個說的比較簡單,就是控制檔案中的歷史資訊 

點選(此處)摺疊或開啟

  1. V$LOG_HISTORY displays log history information from the control file


那麼它們有什麼區別呢,或者說誰統計的個數 更準確?(已做過統計測試,每天生成的歸檔日誌數量不一致)

如下所示:

v$log_history

點選(此處)摺疊或開啟

  1. SQL> SELECT trunc(first_time) "Date",
  2.   2 to_char(first_time, 'Dy') "Day",
  3.   3 count(1) "Totals"
  4.   4 FROM V$log_history where to_date(first_time)>to_date(sysdate-15)
  5.   5 group by trunc(first_time), to_char(first_time, 'Dy')
  6.   6 Order by 1;

  7. Date Day Totals
  8. --------- ------ ----------
  9. 05-JUL-17 Wed 1
  10. 07-JUL-17 Fri 5
  11. 13-JUL-17 Thu 1
  12. 18-JUL-17 Tue 2

v$archived_log

點選(此處)摺疊或開啟

  1. SQL> select trunc(completion_time) as "date",count(*) as "Count",(sum(blocks*block_size)/1024/1024) as "MB" from v$archived_log group by trunc(completion_time);

  2. date Count MB
  3. --------- ---------- ----------
  4. 18-JUL-17 3 28.9492188
  5. 07-JUL-17 7 229.628418
  6. 13-JUL-17 1 27.3828125

18-JUL-17 天,我手動切了三次歸檔,如下


點選(此處)摺疊或開啟

  1. SQL> alter system switch logfile;

  2. System altered.

  3. SQL> /

  4. System altered.

  5. SQL> /

  6. System altered.

而v$log_history 顯示的卻是2個

下面我們透過rman來看   顯示結果 18日這天是2個, 也就是統計資訊跟v$log_history 一樣

點選(此處)摺疊或開啟

  1. RMAN> list archivelog all;

  2. using target database control file instead of recovery catalog
  3. List of Archived Log Copies for database with db_unique_name MYDB
  4. =====================================================================

  5. Key Thrd Seq S Low Time
  6. ------- ---- ------- - ---------
  7. 1 1 306 A 30-JUN-17
  8.         Name: /backup/mydbarchivelog/1_306_947429846.dbf

  9. 2 1 307 A 04-JUL-17
  10.         Name: /backup/mydbarchivelog/1_307_947429846.dbf

  11. 3 1 308 A 05-JUL-17
  12.         Name: /backup/mydbarchivelog/1_308_947429846.dbf

  13. 4 1 309 A 07-JUL-17
  14.         Name: /backup/mydbarchivelog/1_309_947429846.dbf

  15. 5 1 310 A 07-JUL-17
  16.         Name: /backup/mydbarchivelog/1_310_947429846.dbf

  17. 6 1 311 A 07-JUL-17
  18.         Name: /backup/mydbarchivelog/1_311_947429846.dbf

  19. 7 1 312 A 07-JUL-17
  20.         Name: /backup/mydbarchivelog/1_312_947429846.dbf

  21. 8 1 313 A 07-JUL-17
  22.         Name: /backup/mydbarchivelog/1_313_947429846.dbf

  23. 9 1 314 A 13-JUL-17
  24.         Name: /backup/mydbarchivelog/1_314_947429846.dbf

  25. 10 1 315 A 18-JUL-17
  26.         Name: /backup/mydbarchivelog/1_315_947429846.dbf

  27. 11 1 316 A 18-JUL-17
  28.         Name: /backup/mydbarchivelog/1_316_947429846.dbf


好,我們在透過系統命令來看 ,卻是3個

點選(此處)摺疊或開啟

  1. SQL> !ls -l /backup/mydbarchivelog
  2. total 341292
  3. -rw-r----- 1 oracle oinstall 27716608 Jun 28 16:33 1_303_947429846.dbf
  4. -rw-r----- 1 oracle oinstall 1552896 Jun 29 11:10 1_304_947429846.dbf
  5. -rw-r----- 1 oracle oinstall 20325888 Jun 30 09:21 1_305_947429846.dbf
  6. -rw-r----- 1 oracle oinstall 19091968 Jul 7 13:58 1_306_947429846.dbf
  7. -rw-r----- 1 oracle oinstall 22322176 Jul 7 13:58 1_307_947429846.dbf
  8. -rw-r----- 1 oracle oinstall 21595136 Jul 7 13:58 1_308_947429846.dbf
  9. -rw-r----- 1 oracle oinstall 48646656 Jul 7 15:15 1_309_947429846.dbf
  10. -rw-r----- 1 oracle oinstall 47450112 Jul 7 15:49 1_310_947429846.dbf
  11. -rw-r----- 1 oracle oinstall 41217024 Jul 7 16:00 1_311_947429846.dbf
  12. -rw-r----- 1 oracle oinstall 40463360 Jul 7 22:00 1_312_947429846.dbf
  13. -rw-r----- 1 oracle oinstall 28713472 Jul 13 11:10 1_313_947429846.dbf
  14. -rw-r----- 1 oracle oinstall 30352896 Jul 18 12:57 1_314_947429846.dbf
  15. -rw-r----- 1 oracle oinstall 1024 Jul 18 12:57 1_315_947429846.dbf
  16. -rw-r----- 1 oracle oinstall 3072 Jul 18 12:57 1_316_947429846.dbf


什麼情況呢,透過跟rman對比,我們可以看出,其實一個統計的是開始時間,另一個統計的是結束(完成)時間,
開始時間 也就是rman執行命令(list archivelog all)查詢結果一致,另一個結束時間,也就跟作業系統中執行命令(ls -lrt)結果一致,當然他們統計的資訊是在歸檔檔案未刪除前是一致的,因為刪除後,'list archivelog all' 和'ls -lrt’  將不再顯示。

當然,我們可以直接統計未刪除的歸檔日誌大小

點選(此處)摺疊或開啟

  1. SQL> --not delete archivelog sum size
  2. SQL> select ((sum(blocks * block_size)) /1024 /1024) as "MB" from v$archived_log where STANDBY_DEST ='NO' and deleted='NO'

如果想要更準確的結果(如果就是為了統計未刪除的資訊)我們可以選擇 deleted='NO'  或者 NAME IS NOT NULL.


OK, 如果有其他好玩的 ,我們會繼續跟蹤 , 手工,下班






來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29487349/viewspace-2142259/,如需轉載,請註明出處,否則將追究法律責任。

相關文章