Вы находитесь на странице: 1из 43

Type Of Backup Cold Backup Full DB Backup

SQL Command 1 Shutdown The Database sql> shutdown normal sql> shutdown transactional sql> shutdown immediate 2 Copy The Control File, Data File and Redo File to Back cp -p cp -p cp -p cp -p cp -p cp -p cp -p cp -p cp -p cp -p cp -p cp -p cp -p cp -p 3 Start The Database sql> startup

DBA Survival Sheet

Hot Backup

Tablespace Backups

1 List the Tablespace to be Backed Up SQL> select tablespace_name from dba_tablespaces; SQL> select tablespace_name, file_name from DBA_DATA 2 Check The Status Of Tablespace SQL> select file#,status from v$backup; 3 Change the All Tablespace to Backup Mode alter tablespace alter tablespace alter tablespace alter tablespace alter tablespace alter tablespace alter tablespace 4 Again Check The Status Of Tablespace After Begin B SQL> select file#,status from v$backup; 5 Copy All the Tablespace datafile to Backup Location cp -p cp -p cp -p cp -p cp -p cp -p cp -p 6 Change the All Tablespace to END Backup Mode alter tablespace alter tablespace alter tablespace alter tablespace alter tablespace alter tablespace alter tablespace

7 Run The Following cmd to archive the redo being gen sql> alter system archive log current; Control File Backup Binary Backup Trace Backup 1

sql> alter database backup controlfile to '/u02/bkp/cf.bak' REU

2 sql> alter database backup controlfile to trace;

Identifying DB Datafiles Location related Infomartion.


S.no. 1 2 3 4 5 6 File Name Datafiles Controlfiles Redo Files Temp File SPFILE Archive log SQL> SQL> SQL> SQL> SQL> SQL>

Command select file_name from dba_data_files; select name from v$controlfile; select member from v$logfile; select file_name from dba_temp_files; show parameter spfile; show parameter archive;

7 SUM of ALL DATA FILES 8 SUM of ALL REDO LOGS

SQL> select sum(bytes)/1024/1024 from dba_data_files; SQL> select sum(bytes)/1024/1024 from v$log;

SQL Command own The Database utdown normal utdown transactional utdown immediate he Control File, Data File and Redo File to Backup Location /u01/oradata/orcl/control01.ctl /u02/bkp /u01/oradata/orcl/control02.ctl /u02/bkp /u01/oradata/orcl/control03.ctl /u02/bkp /u01/oradata/orcl/system01.dbf /u02/bkp /u01/oradata/orcl/undotbs01.dbf /u02/bkp /u01/oradata/orcl/drsys01.dbf /u02/bkp /u01/oradata/orcl/indx01.dbf /u02/bkp /u01/oradata/orcl/tools01.dbf /u02/bkp /u01/oradata/orcl/users01.dbf /u02/bkp /u01/oradata/orcl/xdb01.dbf /u02/bkp /u01/oradata/orcl/redo01.log /u02/bkp /u01/oradata/orcl/redo02.log /u02/bkp /u01/oradata/orcl/redo03.log /u02/bkp /u01/oradata/orcl/temp01.dbf /u02/bkp he Database

DBA Survival Sheet

Description Shutdown the database from either of the comma The database is never shutdown using SHUTDOW

Make a script to copy the db files to backup locati

Start the database from either of the command

e Tablespace to be Backed Up elect tablespace_name from dba_tablespaces; elect tablespace_name, file_name from DBA_DATA_FILES; The Status Of Tablespace elect file#,status from v$backup; e the All Tablespace to Backup Mode SYSTEM begin backup; UNDOTBS1 begin backup; DRSYS begin backup; INDX begin backup; TOOLS begin backup; USERS begin backup; XDB begin backup; Check The Status Of Tablespace After Begin Backup Mode elect file#,status from v$backup; ll the Tablespace datafile to Backup Location /u01/oradata/orcl/system01.dbf /u02/bkp /u01/oradata/orcl/undotbs01.dbf /u02/bkp /u01/oradata/orcl/drsys01.dbf /u02/bkp /u01/oradata/orcl/indx01.dbf /u02/bkp /u01/oradata/orcl/tools01.dbf /u02/bkp /u01/oradata/orcl/users01.dbf /u02/bkp /u01/oradata/orcl/xdb01.dbf /u02/bkp e the All Tablespace to END Backup Mode SYSTEM end backup; UNDOTBS1 end backup; DRSYS end backup; INDX end backup; TOOLS end backup; USERS end backup; XDB end backup;

