High Availbility

OS & Virtualization

Thursday, June 26, 2008

Flash Recovery usiing Image Copy

Flash Recovery using Image Copy
Image Copy
Oracle RMAN image copies are exact copies of the datafiles, with all the blocks—used or not. Oracle RMAN takes this image copy while the database is up and running, and the database need not be put into any special mode.
Here is how to make an Oracle RMAN image copy backup:
run {
   backup as copy
   database; }

Instant Recovery
Image copies in the FRA become truly useful when you need an "instant recovery." Remember that these image copies are copies of the datafiles—a fact recorded in the Oracle RMAN catalog and the control file. In case of a disaster, you don't need to restore the file; you can use the copy as the principal datafile immediately.
Here is the description of the recovery process, assuming that the USERS tablespace has been damaged: First, check the file ID (number) and name of the datafile of the tablespace. The output is shown in vertical format:
select file_id, file_name  from dba_data_files 
where tablespace_name  = 'USERS'; 
FILE_ID : 4 NAME    : /home/oracle/oradata/PRODB2/users01.dbf 
RMAN> sql 'alter tablespace users offline';
 sql statement: alter tablespace users offline 
RMAN> switch datafile 4 to copy;
 datafile 4 switched to datafile copy "/home/oracle/FRA/PRODB2/datafile/o1_mf_users_2kmqr57t_.dbf" 
RMAN> recover datafile 4;
 Starting recover at 26-SEP-06 using channel ORA_DISK_1
 starting media recovery media recovery complete,
 elapsed time: 00:00:03
 Finished recover at 26-SEP-06  
RMAN> sql 'alter tablespace users online';
 sql statement: alter tablespace users online
 
Switchback 

Even though the datafile has been quickly brought online to minimize downtime, it is now in the backup location, which may be on slower disks than what the main database is on. You may not want to run the database with the datafile at this location for long; you would typically want to move the datafile back to the original location—/home/oracle/oradata/PRODB2/—as soon as it becomes available. You can use Oracle RMAN to accomplish this. Here is a summary of the steps:
1. Make an image copy of the datafile at the original location. 2. Take the tablespace offline. 3. Switch the datafile to the "copy" (however, in this case, the "copy" is at the original location). 4. Recover the tablespace. 5. Place the tablespace online.
These steps are presented in Listing 4. After the switchover, you can make sure the datafile is back in its original location:
select name from v$datafile  where file# = 4;
   NAME ---------------------------------------
 /home/oracle/oradata/PRODB2/users01.dbf
 
RMAN> backup as copy datafile 4 format '/home/oracle/oradata/PRODB2/users01.dbf';
   Starting backup at 27-SEP-06 using channel
 ORA_DISK_1 channel ORA_DISK_1: starting datafile
 copy input datafile fno=00004 name=/home/oracle/FRA/PRODB2/datafile/o1_mf_users_2kmqr57t_.dbf
 output filename=/home/oracle/oradata/PRODB2/users01.dbf
 tag=TAG20060927T103710 recid=45 stamp=602246230 channel
 ORA_DISK_1: datafile copy complete,
 elapsed time: 00:00:01
 Finished backup at 27-SEP-06
   Starting Control File Autobackup at 27-SEP-06 piece handle=/home/oracle/FRA/PRODB2/autobackup/2006_09_27/ o1_mf_n_602246232_2ko34s42_.bkp comment=NONE 
Finished Control File Autobackup at 27-SEP-06 RMAN> sql 'alter tablespace users offline'; ... 
RMAN> switch datafile 4 to copy;   datafile 4 switched to datafile copy "/home/oracle/oradata/PRODB2/users01.dbf"  
RMAN> recover datafile 4; ... 
RMAN> sql 'alter tablespace users online'; ... 
 
In case of a failure, you save valuable time by quickly using the image copy of the datafile in the FRA, and there is no need to restore it first. The same concept can be applied to the entire database as well. If the original location of all the datafiles is damaged, you can easily switch the entire database to the copy stored in the FRA. To switch to the FRA copy, issue the following, which directs the whole database to use all the latest image copies in the FRA location as its datafiles: 
 
RMAN> switch database to copy;  
 


Recover database after disk loss

Control Files

 
Normally, we have multiplexing of controlfiles and they are expected to be placed in different disks.
 
