Overview of the Online Redo Log,overviewredo

來源:互聯網
上載者:User

Overview of the Online Redo Log,overviewredo

對於 oracle 恢複來說最重要的資料結構莫過於online redo log(線上重做日誌), 線上重做日誌包含至少兩個預先分配好的,用來儲存資料庫變化的檔案。線上重做日誌記錄著資料檔案中的變化。



Online Redo Log有什麼作用


Oracle 資料庫通過線上重做記錄檔來確保資料不丟失。特別是當執行個體失敗後, oracle資料庫可以通過線上重做記錄檔恢複已經提交但尚未寫到資料檔案中的資料。

Oracle 資料庫把每個事務先同步寫到 redo log buffer,然後再寫到線上重做記錄檔中。日誌的內容包括未提交的事務,undo資料,模式對象管理聲明。

Oracle 資料庫使用線上重做日誌僅僅用於恢複。資料庫管理員也可以使用 LogMiner這個工具來查詢線上重做日誌。線上重做記錄檔是一個有用的反映資料庫曆史的資訊源。



Oracle資料庫怎樣寫 Online Redo Log


資料庫執行個體的線上重做日誌通常也被稱為 redo線程。在單一實例的環境中,僅僅只有一個執行個體訪問資料庫,因此只有一個 redo線程正在運行。而在 Oracle RAC環境中,通常有兩個或者兩個以上的執行個體並發的訪問資料庫,每個資料庫執行個體擁有一個redo線程。每個執行個體擁有單獨的redo線程是為了避免對唯一的線上重做記錄檔的競爭。

線上重做日誌一般包含兩個或者兩個以上的記錄檔。Oracle資料庫要求至少包含兩個記錄檔來保證其中一個對寫可用,而另外一個用來歸檔(如果資料庫運行在歸檔模式下)。



Online Redo Log切換


Oracle Database uses only one online redo log file at a time to store records written from the redo log buffer. The online redo log file to which the log writer (LGWR) process is actively writing is called the current online redo log file.


Oracle 資料庫同一時間只能使用一個線上重做記錄檔來儲存 redo log buffer 中的資料。LGWR進程正在寫的線上重做記錄檔稱為當前的線上重做記錄檔。


log switch occurs when the database stops writing to one online redo log file and begins writing to another. Normally, a switch occurs when the current online redo log file is full and writing must continue.However, you can configure log switches to occur at regular intervals,regardless of whether the current online redo log file is filled, and force logs witches manually.


日誌切換髮生在資料庫停止往一個線上重做記錄檔並且開始往另一個記錄檔寫的時候。一般來說,噹噹前的線上重做記錄檔已經滿了並且還必須繼續寫的是偶,日誌切換就會發生。然後,你可以設定日誌切換定期發生,不管當前的線上重做記錄檔是否已經充滿,強制手動執行日誌切換。


Log writer writes to online redo log files circularly. When log writer fills the last available online redo log file, the process writes to the first log file, restarting the cycle. Figure 11-6 illustrates the circular writing of the redo log.


LGWR 迴圈的寫線上重做記錄檔。當 LGWR 寫滿了最後一個線上重做記錄檔,這個進程會重新往第一個記錄檔中寫新的資料。


Figure 11-6 Reuse of Online Redo Log Files




The numbers in Figure 11-6 shows the sequence in which LGWR writes to each online redo log file. The database assigns each file a new log sequence number when a log switches and log writers begins writing to it. When the database reuses an online redo log file, this file receives the next available log sequence number.

Filled online redo log files are available for reuse depending on the archiving mode:

  • If archiving is disabled, which means that the database is in NOARCHIVELOG mode, then a filled online redo log file is available after the changes recorded in it have been checkpointed (written) to disk by database writer (DBW).
  • If archiving is enabled, which means that the database is in ARCHIVELOG mode, then a filled online redo log file is available to log writer after the changes have been written to the data files and the file has been archived.

已經填充滿的線上重做記錄檔是否可以重用取決於是否是在歸檔模式下:

如果不是在歸檔模式下,當線上重做記錄檔中的變化的記錄已經被 DBW 進程寫到了磁碟上之後,已經填充滿的線上重做記錄檔可以重用;

如果是在歸檔模式下,當線上重做記錄檔中變化的記錄已經寫到資料檔案中並且檔案已經歸檔後,已經填充滿的線上重做記錄檔可以重用;


In some circumstances, log writer may be prevented from reusing an existing online redo log file. For example, an online redo log file may be active (required for instance recovery) rather than inactive (not required for instance recovery). Also, an online redo log file may be in the process of being cleared.



Online Redo Log Files多個備份


Oracle Database can automatically maintain two or more identical copies of the online redo log in separate locations. An online redo log group consists of an online redo log file and its redundant copies. Each identical copy is a member of the online redo log group. Each group is defined by a number, such as group 1, group 2, and so on.