10g

ALTER DATABASE BEGIN BACKUP

ALTER DATABASE BEGIN BACKUP

e Following cmd to archive the redo being generated while Hotbackup

er system archive log current;

SQL>alter system switch logfile;

er database backup controlfile to '/u02/bkp/cf.bak' REUSE;

er database backup controlfile to trace;

This will create a controlfile sql script under USER

on related Infomartion.

Command elect file_name from dba_data_files; elect name from v$controlfile; elect member from v$logfile; elect file_name from dba_temp_files; how parameter spfile; how parameter archive;

Description

select sum(bytes)/1024/1024 from dba_data_files; elect sum(bytes)/1024/1024 from v$log;

This gives the SUM of all datafiles in MB This gives the SUM of all RDO Log Files in MB

om either of the command tdown using SHUTDOWN ABORT

db files to backup location

ther of the command

SE BEGIN BACKUP

SE BEGIN BACKUP

em switch logfile;

e sql script under USER_DUMP_DEST location

atafiles in MB DO Log Files in MB

Database Mode NOARCHIVELOG

Loss of Non-system datafile System datafile Datafile with no backup One Controlfile

All Controlfiles

Online Online Online Online ARCHIVELOG

Redologs Redologs Redologs Redologs

(One Member) (All ACTIVE MEMBERS) (All INACTIVE MEMBERS) (All CURRENT MEMBERS)

Non-system datafile

System datafile

VVVV IMP

Datafile with no backup

One Controlfile Lost

All Controlfiles lost

VV IMP

ONLINE REDO LOGS One member lost

ALL ACTIVE MEMBERS LOST ALL INACTIVE MEMBERS LOST

ALL CURRENT MEMBERS LOST

DBA Survival Sheet


Recovery Requirements Backup Available Recovery Type

Binary / Trace backup

Binary backup

Trace backup

No backup

Open Database Complete Recovery

Closed/Open Backup+archivelogs

Closed/Open

Closed Database Complete Recovery

All archivelogs since file addition/creation Closed/Open

Binary/Trace backup

Binary backup

Trace backup

No backup

Clear and archived or unarchived logfile group

9i 10G

Gives Error

l Sheet
Recovery Steps Restore the last consistent backup (Closed/Cold database backup) Restore the last consistent backup (Closed/Cold database backup) Restore the last consistent backup (Closed/Cold database backup) SQL> SHUTDOWN IMMEDIATE Copy the available controlfile to lost controlfile location SQL> STARTUP SQL> SHUTDOWN ABORT Restore the binary backup of controlfile to controlfile locations. SQL> STARTUP MOUNT SQL> RECOVER DATABASE UNTIL CANCEL USING BACKUP CONTROLFILE: SQL> ALTER DATABASE OPEN RESETLOGS: SQL> SHUTDOWN ABORT SQL> STARTUP NOMOUNT Run the create controlfile script to create a new controlfile SQL> RECOEVER DATABASE UNTIL CANCEL USING BACKUP CONTROLFILE: SQL> ALTER DATABASE OPEN RESETLOGS: SQL> SHUTDOWN ABORT CREATE A CONTROLFILE SCRIPT MANUALLY SQL> STARTUP NOMOUNT Run the create controlfile script to create a new controlfile SQL> RECOEVER DATABASE UNTIL CANCEL USING BACKUP CONTROLFILE: SQL> ALTER DATABASE OPEN RESETLOGS:

We can take only Closed data

What will happen to database

As a DBA, what will be your r Database would not shutdown

