If you can recover the redologs, you can do a complete recovery. Otherwise it is incomplete recovery. This also means there is data loss. Because all processes are not recovered.
First, we will install Oracle RDBMS and Grid infrastructure. If the ASM intance is accessible, the disk group is ready and the Oracle binary is already installed, we can start installation.
Let us assume that the database we will create is 2-node rac and the name ORCL. Suppose the DBID of our previous database is 1039438773. You can learn DBID information by connecting to rman. This information is also available in v$database view. Suppose we have already learned DBID information in some way. Even if you haven’t, you can find this information in old backup logs.
The first process is to create the necessary directories in ASM disk groups.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | [oracle@db01 ~]$ . oraenv ORACLE_SID = [ORCL1] ? +ASM1 The Oracle base remains unchanged with value /u01/app/oracle [oracle@db01 ~]$ asmcmd ASMCMD> cd DATA ASMCMD> mkdir ORCL ASMCMD> cd ORCL ASMCMD> mkdir CONTROLFILE ASMCMD> mkdir DATAFILE ASMCMD> mkdir ONLINELOG ASMCMD> cd .. ASMCMD> ls DATA/ RECO/ ASMCMD> cd RECO ASMCMD> mkdir ORCL ASMCMD> cd ORCL ASMCMD> mkdir CONTROLFILE ASMCMD> mkdir ONLINELOG ASMCMD> mkdir ARCHIVELOG |
The directory specified by the audit_file_dest parameter in the file system must be created on all nodes.
1 2 | [root@db01 ~]# mkdir -p /u01/app/oracle/admin/ORCL/adump [root@db02 ~]# mkdir -p /u01/app/oracle/admin/ORCL/adump |
The next step is to create our pfile file or copy it from the backup to the corresponding directory ($ ORACLE_HOME / dbs). If you have Autobackup, you can also return your spfile file from autobackup.
1 | RMAN> RESTORE SPFILE FROM '/backup_files/c-1039438773-20160405-01'; |
If you do not have a backup, you can create a pfile as below and register it with the name initORCL1.ora (init{SID}.ora).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | *.aq_tm_processes=2 *.audit_file_dest='/u01/app/oracle/admin/ORCL/adump' *.audit_trail='db' *.cluster_database=true *.cluster_database_instances=2 *.compatible='11.2.0.4.0' *.control_files='+DATA/ORCL/controlfile/current.1842.908572993','+RECO/ORCL/controlfile/current.21318.908572995' *.db_block_size=8192 *.db_create_file_dest='+DATA' *.db_create_online_log_dest_1='+DATA' *.db_files=300 *.db_name='ORCL' *.db_recovery_file_dest='+RECO' *.db_recovery_file_dest_size=3221225472000 *.db_unique_name='ORCL' *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)' ORCL2.instance_number=2 ORCL1.instance_number=1 *.job_queue_processes=1000 ORCL1.local_listener='(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.225.16)(PORT=1521))))' ORCL2.local_listener='(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.225.14)(PORT=1521))))' *.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST' *.memory_max_target=20G *.memory_target=20G *.open_cursors=300 *.processes=5000 *.remote_listener='orcl-scan:1521' *.remote_login_passwordfile='exclusive' *.sessions=5505 *.shared_servers=0 ORCL2.thread=2 ORCL1.thread=1 *.undo_retention=1440 ORCL2.undo_tablespace='UNDOTBS2' ORCL1.undo_tablespace='UNDOTBS1' |
If the disk group we want to restore the database is different from the disk group where the old database is located, the following lines must be in the pfile.
1 2 | *.log_file_name_convert='+OLD_DATA','+NEW_DATA','+OLD_RECO','+NEW_RECO' *.db_file_name_convert='+OLD_DATA','+NEW_DATA' |
We start the instance with pfile which we have created or restored.
We set variables before. You can add variables to /home/oracle/.bash_profile.
Or you can add the following line to /etc/oratab and set it with oraenv.
/etc/oratab content:
1 | ORCL1:/u01/app/oracle/product/11.2.0.4/dbhome_1:N |
After adding this line, we can set all variables with oraaenv.
1 2 3 | [oracle@db01 ~]$ . oraenv ORACLE_SID = [+ASM1] ? ORCL1 The Oracle base remains unchanged with value /u01/app/oracle |
Now we can run sqlplus.
1 2 3 4 5 6 7 | [oracle@db01 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Fri Sep 30 15:20:57 2016 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to an idle instance. |
Let’s start Instance from the pfile file we created.
1 | SQL> startup nomount pfile='/backup_files/pfile_ORCL.ora'; |
Then, we restore the control file with rman.
1 2 3 4 5 6 7 8 9 10 11 12 | RMAN> RESTORE CONTROLFILE from '/backup_files/c-1039438773-20160405-01'; Starting restore at 08-APR-16 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=4084 instance=ORCL1 device type=DISK channel ORA_DISK_1: restoring control file channel ORA_DISK_1: restore complete, elapsed time: 00:00:08 output file name=+DATA/orcl/controlfile/current.1862.908626333 output file name=+RECO/orcl/controlfile/current.22252.908626335 Finished restore at 08-APR-16 |
Let’s add the control file files to the pfile file that we created and restart the instance.
The row of the control file in the new pfile:
1 | *.control_files='+DATA/orcl/controlfile/current.1862.908626333','+RECO/orcl/controlfile/current.22252.908626335' |
After the change, close the instance and reopen it as above.
If the directory in which we copy the backups to restore is different from the paths in the control file, it is necessary to perform catalog operation from rman while in mount mode.
Catalog operation with rman in mount mode:
1 | SQL> startup mount pfile='/backup_files/pfile_ORCL.ora'; |
With the command below, we make sure that the backups in the backup_files file are scanned and written to the control file.(this is catalog operation)
1 | RMAN> catalog start with '/backup_files/'; |
While our database is in nomount mode, we start the restore and recover operations with the following script. With the “set until time” command, we are restoring to the point we specified. If you do not specify it, it will try to restore it until the last moment.
Create a file named restore_recover.sh with the following content and give the necessary permissions(755).
We will run this file as follows.
1 | /path_to_script/restore_recover.sh |
If a different disk group is used, the names of the datafile must be changed and switch database operation is required before recover. The “set newname” command must be run for all datafiles. In this case, restore_recover.sh should be as follows.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | rman << EOF connect target / run { set DBID=1039438773; sql 'alter database mount'; set newname for datafile 1 to '+YENI_DATA'; set newname for datafile 2 to '+YENI_DATA'; set newname for datafile 3 to '+YENI_DATA'; set newname for datafile 4 to '+YENI_DATA'; set newname for datafile 5 to '+YENI_DATA'; set newname for datafile 6 to '+YENI_DATA'; set newname for datafile 7 to '+YENI_DATA'; set newname for datafile 8 to '+YENI_DATA'; set newname for datafile 9 to '+YENI_DATA'; set newname for datafile 10 to '+YENI_DATA'; set newname for datafile 11 to '+YENI_DATA'; set newname for datafile 12 to '+YENI_DATA'; restore database; restore archivelog all; switch database to copy; set until time "to_date('2016-04-06:00:00:00','yyyy-mm-dd:hh24:mi:ss')"; recover database; } EOF |
If the disk group name is the same as before, the content of the restore_recover.sh file should be as follows.
1 2 3 4 5 6 7 8 9 10 11 12 | rman << EOF connect target / run { set DBID=1039438773; sql 'alter database mount'; restore database; restore archivelog all; set until time "to_date('2016-04-06:00:00:00','yyyy-mm-dd:hh24:mi:ss')"; recover database; } EOF |
When the processes are finished, the database and archive logs will be restored and recover will be done. After that, redo logs must also be processed.
We are connecting with sql plus for processing redo logs.
Because the redo logs that are used for all instances in RAC databases are connected, it will request the redologs that are needed to perform complete recovery when you run the following command.
1 | SQL> recover database using backup controlfile until cancel; |
After the line specified by “Specify log:”, you must specify the corresponding redo log. The “Log applied” result is returned when all the required redo logs are recovered.
You can find the entire script below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | [oracle@db01 ]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Fri Apr 8 14:07:29 2016 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options SQL> recover database using backup controlfile until cancel; ORA-00279: change 562385338311 generated at 04/05/2016 17:44:09 needed for thread 1 ORA-00289: suggestion : +RECO ORA-00280: change 562385338311 for thread 1 is in sequence #1607 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /backup_files/ONLINELOG/group_12.11832.858521665 ORA-00279: change 562385338311 generated at needed for thread 2 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /backup_files/ONLINELOG/group_22.2629.858521677 Log applied. Media recovery complete. |
So we have completed a complete recovery. In this case, we can open our database directly.
1 | RMAN> alter database open; |
Otherwise we need to open it by specifying resetlogs.
1 2 3 | RMAN> alter database open resetlogs; database opened |
Since our database has been opened, we can begin operations after restore.
First, create the spfile from the pfile:
1 | SQL> create spfile='+DATA/ORCL/spfileORCL.ora' from pfile='/backup_files/pfile_ORCL.ora'; |
Change the contents of the pfile (initORCL1.ora) under the $ORACLE_HOME/dbs directory as follows:
1 | SPFILE='+DATA/ORCL/spfileORCL.ora' |
Set a password for the SYS user:
1 | SQL> alter user sys identified by your_sys_password; |
Create Orapw file:
1 2 | [oracle@db01 ~]$ cd $ORACLE_HOME/dbs [oracle@db01 ~]$ orapwd file=orapwORCL1 password=Welcome1 entries=5 |
If necessary, add new members to the redo log groups:
1 2 3 | SQL> ALTER DATABASE ADD LOGFILE MEMBER '+RECO' TO GROUP 1; SQL> ALTER DATABASE ADD LOGFILE MEMBER '+RECO' TO GROUP 2; SQL> ALTER DATABASE ADD LOGFILE MEMBER '+RECO' TO GROUP 3; |
If you have not set the local_listener and remote_listener parameters, set it:
We created this information for all nodes when creating pfile.
1 2 3 4 5 6 7 8 9 | SQL> show parameter listener NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ listener_networks string local_listener string (DESCRIPTION=(ADDRESS_LIST=(AD DRESS=(PROTOCOL=TCP)(HOST=172. 16.225.16)(PORT=1521)))) remote_listener string orcl-scan:1521 |
Let’s add the new database and instances to CRS:
1 2 3 | [oracle@db01 ]$ srvctl add database -d ORCL -o /u01/app/oracle/product/11.2.0.4/dbhome_1 -p '+DATA/ORCL/spfileORCL.ora' -n ORCL [oracle@db01 ]$ srvctl add instance -d ORCL -i ORCL1 -n db01 [oracle@db01 ]$ srvctl add instance -d ORCL -i ORCL2 -n db02 |
After copying the necessary files to the second node and creating a second undo tablespace, we can start instance on that node.
Files to copy:
1 2 | db01:$ORACLE_HOME/dbs/initORCL1.ora --> db02:$ORACLE_HOME/dbs/initORCL2.ora db01:$ORACLE_HOME/dbs/orapwORCL1 --> db02:$ORACLE_HOME/dbs/orapwORCL2 |
The creation of the undo tablespace for the second node:
1 2 3 4 5 6 | CREATE UNDO TABLESPACE UNDOTBS2 DATAFILE '+DATA' SIZE 10G AUTOEXTEND ON NEXT 5M MAXSIZE UNLIMITED ONLINE RETENTION NOGUARANTEE BLOCKSIZE 8K FLASHBACK ON; |
Creating a redo log group for the second node and adding a new member:
The size should be the same as that created for the other instance. Group numbers must be different from those created for the other instance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | SQL> ALTER DATABASE ADD LOGFILE THREAD 2 GROUP 4 '+DATA' SIZE 500m; Database altered. SQL> ALTER DATABASE ADD LOGFILE THREAD 2 GROUP 5 '+DATA' SIZE 500m; Database altered. SQL> ALTER DATABASE ADD LOGFILE THREAD 2 GROUP 6 '+DATA' SIZE 500m; Database altered. SQL> ALTER DATABASE ADD LOGFILE MEMBER '+RECO' TO GROUP 4; Database altered. SQL> ALTER DATABASE ADD LOGFILE MEMBER '+RECO' TO GROUP 5; Database altered. SQL> ALTER DATABASE ADD LOGFILE MEMBER '+RECO' TO GROUP 6; Database altered. |
At this stage, we can close the database and open it with srvctl in all instances.
1 | SQL> shu immediate |
1 2 3 4 | [oracle@db01 ]$ srvctl start database -d ORCL [oracle@db01 ]$ srvctl status database -d ORCL Instance ORCL1 is running on node db01 Instance ORCL2 is running on node db01 |
Now, our RAC database is open and runs on 2 nodes.