search
HomeDatabaseOracleDetailed explanation of Oracle control file and log file management issues

This article brings you relevant knowledge about Oracle. It mainly introduces the management of Oracle control files and log files. The control file is one of the physical files of Oracle. Each Oracle database has There must be at least one control file, which records the name of the database, the location of the data file and other information. Let's take a look at it together. I hope it will be helpful to everyone.

Detailed explanation of Oracle control file and log file management issues

## Recommended tutorial: "

Oracle Video Tutorial"

1. Management of control files

The control file is one of Oracle's physical files. Each Oracle database must have at least one control file, which records the name of the database, the location of the data files and other information. When starting a data instance, Oracle will locate the control file based on the initialization parameters, and then Oracle will establish an association between the instance and the database based on the control file. The importance of the control file is that once the control file is damaged, the database will not be able to start.

1. Overview of the control file

The control file is automatically created when the database is created, and will be updated at the same time when physical changes occur in the database. Make sure the control file is available at all times. Only the Oracle process can safely update the contents of the control file, so do not attempt to manually edit the control file at any time.

2. Creation of control files

When the database is created, the system will create a control file based on the settings of control_files in the initialization parameter file. In the later use of the database, if the control file is lost or damaged, a new control file can be created manually.

The basic syntax for manually creating a control file is as follows.

create controlfile
reuse database db_name
logfile
group 1 redofiles_list1
...
datafile
...
maxlogfiles max_value1
maxlogmembers max_value2
maxinstances max_value3
maxdatafiles max_value4
noresetlogsiresetlogs
archiveloginoarchivelog;
The parameter description is as follows.

db_name: database name.
logfile: Indicates the log group file defined below.
redofiles_list1: The name and path of redo log file list 1 in the redo log group.
datafile: Indicates the data file defined below.
max_value1: The maximum number of redo log files.
max_value2: The maximum number of redo log group members.
max_value3: Maximum number of instances.
max_value4: Maximum number of data files.
The basic steps for creating a new control file are as follows.
1. View the names and paths of all data files and redo log files in the database.
2. Close the database.
3. Back up all data files and redo log files.
4. Start the database instance.
5. Create a new control file.
6. Edit initialization parameters.
7. Reopen the database.

1. Re-establish the control file

1. Check the names and paths of all data files and redo log files in the database.

If the database can be opened, you can use the data dictionary to obtain basic information about the data files and log files, as shown below.
Use data dictionary v$logfile to obtain log file information.

select member from v$logfile;
Use data dictionary v$datafile to obtain data file information.

select name from v$datafile;
Use data dictionary v$controlfile to obtain control file information.

select name from v$controlfile;
2. Close the database

If the database is running, before creating the control file, first log in as the sys user and close the database.

conn sys/change_on_install as sysdbashutdown normal
3. Back up all data files and redo log files.

4. Start the database instance.
After the backup is completed, start the database, but do not load the database first. This is mainly because if the database is loaded, the control file will be opened at the same time, and the purpose of creating a new control file cannot be achieved.

startup nomount
3. Backup of control files

In the process of daily database maintenance, in order to avoid the database system crash due to loss or damage of the control file, it is necessary to frequently back up the control file. Files are backed up. Especially when the database structure is modified, such as adding or deleting data files, the control file needs to be backed up again in time.

Backing up the control file can be achieved using the following statement.

alter database backup controlfile
There are generally two types of backups using this statement, one is to back up in the form of a binary file, and the other is to back up in the form of a text file. Let's take a look at how to implement the backup of control files.

1. Back up the control file as a binary file

alter database backup controlfile to 'c:\bak.bkp';

The above code implements backing up the control file to the root directory of the C drive. The file name is bak.bkp. The file exists in binary form.

2、将控制文件备份为文本文件

alter database backup controlfile to trace;

4、控制文件的恢复

当数据库由于各种情况发生损坏时,这时可以使用所备份的文件来恢复数据库。在日常维护中,经常会遇到两种情况,一种是控制文件损坏,另一种情况是磁盘发生故障。
当控制文件损坏时,这种情况较为简单,只需要用备份文件替换损坏的文件即可,不过复制之前要先关闭数据库,然后再复制,复制完成后需要重新启动。

5、添加多路复用的控制文件

为了提高数据库的可靠性,可以建立多个镜像的控制文件,并且分别保存在不同的磁盘中进行多路复用,这样就可以避免由于单个设备故障而使得数据库无法启动的情况发生,这种管理策略被称为多路复用控制文件。当某个磁盘发生物理损坏导致控制文件损坏,数据库将被关闭,此时就可以利用另一个磁盘中保存的控制文件来恢复被损坏的控制文件,然后再重新启动数据库,达到保护控制文件的目的。

二、重做日志文件的管理