SQL> ALTER DATABASE DATAFILE <DATAFILE NO/DATAFILE NAME> OFFLINE; Restore the lost datafile from backup using copy command SQL> RECOVER DATAFILE <DATAFILE NO/DATAFILE NAME>; SQL> ALTER DATABASE DATAFILE <DATAFILE NO/DATAFILE NAME> ONLINE; SQL> ALTER DATABASE OPEN; SQL> SHUTDOWN ABORT; Restore the lost system datafile from backup using copy command SQL> STARTUP MOUNT; SQL> RECOVER DATAFILE <DATAFILE NO/DATAFILE NAME>; SQL> ALTER DATABASE OPEN; SQL> SQL> check SQL> SHUTDOWN IMMEDIATE; STARTUP MOUNT; the alert log for required datafile name and number. Alter database create datafile '/u01/oradata/orcl/arun01.dbf';

Check the path and default si

SQL> SQL> check SQL> SQL>

recover datafile 9/<datafile name>; alter database open the deleted datafile tablespace status. it might be OFFLINE select status,file# from v$datafile; Alter tablespace <arun> online;

SQL> SHUTDOWN IMMEDIATE Copy the available controlfile to lost controlfile SQL> STARTUP SQL> SHUTDOWN ABORT SQL> STARTUP NOMOUNT Restore the binary backup of controlfile to controlfile locations. SQL> RECOEVER DATABASE UNTIL CANCEL USING BACKUP CONTROLFILE: SQL> ALTER DATABASE OPEN RESETLOGS: SQL> SHUTDOWN ABORT SQL> STARTUP NOMOUNT Run the create controlfile script to create a new controlfile SQL> RECOEVER DATABASE UNTIL CANCEL USING BACKUP CONTROLFILE: SQL> ALTER DATABASE OPEN RESETLOGS: SQL> SHUTDOWN ABORT CREATE A CONTROLFILE SCRIPT MANUALLY SQL> STARTUP NOMOUNT Run the create controlfile script to create a new controlfile SQL> RECOEVER DATABASE UNTIL CANCEL USING BACKUP CONTROLFILE: SQL> ALTER DATABASE OPEN RESETLOGS: Shutdown the database Copy the available member over lost member startup the database Check the alert Log for lost group sql> select * from v$log; sql> shut abort; sql> startup mount; SQL> alter database clear logfile unarchived group 2; SQL> alter database clear unarchived logfile group 2; SQL> alter database open;

To check the error To check the Redo Log File ON Shut down the database Starttup the database in Mou This will run in oracle 9i "logf This will run in oracle 10 G, h opent the database

Check the BDUMP Alert Log sql> select * from v$log; sql> shut abort; sql> startup mount; SQL> alter database clear unarchived logfile group 2; SQL> recover database until cancel; SQL> alter database open resetlogs;

To check the error To check the Redo Log File ON Shut down the database Starttup the database in Mou For CURRENT Logfile alter dat So we have to recover incomp Open the database with Rese

We can take only Closed database backups.

What will happen to database?

Nothing will happen to database, the reaosn being, all the controlfiles have t U will get an alert that one of the controlfile is not vaialable

As a DBA, what will be your recovery strategy? Database would not shutdown with immediate option because oracle will not do checkpinting of controlfile

Check the path and default size for deteted datafile

To check the error To check the Redo Log File ONLINE STATUS and Group Number Shut down the database Starttup the database in Mount Mode This will run in oracle 9i "logfile" keyword is use here. This will run in oracle 10 G, here "logfile" keywordis not used. opent the database

To check the error To check the Redo Log File ONLINE STATUS and Group Number Shut down the database Starttup the database in Mount Mode For CURRENT Logfile alter databae clear command will not run and gives error. So we have to recover incomplete database with UNTIL CANCEL option. Open the database with ResetLog option.

being, all the controlfiles have the same infoand if one of the controlfile is unavaialbale, oracle will read databa from other s not vaialable

ng of controlfile

cle will read databa from other controlfiles;

DBA Surviva
S.No Loss of Recovery Requirements RMAN RECOVERY (Archive Log Mode is Must) Data File Non-system Datafile

System Datafile

Datafile With No Backup

Control File

One Controlfile Lost

All Controlfiles Lost

Binary backup

