What Happen if Controlfile got corrupted or deleted ?

 Summary: in this tutorial, you will learn how to restore the Control file if the Control file got corrupted or deleted by someone's Oracle Database.







Remainders:

 In this case, we should have a current backup of the control file previously.


Likewise below!

Task1:

SQL> ALTER DATABASE BACKUP CONTROLFILE TO '/u01/backup/ramesh/control.bkp';


Database altered.

**********************************************************************************************************************************************************************
Task2:

RMAN> BACKUP CURRENT CONTROLFILE;

Starting backup at 29-MAY-23
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=130 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 29-MAY-23
channel ORA_DISK_1: finished piece 1 at 29-MAY-23
piece handle=/u01/app/oracle/fast_recovery_area/TEST/backupset/2023_05_29/o1_mf_ncnnf_TAG20230529T200541_l79g1yd3_.bkp
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 29-MAY-23

RMAN> exit

**********************************************************************************************************************************************************************

Step1:

Find the control file location using the below commands  

SQL>  select name from v$controlfile;


NAME

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/TEST/controlfile/o1_mf_l79fd0g5_.ctl

/u01/app/oracle/fast_recovery_area/TEST/controlfile/o1_mf_l79fd0h3_.ctl

**********************************************************************************************************************************************************************

Step2:

This work log is about deleting the control files

[oracle@oracle ramesh]$ cd /u01/app/oracle/oradata/TEST/controlfile/

[oracle@oracle controlfile]$

[oracle@oracle controlfile]$ ll

total 9808

-rw-r-----. 1 oracle oinstall 10043392 May 29 20:07 o1_mf_l79fd0g5_.ctl

[oracle@oracle controlfile]$

[oracle@oracle controlfile]$

[oracle@oracle controlfile]$

[oracle@oracle controlfile]$ rm o1_mf_l79fd0g5_.ctl

[oracle@oracle controlfile]$

[oracle@oracle controlfile]$ ll

total 0

[oracle@oracle controlfile]$

[oracle@oracle controlfile]$ cd /u01/app/oracle/fast_recovery_area/TEST/controlfile/

[oracle@oracle controlfile]$ ll

total 9808

-rw-r-----. 1 oracle oinstall 10043392 May 29 20:07 o1_mf_l79fd0h3_.ctl

[oracle@oracle controlfile]$ rm o1_mf_l79fd0h3_.ctl

[oracle@oracle controlfile]

**********************************************************************************************************************************************************************

Step3:

We are going to fix the issues using the below methods

Down the database, you will get a missing control file error like below!

SQL> shut immediate

ORA-00210: cannot open the specified control file

ORA-00202: control file: '/u01/app/oracle/oradata/TEST/controlfile/o1_mf_l79fd0g5_.ctl'

ORA-27041: unable to open file

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3

SQL> shut abort

ORACLE instance shut down.

SQL> startup nomount;

ORACLE instance started.


Total System Global Area 1677721600 bytes

Fixed Size                  2925120 bytes

Variable Size            1073745344 bytes

Database Buffers          587202560 bytes

Redo Buffers               13848576 bytes

SQL>


**********************************************************************************************************************************************************************

Step4:

This is the way to connect the RMAN Utility

[oracle@oracle controlfile]$ rman target /

Recovery Manager: Release 12.1.0.2.0 - Production on Mon May 29 20:10:52 2023

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

connected to target database: TEST (not mounted)

RMAN>

*********************************************************************************************************************************************************************

Step6:

Using the below command to restore the control files 

RMAN> RESTORE CONTROLFILE FROM '/u01/backup/ramesh/control.bkp';


Starting restore at 29-MAY-23

using channel ORA_DISK_1


channel ORA_DISK_1: copied control file copy

output file name=/u01/app/oracle/oradata/TEST/controlfile/o1_mf_l79fd0g5_.ctl

output file name=/u01/app/oracle/fast_recovery_area/TEST/controlfile/o1_mf_l79fd0h3_.ctl

Finished restore at 29-MAY-23

**********************************************************************************************************************************************************************

Step7:

Once restore is completed then apply the Archivelog using the below commands 

RMAN> recover database;


Starting recover at 29-MAY-23

Starting implicit crosscheck backup at 29-MAY-23

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=243 device type=DISK

Crosschecked 13 objects

Finished implicit crosscheck backup at 29-MAY-23


Starting implicit crosscheck copy at 29-MAY-23

using channel ORA_DISK_1

Finished implicit crosscheck copy at 29-MAY-23


searching for all files in the recovery area

cataloging files...

no files cataloged


using channel ORA_DISK_1


starting media recovery


archived log for thread 1 with sequence 9 is already on disk as file /u01/app/oracle/fast_recovery_area/TEST/onlinelog/o1_mf_3_l79fd3h9_.log

archived log file name=/u01/app/oracle/fast_recovery_area/TEST/onlinelog/o1_mf_3_l79fd3h9_.log thread=1 sequence=9

media recovery complete, elapsed time: 00:00:00

Finished recover at 29-MAY-23

**********************************************************************************************************************************************************************

Step8:

Once done the recovery needs to open the database reset logs 

Resetlogs nothing but it applies the log starting from the first number! 

RMAN> alter database open resetlogs;


Statement processed

**********************************************************************************************************************************************************************

Step 9: We are fixed the issues!

[oracle@oracle controlfile]$ sqlplus / as sysdba


SQL*Plus: Release 12.1.0.2.0 Production on Mon May 29 20:28:47 2023


Copyright (c) 1982, 2014, Oracle.  All rights reserved.



Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options


SQL>

SQL>

SQL> select name,open_mode from V$database;


NAME      OPEN_MODE

--------- --------------------

TEST      READ WRITE


SQL> select name from v$controlfile;


NAME

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/TEST/controlfile/o1_mf_l79fd0g5_.ctl

/u01/app/oracle/fast_recovery_area/TEST/controlfile/o1_mf_l79fd0h3_.ctl


**********************************************************************************************************************************************************************

Thanks for your time!!



1 Comments

  1. RESTORE CONTROLFILE FROM '/u01/backup/ramesh/control.bkp'; you should also explain how you identified this control file backup location

    ReplyDelete

DELETE Statement in ORACLE DB— Step by Step Internal Flow with classroom example.

Imagine your Oracle database like a school, and you’re Teacher decides to remove a student (row) from the classroom(table). Let’s see how the journey works step by step: 1)Classroom = Oracle Table 2)Students = Rows (Records) 3)Class Teacher = Oracle Server Process 4)Attendance Register = Data Dictionary User fires DELETE statement: DELETE FROM students WHERE grade = 'D'; Internal Processing Steps: Client Process Sends DELETE Statement to Server Process The teacher receives a request to remove a student from the classroom. Syntax Check (Parsing) The teacher checks if the request is grammatically correct — proper command, keywords, and a semicolon. Semantic Check Teacher verifies if the classroom exists and whether the condition (like grade = 'D') makes sense. Object Resolution Teacher confirms that the ‘students’ classroom (table) exists in the school records (data dictionary). Optimization Decides the fastest way to find those students — by roll number, grade, or al...