Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1610256
  • 博文数量: 409
  • 博客积分: 6240
  • 博客等级: 准将
  • 技术积分: 4908
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-01 00:04
文章分类

全部博文(409)

文章存档

2021年(1)

2019年(1)

2017年(1)

2016年(13)

2015年(22)

2013年(4)

2012年(240)

2011年(127)

分类: Oracle

2012-08-09 21:17:32


什么是数据文件、控制文件、重做日志文件?
首先从Oracle的官方文档里摘录下面内容:
The following sections explain the physical database structures of an Oracle database, including datafiles, redo log files, and control files
下面几段内容将解释一下,Oracle数据库的物理结构是什么?其中包括数据文件、控制文件和重做日志文件。
Datafiles
Every Oracle database has one or more physical datafiles. The datafiles contain all the database data. The data of logical database structures, such as tables and indexes, is physically stored in the datafiles allocated for a database.
The characteristics of datafiles are:
A datafile can be associated with only one database.
Datafiles can have certain characteristics set to let them automatically extend when the database runs out of space.
One or more datafiles form a logical unit of database storage called a tablespace.
Data in a datafile is read, as needed, during normal database operation and stored in the memory cache of Oracle. For example, assume that a user wants to access some data in a table of a database. If the requested information is not already in the memory cache for the database, then it is read from the appropriate datafiles and stored in memory.
Modified or new data is not necessarily written to a datafile immediately. To reduce the amount of disk access and to increase performance, data is pooled in memory and written to the appropriate datafiles all at once, as determined by the database writer process (DBWn) background process.

什么是数据文件:
每一个Oracle数据库都要有一个或者多个物理的数据文件,这些数据文件里存储的就是Oracle数据库里的数据。就好比你有一个文件夹,里面有几个txt的文本文件,文本文件里记录的你这个月的每一笔花销。如果把文件夹看做是数据库,那么txt文件就是数据文件,而txt文件里面记录的每一笔花销就是数据了。
然而表、索引等等其实都是数据库的逻辑结构,这些表、索引都被物理的存储在了数据文件里面。
数据文件有三个特性:
1、一个数据文件只能属于一个数据库。
2、数据库中的数据文件可以被设置成自动的增长。(当数据库的空间用完的时候,数据库中的数据文件就会自动增长,比如原来1G的数据文件自动变成了2G的数据文件)
3、一个或者多个数据文件就组成了数据库的一个逻辑单元叫做---表空间。
数据文件里的数据,在需要的时候就会被读取到内容Oracle的缓冲区中,比如当我们想查看一天数据时,而这条数据恰好又不在Oracle的缓冲区中,那么Oracle就会把这条数据从数据文件中读取到Oracle的缓冲区中来。
当更改或者新增一天数据时,也不是马上就写到数据文件里面,这么做是为了减少对磁盘的访问,提高效率,数据先存储在缓冲区,然后在一次都写入数据文件,这个过程有一个dbwn后台进程来控制。
Control Files
 
Every Oracle database has a control file. A control file contains entries that specify the physical structure of the database. For example, it contains the following information:
Database name 
Names and locations of datafiles and redo log files 
Time stamp of database creation 
Oracle can multiplex the control file, that is, simultaneously maintain a number of identical control file copies, to protect against a failure involving the control file.
Every time an instance of an Oracle database is started, its control file identifies the database and redo log files that must be opened for database operation to proceed. If the physical makeup of the database is altered (for example, if a new datafile or redo log file is created), then the control file is automatically modified by Oracle to reflect the change. A control file is also used in database recovery.
控制文件:
每一个数据库都拥有控制文件(它和数据文件一样重要),控制文件里记录的是对数据库物理结构的详细信息,例如它包括如下三个信息:
1、数据库的名称
2、数据文件的名字和存在位置,重做日志文件的名字和存储位置
3、数据库创建的时间标识
Oracle可以使用多重的控制文件,也就是说它可以同时维护多个完全一样的控制文件,这么做就是为了防止数据文件损坏而造成的数据库故障。比如Oracle同时维护3个控制文件,当其中有1个控制文件出问题了,就比较好解决,把出问题的删了,在复制一份没有问题的就可以了。
每当Oracle数据库的实例启动的时候,它就会通过控制文件来识别,要想执行数据库的一些操作,必须需要哪些数据文件和重做日志文件,以及这些数据文件和重做日志文件都存在在什么位置。当数据库的物理构成发生改变的时候,比如新增加了一个数据文件或者重做日志文件,那么控制文件就会自动的更新来记录这些变化。另外在数据库恢复的时候也会用到控制文件。
Redo Log Files
 
Every Oracle database has a set of two or more redo log files. The set of redo log files is collectively known as the redo log for the database. A redo log is made up of redo entries (also called redo records).
The primary function of the redo log is to record all changes made to data. If a failure prevents modified data from being permanently written to the datafiles, then the changes can be obtained from the redo log, so work is never lost.
 
To protect against a failure involving the redo log itself, Oracle allows a multiplexed redo log so that two or more copies of the redo log can be maintained on different disks.
The information in a redo log file is used only to recover the database from a system or media failure that prevents database data from being written to the datafiles. For example, if an unexpected power outage terminates database operation, then data in memory cannot be written to the datafiles, and the data is lost. However, lost data can be recovered when the database is opened, after power is restored. By applying the information in the most recent redo log files to the database datafiles, Oracle restores the database to the time at which the power failure occurred.
The process of applying the redo log during a recovery operation is called rolling forward.
重做日志文件:
每个Oracle数据库都拥有一组文件,其中包括2个或者多个重做日志文件(其实也可以拥有多组,用途跟多个控制文件一样)。这组文件整体被称为数据库的重做日志,而重做日志又是由一条一条的重做记录组成的,所有也被称为重做记录。
重做日志的主要作用就是记录所有的数据变化,当一个故障导致被修改过的数据没有从内存中永久的写到数据文件里,那么数据的变化是可以从重做日志中获得的,从而保证了对数据修改的不丢失。
为了防止重做日志自身的问题导致故障,所以Oracle拥有多重重做日志功能,也就是可以同时保存多组完全相同的重做日志在不同的磁盘上。
重做日志里的信息只是用于恢复由于系统或者介质故障所引起的数据没法写入数据文件的数据。比如突然断电导致数据库的关闭,那么内存中的数据就不能写入到数据文件中,内存中的数据就会丢失。但当数据库重新启动时丢失的数据是可以被恢复的,可以从最近的重做日志中读取丢失信息然后应用到数据文件中,这样就把数据库恢复到断电前的状态。
在恢复操作中恢复重做日志信息的过程叫做前滚。

-----------------------------------------------
重做日志与联机日志
重做日志文件也叫联机日志文件,一般数据库有几个日志文件(例如有三个,编号分别为1,2,3)先写1,当1满时再写2,当2满时再写3,当3满时1就归档出来,产生一个文件写到磁盘上,这个文件就叫归档日志文件.1归档出来后,新的联机日志文件又写到1中,将原来的覆盖,(即联机日志是循环使用的).一般当产生一个检查点或联机日志写满一定程度时会产生一个归档日志文件.(只有数据库运行在归档模式并且初始化参数ARCHIVE_LOG_START等于TRUE时,ARCn进程才能被启动,进行自动归档。
阅读(2853) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~