Trace backup

Redo File Online Redo Logs

STATUS INACTIVE /ACTIVE

CURRENT

DBA Survival Sheet


Recovery Steps

SQL> select * from v$recover_file; SQL> select file#,status from v$datafile; RMAN> ALTER DATABASE DATAFILE OFFLINE RMAN> RESTORE DATAFILE RMAN> RECOVER DATAFILE RMAN> ALTER DATABASE DATAFILE ONLINE SQL> select * from v$recover_file; SQL> select file#,status from v$datafile; RMAN> SHUTDOWN ABORT RMAN> STARTUP MOUNT RMAN> RESTORE DATAFILE 1; RMAN> RECOVER DATAFILE 1; RMAN> ALTER DATABASE OPEN;

SQL> SHUTDOWN IMMEDIATE Copy the available controlfile to lost controlfile location SQL> STARTUP

SQL> SHUTDOWN ABORT SQL> STARTUP NOMOUNT RMAN> RESTORE CONTROLFILE FROM '<path>/<bkp file>'; RMAN> RECOEVER DATABASE UNTIL CANCEL USING BACKUP CONTROLFILE: SQL> ALTER DATABASE OPEN RESETLOGS: SQL> SHUTDOWN ABORT SQL> STARTUP NOMOUNT Run the create controlfile script to create a new controlfile SQL> RECOEVER DATABASE UNTIL CANCEL USING BACKUP CONTROLFILE: SQL> ALTER DATABASE OPEN RESETLOGS:

9i 10G

Check the BDUMP Alert Log sql> select * from v$log; sql> shut abort; sql> startup mount; SQL> alter database clear logfile unarchived group 2; SQL> alter database clear unarchived logfile group 2; SQL> alter database open; Check the BDUMP Alert Log

sql> select * from v$log; sql> shut abort; sql> startup mount; Gives Error SQL> alter database clear unarchived logfile group 2; SQL> recover database until cancel; SQL> alter database open resetlogs;

Description

To To To To To To

Check the list of recoverable file. check the status of all datafiles. take the recoverable datafile in OFFLINE mode. restore the datafile , Write the Datafile Number. recover the datafile , Write the Datafile Number. put back the datafile in ONLINE mode from OFFLINE.

To Check the list of recoverable file. To check the status of all datafiles. We can't take SYSTEM Tablespace OFFLINE and cannot shut the database in normal mode so we ABORT the da

Copy the controlfile from multiplexed location to the lost location

This will restore the controlfile available in the given path and then use recover database until cancel comman

Copy the CREATE controlfile script having RESETLOG option from trace backup file and run it on sql prompt

To check the error To check the Redo Log File ONLINE STATUS and Group Number Shut down the database Starttup the database in Mount Mode This will run in oracle 9i "logfile" keyword is use here. This will run in oracle 10 G, here "logfile" keywordis not used. opent the database To check the error

To check the Redo Log File ONLINE STATUS and Group Number Shut down the database Starttup the database in Mount Mode For CURRENT Logfile alter databae clear command will not run and gives error. So we have to recover incomplete database with UNTIL CANCEL option. Open the database with ResetLog option.

rmal mode so we ABORT the database

database until cancel command

file and run it on sql prompt

Database Type Enabling Archivelog Mode

Steps To Enable/Disable The Archivelog Mode SQL> SELECT LOG_MODE FROM SYS.V$DATABASE; SQL> show parameter spfile; SQL> show parameter dest_1 SQL> show parameter start SQL> show parameter format;

DBA Survival Sheet

SQL> alter system set log_archive_start=true scope=spfile; SQL> alter system set log_archive_format='orcl_%t_%s.arc' scope=sp SQL> alter system set log_archive_dest='/u02/arch' scope=spfile; SQL> SQL> SQL> SQL> SHUTDOWN IMMEDIATE; STARTUP MOUNT; ALTER DATABASE ARCHIVELOG; ALTER DATABASE OPEN;

SQL> select DEST_NAME,STATUS,DESTINATION from V$ARCHIVE_DES Disabling Archivelog Mode SQL> ALTER DATABASE No ARCHIVELOG;