If one or more controlfile is/are lost,mount will fail as shown below:
....
ORA-00205: error in identifying controlfile, check alert log for more info
 
**If at least one copy of the controlfile is not affected by the disk failure, 
   When the database is shutdown cleanly:
   (a) Copy a good copy of the controlfile to the missing location
   (b) Start the database 
 
   Alternatively, remove the lost control file location specified in the nit parameter control_files and start the database.
 
   **If all copies of the controlfile are lost due to the disk failure, then: Check for a backup controlfile. Backup controlfile is normally taken using either of the following commands:
   (a) SQL> alter database backup controlfile to '/backup/control.ctl';
    -- This would have created a binary backup of the current controlfile --
 
    -->If the backup was done in binary format as mentioned above, restore the file to the lost controlfile locations using OS copying utilities.
    --> SQL> startup mount;
    --> SQL> recover database using backup controlfile;
    --> SQL> alter database open;
 
   (b) SQL> alter database backup controlfile to trace;
    -- This would have created a readable trace file containing create controlfile script --
 
    --> Edit the trace file created (check user_dump_dest for the location) and retain the SQL commands alone. Save this to a file say cr_ctrl.sql
รจ      Run the script
 

Redo logs

In normal cases, we would not have backups of online redo log files. But the inactive logfile changes could already have been checkpointed on the datafiles and even archive log files may be available.
 
SQL> 
     ORA-00313: open failed for members of log group 1 of thread 1
     ORA-00312: online log 1 thread 1: '/ORACLE/ORADATA/H817/REDO01.LOG'
     ORA-27041: unable to open file
     OSD-04002: unable to open file
     O/S-Error: (OS 2) The system cannot find the file specified.
 
** Verify if the lost redolog file is Current or not.
     SQL> select * from v$log;
     SQL> select * from v$logfile; 
 
     --> If the lost redo log is an Inactive logfile, you can clear the logfile:
 
     SQL> alter database clear logfile GROUP 1;
 
     Alternatively, you can drop the logfile if you have atleast two other logfiles:
     SQL> alter database drop logfile group 1;
     
     --> If the logfile is the Current logfile, then do the following:
     SQL> recover database until cancel;
     SQL>alter database open resetlogs;
 
If the database is in noarchivelog mode and if ORA-1547, ORA-1194 and ORA-1110 errors occur, then you would have restore from an old backup and start the database.
 
Note that all redo log maintenance operations are done in the database mount state
    

Parameter file

This is not a major loss and can be easily restored. Options are:
1.       If there is a backup, restore the file
2.       If there is no backup, copy sample file or create a new file and add the required parameters. Ensure that the parameters db_name, control_files,vdb_block_size, compatible are set correctly
3.    If the spfile is lost, you can create it from the init parameter file

Flash Recovery using Image Copy

Flash Recovery using Image Copy


Image Copy
Oracle RMAN image copies are exact copies of the datafiles, with all the blocks—used or not. Oracle RMAN takes this image copy while the database is up and running, and the database need not be put into any special mode.
Here is how to make an Oracle RMAN image copy backup:



 
run {
   backup as copy
   database; }
 



Instant Recovery 

Image copies in the FRA become truly useful when you need an "instant recovery." Remember that these image copies are copies of the datafiles—a fact recorded in the Oracle RMAN catalog and the control file. In case of a disaster, you don't need to restore the file; you can use the copy as the principal datafile immediately.  
Here is the description of the recovery process, assuming that the USERS tablespace has been damaged: First, check the file ID (number) and name of the datafile of the tablespace. The output is shown in vertical format:





 select file_id, file_name from dba_data_files where tablespace_name = 'USERS';
FILE_ID : 4 NAME : /home/oracle/oradata/PRODB2/ users01.dbf








 RMAN> sql 'alter tablespace users offline';
sql statement: alter tablespace users offline
RMAN> switch datafile 4 to copy;
datafile 4 switched to datafile copy "/home/oracle/FRA/PRODB2/datafile/o1_mf_users_2kmqr57t_.dbf"
RMAN> recover datafile 4;
Starting recover at 26-SEP-06 using channel ORA_DISK_1 starting media recovery media recovery complete, elapsed time: 00:00:03 Finished recover at 26-SEP-06
RMAN> sql 'alter tablespace users online'; sql statement: alter tablespace users online



 
Switchback 

