Wednesday, October 10, 2012

Oracle File Structure

The file structure of an oracle database will consist of the following files.

1) Control file
2) Redo log file
3) Datafile

Control file:

The control file will have .ctl file extention. There must be a min of 1 control file for a database. We can have upto 8 control files (multiplexing) in different locations for safety. Oracle recommends a minimum of atleast two controlfiles for a database, each controlfile on a separate hard disk drive, multiplexing is keeping mirror copies of the same file in different locations. Incase one of the controlfiles gets deleted then the database will stop functioning at that time.

The solution to this problem is,

1) Remove the entry of the damaged controlfile from the database itself and restart the database and run it with the help of the remaining controlfiles.
2) Shut the database, replace the damaged disk, copy the existing controlfile from the other location , rename the file and restart the database.

The controlfile is the first file that is opened by a database, after opening this file oracle can find the other files like redo logs and datafiles.
The control file is a very important file it will keep critical info regarding the database like,

1) Name and database id of the database.
2) Path and file name of all the datafiles and redo logfiles.
3) Status of the last shutdown of the db (wether db shutdown gracefully or ungracefully).
4) Date and time of creation of the database.
5) System change number (scn) - unique number generated by oracle database every 3 seconds. it is used by oracle to determine recoveribility of a database after a database crash has occured.
6) Incase a dba calls recovery manager (rman) tool to perform a backup of a database, then after completion of that backup, rman will write a record to the database controlfile. That record contains information about the backup taken by rman, this information contains the address of the backup, label given to the backup, size of the backup, scn information generated during the backup and archive information.



Without the control file even if all other files are present we cannot open the database.

It is always advisable to multiplex the control file and maintain two or more copies on multiple disk drives. So even if 1 drive fails we can open db with controlfile on other drive.
Control file is a very tiny file (few kilobytes in size). it only keeps the details of the definition of the database but not the data itself

Redo log file:

1) These files contain the latest transactions that are performed by programmers, DBA's and end users against the database.
2) Redo logfiles will appear under 'log groups', A log group is a logical collection of one or more redo log files.
3) One database should have min of 2 log groups.
4) Each log group can have a min of 1 redo-log file and max of 5 redo-logfiles (multiplexing).
5) The log group is logical in nature it is not a file.
6) At any point in time oracle database will write to the log files of 1 group only that group is said to be the "current group". All the log files within 1 group will keep the same data.

When ever 1 log group is becoming full then oracle will perform a "log switch" and begin writing to the other group which will now become current. this is a cyclic process.

When a log switch occurs then oracle will begin writing to the next log group ,but the previous log groups data will be moved to the datafiles.

7) The min size of logfile in 10g is 4m and 9i it is 300k.
8) Log file will have .log file extention.

Datafiles:

1) They will contain the table rows and index data.
2) The database file will have .dbf file extention.
3) Each dbf is made up of data blocks which has a size of 2 to the power n kb where n ranges from 1 to 5.
4) The very first block of a datafile will keep the scn for that file. the first block of a datafile is also known as the file header or header block.
5) The dbf's are mostly in gb and can even grow to tera byte size.
6) All datablocks in one datafile must be of the same size.

Multiplexing of ctl and log file can save us in case of loss of control or log file but we cannot multiplex a dbf as its size is too huge. Thus we must always backup the dbf from time to time.

No comments:

Post a Comment

Some Most Popular Articles