您好,登錄后才能下訂單哦!
小編給大家分享一下ARCHIVELOG如何統計歸檔日志更準確,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
做一個歸檔日志歷史記錄的一些信息,發現兩個視圖 v$archived_log 另一個是 V$log_history
下面我們先看下官方說明:
v$archived_log 也就是這個視圖顯示的是控制文件中的信息,如果歸檔日志已經刪除,name列將顯示為空
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 這個說的比較簡單,就是控制文件中的歷史信息
V$LOG_HISTORY displays log history information from the control file
那么它們有什么區別呢,或者說誰統計的個數 更準確?(已做過統計測試,每天生成的歸檔日志數量不一致)
如下所示:
v$log_history
SQL> SELECT trunc(first_time) "Date",
2 to_char(first_time, 'Dy') "Day",
3 count(1) "Totals"
4 FROM V$log_history where to_date(first_time)>to_date(sysdate-15)
5 group by trunc(first_time), to_char(first_time, 'Dy')
6 Order by 1;
Date Day Totals
--------- ------ ----------
05-JUL-17 Wed 1
07-JUL-17 Fri 5
13-JUL-17 Thu 1
18-JUL-17 Tue 2
v$archived_log
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);
date Count MB
--------- ---------- ----------
18-JUL-17 3 28.9492188
07-JUL-17 7 229.628418
13-JUL-17 1 27.3828125
18-JUL-17 天,我手動切了三次歸檔,如下
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> /
System altered.
而v$log_history 顯示的卻是2個
下面我們通過rman來看 顯示結果 18日這天是2個, 也就是統計信息跟v$log_history 一樣
RMAN> list archivelog all;
using target database control file instead of recovery catalog
List of Archived Log Copies for database with db_unique_name MYDB
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - ---------
1 1 306 A 30-JUN-17
Name: /backup/mydbarchivelog/1_306_947429846.dbf
2 1 307 A 04-JUL-17
Name: /backup/mydbarchivelog/1_307_947429846.dbf
3 1 308 A 05-JUL-17
Name: /backup/mydbarchivelog/1_308_947429846.dbf
4 1 309 A 07-JUL-17
Name: /backup/mydbarchivelog/1_309_947429846.dbf
5 1 310 A 07-JUL-17
Name: /backup/mydbarchivelog/1_310_947429846.dbf
6 1 311 A 07-JUL-17
Name: /backup/mydbarchivelog/1_311_947429846.dbf
7 1 312 A 07-JUL-17
Name: /backup/mydbarchivelog/1_312_947429846.dbf
8 1 313 A 07-JUL-17
Name: /backup/mydbarchivelog/1_313_947429846.dbf
9 1 314 A 13-JUL-17
Name: /backup/mydbarchivelog/1_314_947429846.dbf
10 1 315 A 18-JUL-17
Name: /backup/mydbarchivelog/1_315_947429846.dbf
11 1 316 A 18-JUL-17
Name: /backup/mydbarchivelog/1_316_947429846.dbf
好,我們在通過系統命令來看 ,卻是3個
SQL> !ls -l /backup/mydbarchivelog
total 341292
-rw-r----- 1 oracle oinstall 27716608 Jun 28 16:33 1_303_947429846.dbf
-rw-r----- 1 oracle oinstall 1552896 Jun 29 11:10 1_304_947429846.dbf
-rw-r----- 1 oracle oinstall 20325888 Jun 30 09:21 1_305_947429846.dbf
-rw-r----- 1 oracle oinstall 19091968 Jul 7 13:58 1_306_947429846.dbf
-rw-r----- 1 oracle oinstall 22322176 Jul 7 13:58 1_307_947429846.dbf
-rw-r----- 1 oracle oinstall 21595136 Jul 7 13:58 1_308_947429846.dbf
-rw-r----- 1 oracle oinstall 48646656 Jul 7 15:15 1_309_947429846.dbf
-rw-r----- 1 oracle oinstall 47450112 Jul 7 15:49 1_310_947429846.dbf
-rw-r----- 1 oracle oinstall 41217024 Jul 7 16:00 1_311_947429846.dbf
-rw-r----- 1 oracle oinstall 40463360 Jul 7 22:00 1_312_947429846.dbf
-rw-r----- 1 oracle oinstall 28713472 Jul 13 11:10 1_313_947429846.dbf
-rw-r----- 1 oracle oinstall 30352896 Jul 18 12:57 1_314_947429846.dbf
-rw-r----- 1 oracle oinstall 1024 Jul 18 12:57 1_315_947429846.dbf
-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’ 將不再顯示。
當然,我們可以直接統計未刪除的歸檔日志大小
SQL> --not delete archivelog sum size
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.
以上是“ARCHIVELOG如何統計歸檔日志更準確”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。