Even though the datafile has been quickly brought online to minimize downtime, it is now in the backup location, which may be on slower disks than what the main database is on. You may not want to run the database with the datafile at this location for long; you would typically want to move the datafile back to the original location—/home/oracle/oradata/PRODB2/—as soon as it becomes available. You can use Oracle RMAN to accomplish this. Here is a summary of the steps: 

1. Make an image copy of the datafile at the original location.
2. Take the tablespace offline.
3. Switch the datafile to the "copy" (however, in this case, the "copy" is at the original location).
4. Recover the tablespace.
5. Place the tablespace online. 

These steps are presented in Listing 4. After the switchover, you can make sure the datafile is back in its original location: 

select name from v$datafile  where file# = 4;
NAME ---------------------------------------
/home/oracle/oradata/PRODB2/users01.dbf
 
 
RMAN> backup as copy datafile 4 format '/home/oracle/oradata/PRODB2/users01.dbf';
Starting backup at 27-SEP-06 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy input datafile fno=00004 name=/home/oracle/FRA/PRODB2/datafile/o1_mf_users_2kmqr57t_.dbf output filename=/home/oracle/oradata/PRODB2/users01.dbf tag=TAG20060927T103710 recid=45 stamp=602246230 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 27-SEP-06 Starting Control File Autobackup at 27-SEP-06 piece handle=/home/oracle/FRA/PRODB2/autobackup/2006_09_27/ o1_mf_n_602246232_2ko34s42_.bkp comment=NONE Finished Control File Autobackup at 27-SEP-06 RMAN> sql 'alter tablespace users offline'; ... RMAN> switch datafile 4 to copy; datafile 4 switched to datafile copy "/home/oracle/oradata/PRODB2/users01.dbf" RMAN> recover datafile 4; ... RMAN> sql 'alter tablespace users online'; ...
In case of a failure, you save valuable time by quickly using the image copy of the datafile in the FRA, and there is no need to restore it first. The same concept can be applied to the entire database as well. If the original location of all the datafiles is damaged, you can easily switch the entire database to the copy stored in the FRA. To switch to the FRA copy, issue the following, which directs the whole database to use all the latest image copies in the FRA location as its datafiles: 
RMAN> switch database to copy;  



Wednesday, June 18, 2008

All About Explain Plan

Introduction

The EXPLAIN PLAN statement displays execution plans chosen by the Oracle optimizer for SELECT, UPDATE, INSERT, and DELETE statements. A statement's execution plan is the sequence of operations Oracle performs to run the statement.

Using V$SQL_PLAN

In addition to running the EXPLAIN PLAN command and displaying the plan, you can use the V$SQL_PLAN views to display the execution plan of a SQL statement:

 
Using Explain Plan
Steps
  • EXPLAIN PLAN FOR   SELECT last_name FROM employees;
  • SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY());

About Autotrace

  1. cd $oracle_home/rdbms/admin

  2. log into sqlplus as system

  3. run SQL> @utlxplan

  4. run SQL> create public synonym plan_table for plan_table

  5. run SQL> grant all on plan_table to public

  6. exit sqlplus and cd $oracle_home/sqlplus/admin

  7. log into sqlplus as SYS

  8. run SQL> @plustrce

  9. run SQL> grant plustrace to public

 

You can control the report by setting the AUTOTRACE system variable.
  • SET AUTOTRACE ON EXPLAIN - The AUTOTRACE report shows only the optimizer execution path. 
  • SET AUTOTRACE ON STATISTICS - The AUTOTRACE report shows only the SQL statement execution statistics.  
  • SET AUTOTRACE ON  - The AUTOTRACE report includes both the optimizer execution path and the SQL statement execution statistics.  
  • SET AUTOTRACE TRACEONLY - Like SET AUTOTRACE ON, but suppresses the printing of the user's query output, if any. 


Wednesday, June 11, 2008

How to bypass Oracle installer check

Is there a way to get Oracle10g installed on other linux not specified in the pre-requities list?

<< ./runInstaller Starting Oracle Universal Installer... Checking installer requirements... Checking operating system version: must be redhat-2.1, UnitedLinux-1.0 or redhat-3 Failed <<<< ./runInstaller -ignoreSysPrereqs