Log_ARCHIVE_FORMAT

orcl_%t_%s.arc orcl %t %s Database Name Thread No. Sequence Number For Single instnace DB - 1 Thread RAC (2 Node) - 2 Thread RAC (3 Node) - 3 Thread

orcl_%_%s_%r %r Resetelogs Identifier

The Archivelog Mode SYS.V$DATABASE;

BA Survival Sheet

Description To check Arch mode is on or off DB is running on Spfile or Pfile To check Log Arch Dest To Check Log Arch Start parameter value To Check the File Format

e_start=true scope=spfile; e_format='orcl_%t_%s.arc' scope=spfile; e_dest='/u02/arch' scope=spfile;

10g SQL> alter system set log_archive_format='orcl_%t_%s.arc' scope SQL> alter system set log_archive_dest='/u02/arch' scope=spfile;

,DESTINATION from V$ARCHIVE_DEST;

DB

For Single instnace DB - 1 Thread RAC (2 Node) - 2 Thread RAC (3 Node) - 3 Thread DB

1 2 3 4 5

DB 1 2 3 4 Opened with resetlogs OR DB DB 1 DB (OR)

1 2 3 4 1 2 3

%r

1 1 1 1 2 3 2 3

e_format='orcl_%t_%s.arc' scope=spfile; e_dest='/u02/arch' scope=spfile;

Backup Available Cold Online Redologs backed Up

Online Redologs not backed Up

Hot

RMAN Cloning DB using Catalog Full db backup