Oracle 資料庫能夠自動管理兩個或者多個不同位置的線上重做記錄檔的相同備份組。一個線上重做記錄檔組包含一個線上重做記錄檔和它的冗餘備份。每個完全相同的備份是線上重做記錄檔組中的一個成員。每個組用數字來定義,例如 group 1, group 2 等等。


Maintaining multiple members of an online redo log group protects against the loss of the redo log. Ideally, the locations of the members should be on separate disks so that the failure of one disk does not cause the loss of the entire online redo log.


儲存線上重做記錄檔組的多個成員來保證重做日誌不丟失。理論上說,記錄檔組的成員的存放位置應該放在磁碟上的不同位置,這樣即使一個磁碟損壞也不會導致整個線上重做記錄檔丟失。


In Figure 11-7, A_LOG1 and B_LOG1 are identical members of group 1, while A_LOG2 and B_LOG2 are identical members of group 2. Each member in a group must be the same size. LGWR writes concurrently to group 1(members A_LOG1 and B_LOG1), then writes concurrently to group2 (members A_LOG2 and B_LOG2), then writes to group 1, and so on. LGWR never writes concurrently to members of different groups.


在圖 11-7 中,A_LOG1 和 B_LOG1 是 group 1 中的相同的成員,而 A_LOG2 和 B_LOG2 是 group 2中的相同的成員。每個組中的成員必須大小一致。後台進程 LGWR 並發的寫資料到 group 1,然後並發的寫資料到 group 2,然後再並發的寫資料到 group 1. LGWR 從不會並發寫資料到不同的組。


Figure 11-7 Multiple Copies of Online Redo Log Files




注意: 

Oracle recommends that you multiplex the online redo log. The loss of log files can be catastrophic if recovery is required. When you multiplex the online redo log, the database must increase the amount of I/O it performs. Depending on your system, this additional I/O may impact overall database performance.

Oracle 推薦保留多份線上重做記錄檔。記錄檔的丟失對於恢複來說將是致命的。但是當你保留多份線上重做日誌時,資料庫必須增加執行 I/O 的數量。這種額外的 I/O 是否會影響資料庫的整體效能取決於你的系統。

 

Archived Redo Log Files(歸檔重做記錄檔)


歸檔記錄檔是線上重做記錄檔的一個備份,也不認為是資料庫的一部分,但是歸檔記錄檔是資料庫建立的線上重做記錄檔的離線備份並且可以寫到指定的位置。

歸檔記錄檔是和恢複策略中非常重要的部分,你可以使用歸檔記錄檔用來:

  • Recover a database backup (恢複資料庫)
  • Update a standby database (更新備用資料庫)
  • Obtain information about the history of a database using the LogMiner utility (通過logminer擷取資料庫的曆史資訊)

歸檔是產生歸檔記錄檔的一個操作,歸檔這個操作只有在資料庫運行在歸檔記錄模式才有效,可以自動也可以手動


An archived redo log file includes the redo entries and the log sequence number of the identical member of the online redo log group. In Figure 11-7, files A_LOG1 and B_LOG1 are identical members of Group 1. If the database is in ARCHIVELOG mode, and if automatic archiving is enabled, then the archiver process (ARCn) will archive one of these files. If A_LOG1 is corrupted, then the process can archive B_LOG1. The archived redo log contains a copy of every group created since you enabled archiving.


一個歸檔記錄檔包含redo entries(重做條目)和線上重做記錄檔組相同的記錄序號。在圖 11-7 中,檔案 A_LOG1 和 B_LOG1 是 Group 1 相同的成員。如果資料庫運行在歸檔記錄模式下並且開啟了自動歸檔,那麼歸檔進程(ARCn)將他們中一個進行歸檔。如果 A_LOG1 損壞了,歸檔進程可以對 B_LOG1 進行歸檔。如果你開啟了歸檔,已經歸檔的重做記錄檔將包含每個線上重做記錄檔組的備份。



Online Redo Log結構


線上重做日誌中包含許多 redo records(重做記錄).一條重做記錄由一組改變向量組成,每個改變向量描述了對一個資料區塊的修改。例如,在employees表中修改salary就會產生一條redo記錄,用來描述這個表的資料區段發生的變化,undo段資料區塊以及undo段的事務表。

重做記錄包含改變的所有相關的基本中繼資料,具體如下:

  • 改變時的SCN和時間戳記
  • 產生這個變化的事務的ID
  • 事務提交的SCN和時間戳記(如果已經提交)
  • 產生變化的操作類型
  • 被修改的資料區段的名字和類型

 

原文來自文檔:http://docs.oracle.com/cd/E11882_01/server.112/e40540/physical.htm#CNCPT1113

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.