重做日志文件也称为日志文件,是记录系统的日常操作、异常等行为的文件,是包含系统信息的文件,包括内核、服务、在系统上运行的应用程序等。重做日志文件是数据库安全和恢复的基本保障,当数据库出现故障的时候,管理员可以根据日志文件和数据库备份文件,将崩溃的数据库恢复到最近一次记录日志时的状态。

1、重做日志文件概述

在oracle数据库中,重做日志文件用于记录用户对数据库所做的各种变更操作所引起的数据变化,此时,所产生的操作会先写入重做日志缓冲区,当用户提交一个事务的时候,LGWR进程将与该事务相关的所有重做记录写入重做日志文件,同时生成一个“系统变更数”,scn会和重做记录一起保存到重做日志文件组,以标识与该事务提交成功。如果某个事务提交出现错误,可以通过重做记录找到数据库修改之前的内容,进行数据恢复。

2、查询重做日志文件信息

在oracl数据库日常运行过程中,数据库管理员可以查看重做日志文件信息,用于了解数据库的运行情况。这可以通过查询数据字典视图v l o g 、 v log、v log、vlogfile和v l o g h i s t o r y 来 实 现 , 通 过 它 们 可 以 查 询 的 信 息 如 下 。 v log_history来实现,通过它们可以查询的信息如下。 v loghistory来实现,通过它们可以查询的信息如下。vlog:包含重做日志文件组的信息。
v l o g f i l e : 包 含 重 做 日 志 文 件 成 员 信 息 。 v logfile:包含重做日志文件成员信息。 v logfile:包含重做日志文件成员信息。vlog_history:包含日志历史信息。

3、重做日志文件组及成员的创建

在数据库的日常维护过程中,数据库管理员可以通过手工方式向数据库中添加新的重做日志组或日志文件,也可以改变重做日志文件的名称与位置,或者删除重做日志组或其成员。

1、创建重做日志文件组
语法如下:

alter database add logfile [group] [编号](日志文件) size

上面语句中group可选,当不选择的时候,系统会自动产生组号,为当前重做日志文件组的个数加1。

4、重做日志文件组及成员的删除

当重做日志文件组,其成员不合适或者所在存储位置出现错误时,此时可以将重做日志文件组或者其成员删除。

1、删除重做日志成员文件
删除重做日志文件成员使用如下语法。

alter database drop logfile member 文件名

删除group5添加的新成员文件

alter database drop logfile member 'd:\app\redo05_3.log';

5、修改重做日志文件的名称或位置

在数据库正常使用中,如果想要改变重做日志文件的名称或位置,可以按照如下步骤进行重做日志文件的修改。
1、关闭数据库。
2、复制或者修改日志文件的位置。
3、启动数据库实例,但不打开数据库,只加载数据库。
4、重新设置重做日志文件的名称或位置。
5、打开数据库。

三、归档日志文件的管理

在oracle数据库中,重做日志文件用于记录用户对数据库所做的各种变更操作所引起的数据变化。在把这些变化写入重做的日志文件的时候,一般情况下有多个重做日志文件组,每个文件组有多个文件,oracle向这些重做文件写入的时候,一般情况下有多个重做日志文件组,每个文件组有多个文件,oracle向这些重做文件写入的时候,是使用循环的方式向这些重做日志文件组中的文件进行写入的,当最后一个重做日志文件组中的文件内容写满后,会重新写入第一个重做日志文件组中的文件。在这种情况下,原先重做日志文件的内容如何处理,是直接覆盖还是把原先的记录保存,就是我们要介绍的归档日志。

1、归档日志文件概述

所谓归档日志文件就是指当重做日志文件写满的时候,把其中内容保存到新的文件中,这些新的文件集合就是归档日志文件。但是重做日志文件并不一定主动被保存到新的文件中,根据数据库设置不同,oracle有两种日志模式:归档日志模式和非归档日志模式。在非归档日志模式下,原日志文件的内容会被新的日志内容所覆盖;在归档日志模式下,oracle会首先对原日志文件进行归档存储,且在归档未完成之前不允许覆盖原有日志。

2、归档日志信息的查询

数据库管理人员可以修改归档日志文件和非归档日志文件,但首先需要了解归档日志信息。在oracle中,可以通过查询数据字典了解归档日志的一些基本信息,常用的数据字典有v a r c h i v e d l o g 、 v archived_log、v archivedlog、varchive_dest、v$database等

3、归档模式的设置

默认情况下,oracle数据库处于非归档日志模式,即当重做日志文件写满的时候,直接覆盖里面的内容,原先的日志记录不会被写入到归档日志文件中。根据oracle数据库对应的应用系统不同,数据库管理员可以把数据库的日志模式在归档模式和非归档模式之间进行切换。可以通过alter database archivelog或noarchivelog语句实现数据库在归档模式与非归档模式之间进行切换。
切换步骤如下:
1、关闭数据库