*.control_files='/u02/oradata/orclnw/control01.ctl','/u02/oradata *.core_dump_dest='/u01/app/oracle/admin/orclnw/cdump' *.db_name='orclnw' *.instance_name='orclnw' *.log_archive_dest='/u02/arch1' *.user_dump_dest='/u01/app/oracle/admin/orclnw/udump' *.db_file_name_convert=('/u01/oradata/orcl/','/u02/oradata/orcl *.log_file_name_convert=('/u01/oradata/orcl/','/u02/oradata/orc

edit the tnsnames.ora file create new SID entry "orclnw' create the directory structure for db file, control file, log file and a create the directory structure for bdump,udump.cdump. On Target Server $ export ORACLE_SID=orclnw sql> startup nomount; Connect to auxiliary (target) database (orclnw)

RMAN> connect auxiliary / Connect to Source database (orclnw) RMAN> connect target sys/sys123@orcl Connect to catalog database RMAN> connect catalog rmancat/rmancat@rman RMAN> duplicate target database to orclnw;

DBA Su
SQL Command On Different Server FTP/SCP init.ora and pwd file to the server where cloning is to be done. RESTORE THE COLD BACKUP (CF,DF and OR) to the new location. $ export ORACLE_SID=<ORACLE_SID> SQL> STARTUP RESTORE THE COLD BACKUP (CF,DF and OR) $ export ORACLE_SID=<ORACLE_SID> SQL> STARTUP MOUNT; SQL> ALTER DATABASE OPEN RESETLOGS;

With same database name RESTORE THE HOT BACKUP of DATAFILES CREATE CONTROLFILE SCRIPT MANUALLY using trace from production (database to be cloned) RUN CREATE CONTROLFILE SCRIPT TO CREATE THE CONTROLFILE on production and extract controlfile script SQL> STARTUP NOMOUNT SQL> @ctl.sql The above script will create controlfiles and mount the database SQL> RECOVER DATABASE UNTIL CANCEL/CHANGE/TIME USING BACKUP CONTROLFILE (incomplete recovery The recovery will ask for archivelogs. Apply some archivelogs and do a CANCEL SQL> ALTER DATABASE OPEN RESETLOGS (Opens the database with resetlogs after incomplete recovery

Source DB - orcl and Target DB - orclnw Create directories for controlfiles,datafiles and online redologs. Copy init<SID>.ora from source server to target server(where db is to be cloned) Copy and rename the password file on target server. Change the necessary parameters in init<SID>.ora *.background_dump_dest='/u01/app/oracle/admin/orclnw/bdump' *.control_files='/u02/oradata/orclnw/control01.ctl','/u02/oradata/orclnw/control02.ctl','/u02/oradata/orclnw/c *.core_dump_dest='/u01/app/oracle/admin/orclnw/cdump' *.db_name='orclnw' *.instance_name='orclnw' *.log_archive_dest='/u02/arch1' *.user_dump_dest='/u01/app/oracle/admin/orclnw/udump' *.db_file_name_convert=('/u01/oradata/orcl/','/u02/oradata/orclnw/') *.log_file_name_convert=('/u01/oradata/orcl/','/u02/oradata/orclnw/') edit the tnsnames.ora file create new SID entry "orclnw' create the directory structure for db file, control file, log file and archive location. create the directory structure for bdump,udump.cdump. On Target Server $ export ORACLE_SID=orclnw sql> startup nomount; Connect to auxiliary (target) database (orclnw)

RMAN> connect auxiliary / Connect to Source database (orclnw) RMAN> connect target sys/sys123@orcl Connect to catalog database RMAN> connect catalog rmancat/rmancat@rman RMAN> duplicate target database to orclnw;

DBA Survival Sheet


On Same Server (ORACLE_SID should be different) Copy init.ora and pwd file to the server where cloning is to be done. Modify the init.ora parameters (controlfile,bdump,cdump,udump,adump,archive_dest etc)

Resetlogs is required in this case just to create new resetlogs With different database name

Change REUSE -> SET, OLD DB_NAME -> NEW DB_NAME in controlfile

(incomplete recovery)

omplete recovery

u02/oradata/orclnw/control03.ctl'

Description

Database Mode Enabling Flashback RVWR BG Process is used in Flashback Database

Steps To Configure Flashback Database Make sure that the database is Archivelog Mode SQL> select log_mode from v$database;

DBA Survival Sheet

Configure the Recovery Area SQL> show parameter db_recovery SQL> alter system set db_recovery_file_dest='/u01/app/oracle/flash_r SQL> alter system set db_recovery_file_dest_size=600M; Start the database in Mount Mode SQL> shutdown immediate; SQL> startup mount; SQL> alter system set db_flashback_retention_target=60; SQL> alter database flashback on; SQL> alter database open;

SQL> select flashback_on from v$database; SQL> show parameter flashback; SQL> select * from v$flashback_database_log; SQL> select current_scn,scn_to_timestamp(current_scn) from v$data SQL> ALTER DATABASE FLASHBACK OFF; Flashback Database Recover From Flashback Log RMAN SQL

RMAN> FLASHBACK DATABASE TO TIME = TO_DATE (06/25/03 12:00: SQL> FLASHBACK DATABASE TO TIMESTAMP to_timestamp('2009-09-2 SQL> FLASHBACK DATABASE TO SCN 76239; SQL> ALTER DATABASE RESETLOGS;

Flashback Table Recover From RECYCLE BIN

SQL> SQL> SQL> SQL>

select current_scn,scn_to_timestamp(current_scn) from v$datab drop table arun; select * from user_recyclebin; flashback table arun to before drop;

SQL> select count (*) from table as of sCN <11111>; SQL> create table arunnew as select * from arun as of scn <11111>;

shback Database

ival Sheet

Discription

t='/u01/app/oracle/flash_recovery_area; t_size=600M;

on_target=60;

60 Mins

To Enable the Flashback To check the flashback status To Know the Flashback retention target To know the Current Timestamp and SCN number To Disable the Flashback

(current_scn) from v$database;

_DATE (06/25/03 12:00:00,MM/DD/YY HH:MI:SS); to_timestamp('2009-09-20 04:36:00','YYYY-MM-DD HH24:MI:SS'); Must issue the RESETLOGS command after flashback database.

(current_scn) from v$database;

<11111>; arun as of scn <11111>;

To count the rows before last SCN transation To Create a new table before last SCN transation

alter alter alter alter alter alter

tablespace tablespace tablespace tablespace tablespace tablespace

SYSTEM begin UNDOTBS1begin EXAMPLE begin INDX begin TOOLS begin USERS begin

backup; backup; backup; backup; backup; backup;