search
HomeDatabaseMysql TutorialAll about control file in Oracle Database

--数据库实例启动的三个阶段: NOMOUNT(START):打开初始化参数文件 MOUNT:打开控制文件 OPEN:打开数据文件和日志文件 --控制文件 控制文件的作用:管理数据库的状态和描述数据库的物理结构信息。 控制文件主要包含如下信息: 数据库名 数据库标识符DBID 数据



--数据库实例启动的三个阶段:
NOMOUNT(START):打开初始化参数文件
MOUNT:打开控制文件
OPEN:打开数据文件和日志文件

--控制文件
控制文件的作用:管理数据库的状态和描述数据库的物理结构信息。
控制文件主要包含如下信息:
数据库名
数据库标识符DBID
数据库创建时间戳
数据库字符集
数据文件信息
临时文件信息
在线重做日志信息
近期的归档日志信息
表空间信息
RMAN 信息库
检查点信息
损坏的数据块注册表
还原点信息
RESET_SCN
脏数据块的数量
                                         
                                                                    
-------------All about DBID
1. DBID 在数据库创建时自动生成
2. Oracle 不保证两个同名数据库DBID一定唯一
3. DBID 在数据库创建后永远不变,除非使用 $ORACLE_HOME/bin/nid 修改数据库名称时自动生成新的 DBID
4. 在未使用 FRA 时,通过控制文件的自动备份 restore 控制文件时,会遇到 ORA-06495 错误(在11R2尝试时未出现此错误)
5. DBID 和数据库名一样,不仅存在于控制文件,还存在于数据文件、日志文件头部,用于判断控制文件、数据文件和日志文件是否属于同一数据库

--获取数据库的 DBID
1. v$database.dbid

SQL> select dbid from v$database;

      DBID
----------
2127893003

2.控制文件的自动备份文件名(前提是自动备份没有放在FRA上,FRA使用OMF管理方式不会显式地显示DBID信息)
[oracle@ora dbs]$ ls -lrt c*
-rw-r----- 1 oracle asmadmin 48005120 Oct 28 15:09 c-2127893003-20131028-00
--------------2127893003 即为 DBID

3.执行转储命令查看各种数据文件的文件头信息
SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------
         1          1          1   10485760        512          2 NO  CURRENT                 459088 28-OCT-13   2.8147E+14
         2          1          0   10485760        512          2 YES UNUSED                       0                      0
         3          1          0   10485760        512          2 YES UNUSED                       0                      0

SQL> alter system dump logfile '+DATA/test/onlinelog/group_1.266.829746583';

System altered.

SQL> select value from v$diag_info where name='Default Trace File';

VALUE
------------------------------------------------------------
/u01/app/oracle/diag/rdbms/test/test/trace/test_ora_7538.trc

[oracle@ora dbs]$ grep -i 'db id' /u01/app/oracle/diag/rdbms/test/test/trace/test_ora_7538.trc
        Db ID=2127893003=0x7ed5120b, Db Name='TEST'
 
4.如果使用了 catalog ,还可以在查询 catalog 数据库中的 DB 表

select * from catalog_user.DB;


-----------数据库物理信息
在数据库处于 mount 状态(datafile和logfile均未open)时,可以查询记录在控制文件中的相应动态视图获取数据库的物理结构

v$database
v$archive_log
v$datafile
v$tempfile
v$log
v$logfile
v$recover_file

-----------控制文件序列号
控制文件序列号用于判断控制文件是否过时的因素“之一”,在控制文件被更新后就会增长。控制文件的更新包括检查点信息更新,表空间的增删操作等。
控制文件序列号也存在于数据文件和日志文件,只不过它们是在自身的文件头被更新时从当时的控制文件复制而来。
控制文件的更新次数总是比数据文件和日志文件多,因为每当数据文件和日志文件头被更新时,控制文件都会复制其部分内容,同时控制文件
的某些操作比如增量检查点只会更新控制文件而不会更新日志文件盒数据文件。

查看 v$database 和 v$kcvfh 可以查看当前控制文件记录的控制文件序列号和各个数据文件头部所记录的控制文件序列号。