shutdown immediate;

2、将数据库启动到加载状态。

startup mount;

3、修改数据库的归档模式或非归档模式
归档模式修改为非归档模式

alter database noarchivelog;

非归档模式修改为归档模式

alter database archivelog;

4、重新打开数据库

alter database open;

推荐教程:《Oracle视频教程

The above is the detailed content of Detailed explanation of Oracle control file and log file management issues. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:脚本之家. If there is any infringement, please contact admin@php.cn delete
Oracle's Products: A Deep DiveOracle's Products: A Deep DiveApr 19, 2025 am 12:14 AM

Oracle's product ecosystem includes databases, middleware and cloud services. 1. OracleDatabase is its core product, supporting efficient data storage and management. 2. Middleware such as OracleWebLogicServer connects to different systems. 3. OracleCloud provides a complete set of cloud computing solutions.

MySQL and Oracle: Key Differences in Features and FunctionalityMySQL and Oracle: Key Differences in Features and FunctionalityApr 18, 2025 am 12:15 AM

MySQL and Oracle each have advantages in performance, scalability, and security. 1) Performance: MySQL is suitable for read operations and high concurrency, and Oracle is good at complex queries and big data processing. 2) Scalability: MySQL extends through master-slave replication and sharding, and Oracle uses RAC to provide high availability and load balancing. 3) Security: MySQL provides fine-grained permission control, while Oracle has more comprehensive security functions and automation tools.

Oracle: The Powerhouse of Database ManagementOracle: The Powerhouse of Database ManagementApr 17, 2025 am 12:14 AM

Oracle is called the "Powerhouse" of database management because of its high performance, reliability and security. 1. Oracle is a relational database management system that supports multiple operating systems. 2. It provides a powerful data management platform with scalability, security and high availability. 3. Oracle's working principles include data storage, query processing and transaction management, and supports performance optimization technologies such as indexing, partitioning and caching. 4. Examples of usage include creating tables, inserting data, and writing stored procedures. 5. Performance optimization strategies include index optimization, partition table, cache management and query optimization.

What Does Oracle Offer? Products and Services ExplainedWhat Does Oracle Offer? Products and Services ExplainedApr 16, 2025 am 12:03 AM

Oracleoffersacomprehensivesuiteofproductsandservicesincludingdatabasemanagement,cloudcomputing,enterprisesoftware,andhardwaresolutions.1)OracleDatabasesupportsvariousdatamodelswithefficientmanagementfeatures.2)OracleCloudInfrastructure(OCI)providesro

Oracle Software: From Databases to the CloudOracle Software: From Databases to the CloudApr 15, 2025 am 12:09 AM

The development history of Oracle software from database to cloud computing includes: 1. Originated in 1977, it initially focused on relational database management system (RDBMS), and quickly became the first choice for enterprise-level applications; 2. Expand to middleware, development tools and ERP systems to form a complete set of enterprise solutions; 3. Oracle database supports SQL, providing high performance and scalability, suitable for small to large enterprise systems; 4. The rise of cloud computing services further expands Oracle's product line to meet all aspects of enterprise IT needs.

MySQL vs. Oracle: The Pros and ConsMySQL vs. Oracle: The Pros and ConsApr 14, 2025 am 12:01 AM

MySQL and Oracle selection should be based on cost, performance, complexity and functional requirements: 1. MySQL is suitable for projects with limited budgets, is simple to install, and is suitable for small to medium-sized applications. 2. Oracle is suitable for large enterprises and performs excellently in handling large-scale data and high concurrent requests, but is costly and complex in configuration.

Oracle's Purpose: Business Solutions and Data ManagementOracle's Purpose: Business Solutions and Data ManagementApr 13, 2025 am 12:02 AM

Oracle helps businesses achieve digital transformation and data management through its products and services. 1) Oracle provides a comprehensive product portfolio, including database management systems, ERP and CRM systems, helping enterprises automate and optimize business processes. 2) Oracle's ERP systems such as E-BusinessSuite and FusionApplications realize end-to-end business process automation, improve efficiency and reduce costs, but have high implementation and maintenance costs. 3) OracleDatabase provides high concurrency and high availability data processing, but has high licensing costs. 4) Performance optimization and best practices include the rational use of indexing and partitioning technology, regular database maintenance and compliance with coding specifications.

How to delete oracle library failureHow to delete oracle library failureApr 12, 2025 am 06:21 AM

Steps to delete the failed database after Oracle failed to build a library: Use sys username to connect to the target instance. Use DROP DATABASE to delete the database. Query v$database to confirm that the database has been deleted.

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 Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.