Sunday, 31 July 2016

Control file corrupted

Scenarios in which control file to be backed up  in Oracle
It is very important to backup control file whenever there is a change in the physical structure of the database. Some of the examples of structural changes are
  • Adding or dropping or renaming of datafiles
  • Adding or dropping a tablespace
  • Altering the read/write state of the tablespace
  • Adding or dropping redolog files or groups

Control file backup procedure  in Oracle
ALTER DATABASE BACKUP CONTROLFILE statement is used to backup control files in Oracle.
There are 2 options to backup control files.
  1. Backup the control file to a binary file (duplicate of existing control file) using the below statement:
ALTER DATABASE BACKPUP CONTROLFILE  TO  ‘/oracle/backup/control.bkp’;

  1. Produce SQL statements that can later be used to re-create control file.

ALTER DATABASE BACKUP CONTROLFILE  TO TRACE;
Above command writes  a SQL script to the database trace file where it can be captured and edited to regenerate the control file.

Recovering an instance when one of the  control files got corrupted
Oracle recommends to have atleast 2 control files each stored on a different disk.
(Please note, for SAP applications , 3 control files are generally maintained in an oracle database at different locations)
If a control file got corrupted due to a disk failure the respective instance should be shut down. Once the disk drive is repaired, the corrupted control file can be restored using the copy of control file from other disk and the instance can be brought up. In these cases, media recovery is not required.

How multiple control files are managed in Oracle?

  • All the control files that are listed in the CONTROL_FILES parameter are updated by the database.
  • The database reads only the first file listed in the CONTROL_FILES parameter during database operation
  • If any of the control files got corrupted or become unavailable during database operation, the instance won’t function and it should be shutdown and recovered as mentioned earlier


Query to find current location of control files :

SQL > select name from v$controlfile;

After executing the above query, System outputs  the location of all control files in the system
Usually there will be 3 control files in oracle database( for SAP applications).

Can we rename or move control files location? If so, what is that parameter?

Yes. If required, control files location can changed with the control_files instance parameter.
Please execute the below query to display the current value of control_files parameter
SQL > show parameter control_files
The above command outputs the current value. This value can be changed with the ALTER SYSTEM command. In other words the current location of the control files can be changed using ALTER SYSTEM command.

Steps to be followed to rename or move control files location

1)      Alter the control_files parameter using the ALTER SYSTEM command
Syntax:
SQL> ALTER SYSTEM SET control_files=’<New controlfile1 path or newcontrol file name>’, <New controlfile2 path or newcontrol file name>’, <New controlfile13 path or newcontrol name>’ SCOPE=SPFILE;
 Eg: In the below command set the paths or names  for various control files  as per your requirement
SQL> ALTER SYSTEM SET control_files=’D:\ORACLE\..\..\..\Newname1.CTL’, 
’D:\ORACLE\..\..\..\Newname2.CTL’,  ’D:\ORACLE\..\..\..\Newname3.CTL’
SCOPE=SPFILE;

2)     Shutdown the database
SQL > shutdown immediate;

3)     Rename the physical file in the OS
SQL >  HOST  MOVE <old controlfile with path> <new controlfile with path >
 Eg:
SQL > HOST  MOVE  D:\ORACLE\ORADATA\CONTROL01.CTL D:\ORACLE\ORADATA\NEW_CONTROL01.CTL
4)     Start the database
SQL > startup

No comments:

Post a Comment