SQL> select CONTROLFILE_SEQUENCE# from v$database;

CONTROLFILE_SEQUENCE#
---------------------
                 1160
                 
SQL> select hxfil as file#, fhcsq from x$kcvfh;

     FILE#      FHCSQ
---------- ----------
         1       1128
         2       1128
         3       1128
         4       1128
         
       
-----------控制文件检查点 SCN
控制文件检查点 SCN 也是判断控制文件是否过时的要素之一。检查点分为完全检查点和增量检查点,完全检查点会把 SCN 更新至数据文件头和控制文件中,
而增量检查点只会将SCN更新至控制文件。无论哪种检查点,其SCN在控制文件中都称为控制文件检查点SCN(有别于数据库检查点SCN)

 select CONTROLFILE_CHANGE# from v$database;

CONTROLFILE_CHANGE#
-------------------
             464297
             
每当控制文件发生变化(增删文件、日志切换、完全或增量检查点),控制文件检查点SCN的值都会上升。该SCN的值一定大于或等于 current redo log 的低位 SCN
同时,控制文件检查点 SCN 的值一定大于所有数据文件头部的检查点SCN号,否则该控制文件就会被认为过时,实例无法启动。

  select controlfile_change# from v$database
  union all
  select first_change# from v$log where status = 'CURRENT';

CONTROLFILE_CHANGE#
-------------------
             466258
             465700

------------数据库检查点 SCN
控制文件中保存的数据库检查点SCN实际上市所有数据文件头中最小的检查点SCN。Oracle 根据该值与每个 redo 日志的高低为SCN一一比较,确定恢复数据文件时
所需的第一个 redo 或归档日志
v$database 中的 checkpoint_change# 和 v$datafile_header 中的 checkpoint_change# 应该一致

SQL> select checkpoint_change# from v$database
  2  union all
  3  select checkpoint_change# from v$datafile_header;

CHECKPOINT_CHANGE#
------------------
            465700
            465700
            465700
            465700
            465700
            
------------online redo 的高低水位 SCN
SQL> select GROUP#,FIRST_CHANGE#,NEXT_CHANGE#,status from v$log;

    GROUP# FIRST_CHANGE# NEXT_CHANGE# STATUS
---------- ------------- ------------ ----------------
         1        459088       465700 INACTIVE
         2        465700   2.8147E+14 CURRENT
         3             0            0 UNUSED
         
FIRST_CHANGE#:低位SCN redo log 中的第一个 redo entry
NEXT_CHANGE#:高位SCN下一个日志文件中的第一个 redo entry


------------RMAN 信息库
RMAN 配置、闪回日志路径、重做日志历史、归档路径及属性、RMAN 备份集信息、RMAN image copy 信息、RMAN 备份集和RMAN IMAGE COPY 中损坏的数据块
数据文件坏块信息等

------------还原点信息
还原点主要通过 create restore point 命令创建,是SCN的别名,主要用于 flashback 技术

------------resetlog SCN

使用resetlog选项open数据块时的SCN值,也存在于数据文件和日志文件头部。每次打开数据库时都会检查他们是否一致


<p><span></span></p><p><span><span>作者:xiangsir</span></span></p><p><span></span></p><p><span><span>QQ:444367417</span></span></p><p><span><span>MSN:xiangsir@hotmail.com</span></span></p>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQL: String Data Types and ENUMs?MySQL: String Data Types and ENUMs?May 13, 2025 am 12:05 AM

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

MySQL BLOB: how to optimize BLOBs requestsMySQL BLOB: how to optimize BLOBs requestsMay 13, 2025 am 12:03 AM

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Adding Users to MySQL: The Complete TutorialAdding Users to MySQL: The Complete TutorialMay 12, 2025 am 12:14 AM

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

Mastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMay 12, 2025 am 12:12 AM

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

MySQL: String Data Types and Indexing: Best PracticesMySQL: String Data Types and Indexing: Best PracticesMay 12, 2025 am 12:11 AM

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools