谈谈Oracle日志文件的INVALID状态
在Oracle数据库中,三大文件(Data File、Control File和Online Redo Log)扮演着极其重要的地位和作用。其中,Redo Log和Oracle
在Oracle数据库中,三大文件(Data File、Control File和Online Redo Log)扮演着极其重要的地位和作用。其中,Redo Log和Oracle Redo Log机制更是Oracle正常、安全运行的保证。
Oracle Online Redo Log采用日志组(Logfile Group)和组成员(Group Member)的方式。每个Log File Group中的成员内容保持镜像相同,生成的每一条Redo Log Entry都需要写入到每个成员中。原则上,各个日志成员保存在不同的存储位置,这样一旦发生介质损坏,可以使用其他成员进行恢复。
Oracle数据库提供了对日志组和日志成员管理的语句操作支持。我们可以方便的添加、删除日志组,向日志组中添加、删除成员文件。但是,在一般的情况下,我们还是希望能够一次性将日志组所有成员确定添加。这样可以避免很多问题,其中之一就是日志文件的INVALID状态。
1、实验环境介绍
本文选择Oracle 11g进行实验测试。
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
当前系统中有三个日志组,每个组成员两个。当前第三组是Current状态Redo Log Group。
SQL> select group#, sequence#, members, status, first_change#, next_change# from v$log;
GROUP# SEQUENCE# MEMBERS STATUS FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------- ---------------- ------------- ------------
1 73 2 INACTIVE 1560017 1580625
2 74 2 INACTIVE 1580625 1600939
3 75 2 CURRENT 1600939 281474976710
SQL> select group#, status, type, member from v$logfile;
GROUP# STATUS TYPE MEMBER
---------- ------- ------- --------------------------------------------------------------------------------
3 ONLINE /u01/oradata/WILSON/onlinelog/o1_mf_3_7xt456o0_.log
3 ONLINE /u01/flash_recovery_area/WILSON/onlinelog/o1_mf_3_7xt45bvp_.log
2 ONLINE /u01/oradata/WILSON/onlinelog/o1_mf_2_7xt44w3k_.log
2 ONLINE /u01/flash_recovery_area/WILSON/onlinelog/o1_mf_2_7xt450rv_.log
1 ONLINE /u01/oradata/WILSON/onlinelog/o1_mf_1_7xt44nq1_.log
1 ONLINE /u01/flash_recovery_area/WILSON/onlinelog/o1_mf_1_7xt44qt6_.log
6 rows selected
在v$logfile中,有一个状态列status,默认情况下是为空。
2、非Current日志组成员添加
如果当前我们希望给日志组添加一个member的时候,Oracle是提供了相应的语句的。当前日志组是group 3,我们先给非current组添加。
SQL> alter database add logfile member '/u01/flash_recovery_area/WILSON/onlinelog/redolog01a.log' to group 1;
Database altered
SQL> select group#, status, type, member from v$logfile;
GROUP# STATUS TYPE MEMBER
---------- ------- ------- --------------------------------------------------------------------------------
3 ONLINE /u01/oradata/WILSON/onlinelog/o1_mf_3_7xt456o0_.log
3 ONLINE /u01/flash_recovery_area/WILSON/onlinelog/o1_mf_3_7xt45bvp_.log
2 ONLINE /u01/oradata/WILSON/onlinelog/o1_mf_2_7xt44w3k_.log
2 ONLINE /u01/flash_recovery_area/WILSON/onlinelog/o1_mf_2_7xt450rv_.log
1 ONLINE /u01/oradata/WILSON/onlinelog/o1_mf_1_7xt44nq1_.log
1 ONLINE /u01/flash_recovery_area/WILSON/onlinelog/o1_mf_1_7xt44qt6_.log
1 INVALID ONLINE /u01/flash_recovery_area/WILSON/onlinelog/redolog01a.log
7 rows selected
SQL> select group#, sequence#, members, status, first_change#, next_change# from v$log;
GROUP# SEQUENCE# MEMBERS STATUS FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------- ---------------- ------------- ------------
1 73 3 INACTIVE 1560017 1580625
2 74 2 INACTIVE 1580625 1600939
3 75 2 CURRENT 1600939 281474976710
注意,我们的确给group 1添加了文件。但是该文件的状态是INVALID。在OS层面,我们观察一下:
[oracle@bspdev onlinelog]$ pwd
/u01/flash_recovery_area/WILSON/onlinelog
[oracle@bspdev onlinelog]$ ls -l
total 205040
-rw-r----- 1 oracle oinstall 52429312 Sep 10 03:56 o1_mf_1_7xt44qt6_.log
-rw-r----- 1 oracle oinstall 52429312 Sep 10 03:56 o1_mf_2_7xt450rv_.log
-rw-r----- 1 oracle oinstall 52429312 Sep 10 04:04 o1_mf_3_7xt45bvp_.log
-rw-r----- 1 oracle oinstall 52429312 Sep 10 04:03 redolog01a.log
[oracle@bspdev onlinelog]$
在OS层面上,Oracle的确创建了文件redolog01a.log,而且大小和其他组成员大小相同。那么这个INVALID状态是什么意思呢?如果我们切换日志组,转换到文件上,有什么问题吗?
SQL> alter system switch logfile;
System altered
SQL> select group#, sequence#, members, status, first_change#, next_change# from v$log;
GROUP# SEQUENCE# MEMBERS STATUS FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------- ---------------- ------------- ------------
1 76 3 CURRENT 1601735 281474976710
2 74 2 INACTIVE 1580625 1600939
3 75 2 ACTIVE 1600939 1601735
SQL> select group#, status, type, member from v$logfile;
GROUP# STATUS TYPE MEMBER
---------- ------- ------- --------------------------------------------------------------------------------
(篇幅原因,有省略……)
2 ONLINE /u01/flash_recovery_area/WILSON/onlinelog/o1_mf_2_7xt450rv_.log
1 ONLINE /u01/oradata/WILSON/onlinelog/o1_mf_1_7xt44nq1_.log
1 ONLINE /u01/flash_recovery_area/WILSON/onlinelog/o1_mf_1_7xt44qt6_.log
1 ONLINE /u01/flash_recovery_area/WILSON/onlinelog/redolog01a.log
7 rows selected
当进行switch logfile之后,redolog01a.log文件的状态变为空,表示一切正常。可以猜想:当日志切换到一个新的日志组的时候,会将日志原有的内容覆盖刷新。这个过程中,伴随着各个成员Member保持一致。此时,,Invalid状态的日志文件就会得到同步的机会。
进一步想,标记为Invalid状态的日志文件,虽然大小已经确定,但是内容上没有与其他同Group Member同步。所以Oracle将其标记为Invalid。
根据Oracle的工作规则,如果处在Invalid状态的日志文件组不是Current日志组,那么在日志切换到该组的时候,内容都会被覆盖。由此,Invalid状态消失。
那么,如果当前Invalid所在是一个Current日志组,Lgwr不断的写入内容。这个过程是如何呢?
3、Current日志组成员添加
接着上面的实验结果,如果往当前Current日志组中添加成员,效果如何呢?
SQL> alter database add logfile member '/u01/flash_recovery_area/WILSON/onlinelog/redolog01b.log' to group 1;
Database altered
SQL> select group#, status, type, member from v$logfile;
GROUP# STATUS TYPE MEMBER
---------- ------- ------- --------------------------------------------------------------------------------
(篇幅原因,省略….)
1 ONLINE /u01/flash_recovery_area/WILSON/onlinelog/redolog01a.log
1 INVALID ONLINE /u01/flash_recovery_area/WILSON/onlinelog/redolog01b.log
8 rows selected
SQL> select group#, sequence#, members, status, first_change#, next_change# from v$log;
GROUP# SEQUENCE# MEMBERS STATUS FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------- ---------------- ------------- ------------
1 76 4 CURRENT 1601735 281474976710
2 74 2 INACTIVE 1580625 1600939
3 75 2 ACTIVE 1600939 1601735
之后,我们实验生成Redo Entry之后,Lgwr会不会书写到Invalid状态的日志中。
SQL> col name for a10;
SQL> select * from v$statname where;
STATISTIC# NAME CLASS STAT_ID
---------- ---------- ---------- ----------
169 redo size 2 1236385760
SQL> select * from v$mystat where STATISTIC#=169;
SID STATISTIC# VALUE
---------- ---------- ----------
43 169 8585072
SQL> delete t;
72591 rows deleted
SQL> commit;
Commit complete
SQL> select * from v$mystat where STATISTIC#=169;
SID STATISTIC# VALUE
---------- ---------- ----------
43 169 36099756
删除数据表T,生成了(36099756-858072)的redo log。那么,此时Invalid状态的日志文件如何呢?
SQL> select group#, status, type, member from v$logfile;
GROUP# STATUS TYPE MEMBER
---------- ------- ------- --------------------------------------------------------------------------------
(篇幅原因,省略部分……)
1 ONLINE /u01/flash_recovery_area/WILSON/onlinelog/o1_mf_1_7xt44qt6_.log
1 ONLINE /u01/flash_recovery_area/WILSON/onlinelog/redolog01a.log
1 INVALID ONLINE /u01/flash_recovery_area/WILSON/onlinelog/redolog01b.log
8 rows selected
SQL> select group#, sequence#, members, status, first_change#, next_change# from v$log;
GROUP# SEQUENCE# MEMBERS STATUS FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------- ---------------- ------------- ------------
1 76 4 CURRENT 1601735 281474976710
2 74 2 INACTIVE 1580625 1600939
3 75 2 INACTIVE 1600939 1601735
虽然生成了redo log,并且写入到了文件中,但是Invalid状态没有变化。说明,即使是当前的日志组,如果有处在Invalid状态日志,内容不会同步,新日志也不会写入到其中。
只有在日志组切换到下一个循环之后,才能最后实现同步。
SQL> alter system switch logfile;
System altered
SQL> alter system switch logfile;
System altered
SQL> alter system switch logfile;(执行时间很长)
System altered
SQL> select group#, status, type, member from v$logfile;
GROUP# STATUS TYPE MEMBER
---------- ------- ------- --------------------------------------------------------------------------------
(篇幅原因,省略部分……)
1 ONLINE /u01/flash_recovery_area/WILSON/onlinelog/redolog01b.log
8 rows selected
SQL> select group#, sequence#, members, status, first_change#, next_change# from v$log;
GROUP# SEQUENCE# MEMBERS STATUS FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------- ---------------- ------------- ------------
1 79 4 CURRENT 1603673 281474976710
2 77 2 ACTIVE 1603650 1603669
3 78 2 ACTIVE 1603669 1603673
可见,只有在循环之后才有消除Invalid状态。接下来,我们讨论Invalid对Oracle启动过程的影响。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]
