Home > Database > Oracle > body text

Detailed explanation of Oracle control file and log file management issues

WBOY
Release: 2022-07-26 20:00:04
forward
2593 people have browsed it

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!

Related labels:
source:jb51.net
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!