Table of Contents
alter database backup controlfile to 'c:\bak.bkp';
Copy after login
" >
alter database backup controlfile to 'c:\bak.bkp';
Copy after login
2、将控制文件备份为文本文件
4、控制文件的恢复
5、添加多路复用的控制文件
二、重做日志文件的管理
1、重做日志文件概述
2、查询重做日志文件信息
3、重做日志文件组及成员的创建
4、重做日志文件组及成员的删除
5、修改重做日志文件的名称或位置
三、归档日志文件的管理
1、归档日志文件概述
2、归档日志信息的查询
3、归档模式的设置
Home Database Oracle Detailed explanation of Oracle control file and log file management issues

Detailed explanation of Oracle control file and log file management issues

Jul 26, 2022 pm 02:11 PM
oracle

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;
Copy after login
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;
Copy after login
Use data dictionary v$datafile to obtain data file information.

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

select name from v$controlfile;
Copy after login
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
Copy after login
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
Copy after login
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
Copy after login
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';
Copy after login

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;
Copy after login

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
Copy after login

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

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

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

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

alter database drop logfile member 文件名
Copy after login

删除group5添加的新成员文件

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

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;
Copy after login

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

startup mount;
Copy after login

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

alter database noarchivelog;
Copy after login

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

alter database archivelog;
Copy after login

4、重新打开数据库

alter database open;
Copy after login

推荐教程:《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 of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

See all articles