In sweet memories of my ever loving brother "kutty thambi " ARUN KUMAR
Showing posts with label rman. Show all posts
Showing posts with label rman. Show all posts

Monday, August 8, 2011

Duplicate a database without connecting to a target database and a recovery catalog (11gR2 New Features)

Users can duplicate a database without connecting to a target database. The only requirements for this operation are a connection to a catalog and an auxiliary database. This new functionality is useful when the target database is not always available.
Users can also duplicate a database without connecting to a target database and a recovery catalog. In this case, the only requirement is that you provide a disk backup location where RMAN can find all the backups, datafile copies, archived logs, and control file copies for database duplication. This database duplication enhancement is helpful when it is not possible to connect to the target database and the recovery catalog.

here is an demo, In our example i am going to create a duplicate database with the name CLONEDB from the database DB2


1. Take backup of target database.
2. Copy the backupsets to the machine where you would like to clone the target database.
3. Create a new pfile for clone database or copy the pfile of target database and replace/edit the pfile entries for the clone database.
4. Create a password file
5. Create required folders for dump and database files.
6. Add an entry in /etc/oratab file
7. Create pfile for duplicate database
8. Add required TNS entry in tnsnames.ora file
9. startup nomount the clone/duplicate database.
10. Duplicate command in auxiliary instance.


  
SQL> select name from v$database;

NAME
--------------------------------------------------------
DB2

[oracle@node2 backupnew]$ . oraenv
ORACLE_SID = [db2] ?
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 is /u01/app/oracle
[oracle@node2 backupnew]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Aug 8 00:31:43 2011

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

connected to target database: DB2 (DBID=1922019997)

RMAN> backup as compressed backupset database format '/u01/app/oracle/backup/%d_%s_%I_%T' plus archivelog format '/u01/app/oracle/backup/%d_%s_%I_%T';

RMAN> backup archivelog all format '/u01/app/oracle/backup/%d_%s_%I_%T';

RMAN> EXIT;

[oracle@node2 backup]$ cd /u01/app/oracle/backup
[oracle@node2 backup]$ pwd
/u01/app/oracle/backup
[oracle@node2 backup]$ ls -ltr
total 463128
-rw-r----- 1 oracle dba 28600320 Aug 8 00:33 DB2_26_1922019997_20110808
-rw-r----- 1 oracle dba 265560064 Aug 8 00:35 DB2_27_1922019997_20110808
-rw-r----- 1 oracle dba 1114112 Aug 8 00:35 DB2_28_1922019997_20110808
-rw-r----- 1 oracle dba 94208 Aug 8 00:35 DB2_29_1922019997_20110808
-rw-r----- 1 oracle dba 89183232 Aug 8 00:36 DB2_30_1922019997_20110808
-rw-r----- 1 oracle dba 89189376 Aug 8 00:37 DB2_31_1922019997_20110808
******************************************************************************
copy the backups to the second server where you would like to clone the database

[oracle@node1 oracle]$ pwd
/u01/app/oracle
[oracle@node1 oracle]$ mkdir backup

[oracle@node2 backup]$ pwd
/u01/app/oracle/backup
[oracle@node2 backup]$ scp * oracle@192.168.2.101:/u01/app/oracle/backup
DB2_26_1922019997_20110808 100% 27MB 13.6MB/s 00:02
DB2_27_1922019997_20110808 100% 253MB 6.5MB/s 00:39
DB2_28_1922019997_20110808 100% 1088KB 1.1MB/s 00:00
DB2_29_1922019997_20110808 100% 92KB 92.0KB/s 00:00
DB2_30_1922019997_20110808 100% 85MB 6.5MB/s 00:13
DB2_31_1922019997_20110808 100% 85MB 14.2MB/s 00:06
[oracle@node2 backup]$

[oracle@node2 dbs]$ pwd
/u01/app/oracle/product/11.2.0/dbhome_1/dbs
[oracle@node2 dbs]$ ls | grep init
initdb2.ora
init.ora
initorcl2.ora
[oracle@node2 dbs]$ scp initdb2.ora oracle@192.168.2.101:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initclonedb.ora

edit/replace the name and directory/folder for the clone database

eg:- I have replaced/edited the pfile as below
clonedb.__db_cache_size=541065216
clonedb.__java_pool_size=4194304
clonedb.__large_pool_size=4194304
clonedb.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
clonedb.__pga_aggregate_target=260046848
clonedb.__sga_target=780140544
clonedb.__shared_io_pool_size=0
clonedb.__shared_pool_size=218103808
clonedb.__streams_pool_size=4194304
*.audit_file_dest='/u01/app/oracle/admin/clonedb/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/clonedb/control01.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='clonedb'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=4039114752
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=clonedbXDB)'
*.open_cursors=300
*.pga_aggregate_target=258998272
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=776994816
*.undo_tablespace='UNDOTBS1'
db_file_name_convert='/u01/app/oracle/db2/','/u01/app/oracle/clonedb/'
log_file_name_convert='/u01/app/oracle/db2/','/u01/app/oracle/clonedb/'
*******************************************************************************
create a password file for clonedb
*******************************************************************************
[oracle@node1 dbs]$ orapwd file=$ORACLE_HOME/dbs/orapwclonedb password=oracle

create required folders and directories for database files and dump files
[oracle@node1 clonedb]$ mkdir -p /u01/app/oracle/admin/clonedb/adump
[oracle@node1 clonedb]$ mkdir -p /u01/app/oracle/admin/clonedb/udump
[oracle@node1 clonedb]$ mkdir -p /u01/app/oracle/admin/clonedb/bdump
[oracle@node1 clonedb]$ mkdir -p /u01/app/oracle/admin/clonedb/cdump
[oracle@node1 clonedb]$ mkdir -p /u01/app/oracle/clonedb

add an entry in the /etc/oratab file
clonedb:/u01/app/oracle/product/11.2.0/dbhome_1:N

[oracle@node1 clonedb]$ . oraenv
ORACLE_SID = [RAC1] ? clonedb
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 is /u01/app/oracle
[oracle@node1 clonedb]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Mon Aug 8 01:05:39 2011

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

Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area 778387456 bytes
Fixed Size 1339344 bytes
Variable Size 222298160 bytes
Database Buffers 549453824 bytes
Redo Buffers 5296128 bytes
SQL>

[oracle@node1 clonedb]$ . oraenv
ORACLE_SID = [RAC1] ? clonedb
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 is /u01/app/oracle
[oracle@node1 clonedb]$ rman auxiliary /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Aug 8 01:06:32 2011

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

connected to auxiliary database: CLONEDB (not mounted)

RMAN> duplicate database to clonedb backup location '/u01/app/oracle/backup' nofilenamecheck;


SQL> select name from v$database;

NAME
---------
CLONEDB

SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Next log sequence to archive 1
Current log sequence 1


Monday, May 23, 2011

RMAN cloning in archive log mode

i have cloned the database SUNU in RAC2 machine to RAC1 Machine in the name DBDEMO.


****************************************************************
RAC2 MACHINE
****************************************************************
ORACLE_SID = [test] ? sunu
[oracle@rac2 ~]$ sqlplus '/as sysdba'

SQL*Plus: Release 10.2.0.1.0 - Production on Sun May 15 19:27:41 2011

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


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options

SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 5
Next log sequence to archive 7
Current log sequence 7
SQL>

[oracle@rac2 ~]$ . oraenv
ORACLE_SID = [oracle] ? sunu
[oracle@rac2 ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Sun May 15 19:34:50 2011

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

connected to target database: SUNU (DBID=555109830)

RMAN> backup full database format '/home/u01/app/backup/%d_%U.bkp' plus archivelog format '/home/u01/app/backup/%d_%U.bkp';


[oracle@rac2 backup]$ pwd
/home/u01/app/backup
[oracle@rac2 backup]$ ls -ltr
total 516356
-rw-r----- 1 oracle oinstall 2124800 May 15 19:37 SUNU_01mcdp74_1_1.bkp
-rw-r----- 1 oracle oinstall 518946816 May 15 19:37 SUNU_02mcdp76_1_1.bkp
-rw-r----- 1 oracle oinstall 7143424 May 15 19:37 SUNU_03mcdp8j_1_1.bkp
-rw-r----- 1 oracle oinstall 2560 May 15 19:37 SUNU_04mcdp8l_1_1.bkp
[oracle@rac2 backup]$



step 2:-
copy the initsunu.ora file to rac1 machine and also create a password file in rac1 machine for dbdemo database
add an entry in oratab file in rac1 machine
also move the backup files to rac1 machine to exact folder as it is in rac2(source) machine

note: make sure the folder is available in RAC1 machine
here we are taking backup in /home/u01/app/backup so now i am going to create a folder in RAC1 machine and also moving the backup from RAC2 to RAC1.
[oracle@rac2 backup]$ scp * oracle@192.168.1.1:/home/u01/app/backup/


or you can create a symbolic link for the backup location

example, in machine RAC1(the machine/host/server i dont have exact folder or exact mount point as it is in RAC2 machine(target)
do like this,

[oracle@rac2 dbs]$ cd /home/u01/app/backup/
[oracle@rac2 backup]$ pwd
/home/u01/app/backup
[oracle@rac2 backup]$ scp * oracle@192.168.1.1:/home/u01/app/test_bk/

and then create a symbolic link:
[oracle@rac1 app]$ ln -s /home/u01/app/test_bk /home/u01/app/backup

[oracle@rac1 app]$ ls
backup oracle test_bk
[oracle@rac1 app]$ cd backup/
[oracle@rac1 backup]$ ls -ltr
total 671932
-rw-r----- 1 oracle oinstall 7029760 May 22 12:35 SUNU_09mcoc44_1_1.bkp
-rw-r----- 1 oracle oinstall 97460224 May 22 12:36 SUNU_0amcoc48_1_1.bkp
-rw-r----- 1 oracle oinstall 6144 May 22 12:36 SUNU_0cmcoc7a_1_1.bkp
-rw-r----- 1 oracle oinstall 1097728 May 22 12:36 SUNU_0bmcoc78_1_1.bkp
-rw-r----- 1 oracle oinstall 39838720 May 22 12:36 SUNU_0dmcvels_1_1.bkp
-rw-r----- 1 oracle oinstall 534740992 May 22 12:38 SUNU_0emcvem5_1_1.bkp
-rw-r----- 1 oracle oinstall 27648 May 22 12:38 SUNU_0gmcvepg_1_1.bkp
-rw-r----- 1 oracle oinstall 7143424 May 22 12:38 SUNU_0fmcvepe_1_1.bkp
[oracle@rac1 backup]$

now we are going to copy the init files from RAC2 to RAC1 machine using scp , as shown below.
you can mention hostname or ipaddress in scp command

[oracle@rac2 dbs]$ scp initsunu.ora oracle@192.168.1.1:$ORACLE_HOME/dbs/
initsunu.ora 100% 1070 1.0KB/s 00:00
***********************************************************************
IN RAC1 MACHINE
***********************************************************************

i copied the initsunu.ora file to the RAC1 machine and now i am going to replace
the database name sunu by dbdemo
also,
adding the parameter log_file_name_convert and db_file_name_convert parameters to clone database with different directory structure.

dbdemo.__db_cache_size=541065216
dbdemo.__java_pool_size=4194304
dbdemo.__large_pool_size=4194304
dbdemo.__shared_pool_size=192937984
dbdemo.__streams_pool_size=0
*.audit_file_dest='/home/u01/app/oracle/admin/dbdemo/adump'
*.background_dump_dest='/home/u01/app/oracle/admin/dbdemo/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/home/u01/app/oracle/oradata/dbdemo/control01.ctl','/home/u01/app/oracle/oradata/dbdemo/control02.ctl','/home/u01/app/oracle/oradata/dbdemo/control03.ctl'
*.core_dump_dest='/home/u01/app/oracle/admin/dbdemo/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='dbdemo'
*.db_recovery_file_dest='/home/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=dbdemoXDB)'
*.job_queue_processes=10
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.pga_aggregate_target=248512512
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/home/u01/app/oracle/admin/dbdemo/udump'
db_file_name_convert=(/home/u01/app/oracle/oradata/sunu/,/home/u01/app/oracle/oradata/dbdemo/)
log_file_name_convert=(/home/u01/app/oracle/oradata/sunu/,/home/u01/app/oracle/oradata/dbdemo/)

*.sga_target=745537536


Now i am going to add an entry in the /etc/oratab file for dbdemo database

dbdemo:/home/u01/app/oracle/product/10.2.0/db_1:N


going to create required folders for the dbdemo database files

[oracle@rac1 dbdemo]$ pwd
/home/u01/app/oracle/admin/dbdemo

[oracle@rac1 dbdemo]$ ls
adump bdump cdump dpdump hdump pfile udump
[oracle@rac1 dbdemo]$

[oracle@rac1 oradata]$ pwd
/home/u01/app/oracle/oradata
[oracle@rac1 oradata]$ ls
dbdemo
[oracle@rac1 oradata]$


creating a pwd file for dbdemo database

[oracle@rac1 oradata]$ orapwd file=$ORACLE_HOME/dbs/orapwdbdemo password=oracle
bash: orapwd: command not found
[oracle@rac1 oradata]$ . oraenv
ORACLE_SID = [orcl] ? dbdemo
[oracle@rac1 oradata]$ orapwd file=$ORACLE_HOME/dbs/orapwdbdemo password=oracle
[oracle@rac1 oradata]$

now i am going to start dbdemo database in nomount mode
and then do cloning

before that we should have add the tns entry of sunu database in RAC1 machine


[oracle@rac1 backup]$ cd /home/u01/app/oracle/product/10.2.0/db_1/network/admin/
[oracle@rac1 admin]$ ls -ltr

add/check this entries available in both machines else add this entry in tnsnames.ora file of both machines.

SUNU =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = sunu)
)
)

DBDEMO =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dbdemo)
)
)
[oracle@rac1 admin]$ tnsping DBDEMO

TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 19-MAY-2011 20:31:21

Copyright (c) 1997, 2005, Oracle. All rights reserved.

Used parameter files:
/home/u01/app/oracle/product/10.2.0/db_1/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.1)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dbdemo)))
OK (0 msec)
[oracle@rac1 admin]$ tnsping SUNU

TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 19-MAY-2011 20:31:26

Copyright (c) 1997, 2005, Oracle. All rights reserved.

Used parameter files:
/home/u01/app/oracle/product/10.2.0/db_1/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.2)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = sunu)))
OK (10 msec)
[oracle@rac1 admin]$

[oracle@rac2 admin]$ tnsping DBDEMO

TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 19-MAY-2011 20:29:09

Copyright (c) 1997, 2005, Oracle. All rights reserved.

Used parameter files:
/home/u01/app/oracle/product/10.2.0/db_1/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.1)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dbdemo)))
OK (10 msec)
[oracle@rac2 admin]$ tnsping SUNU

TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 19-MAY-2011 20:29:15

Copyright (c) 1997, 2005, Oracle. All rights reserved.

Used parameter files:
/home/u01/app/oracle/product/10.2.0/db_1/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip.localdomain)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = sunu)))
OK (10 msec)
[oracle@rac2 admin]$

we are checking connectivity b/n the two machines using tnsping command.

now all the pre cloning steps finished.

now we can start the cloning in RAC1 machine.


startup nomount the DATABASE dbdemo in RAC1 machine


making/creating flash recovery area in RAC1 machine

[oracle@rac1 oracle]$ mkdir -p /home/u01/app/oracle/flash_recovery_area
[oracle@rac1 oracle]$ ls
admin flash_recovery_area oradata oraInventory product
[oracle@rac1 oracle]$ cd flash_recovery_area/
[oracle@rac1 flash_recovery_area]$ ls
[oracle@rac1 flash_recovery_area]$ mkdir dbdemo
[oracle@rac1 flash_recovery_area]$ ls
dbdemo


[oracle@rac1 dbs]$ . oraenv
ORACLE_SID = [dbdemo] ?
[oracle@rac1 dbs]$ sqlplus '/as sysdba'

SQL*Plus: Release 10.2.0.1.0 - Production on Thu May 19 20:40:50 2011

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

Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area 746586112 bytes
Fixed Size 1221636 bytes
Variable Size 201329660 bytes
Database Buffers 541065216 bytes
Redo Buffers 2969600 bytes
SQL>

[oracle@rac1 flash_recovery_area]$ . oraenv
ORACLE_SID = [ORCL1] ? dbdemo
[oracle@rac1 flash_recovery_area]$ rman target sys/oracle@SUNU auxiliary /

Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 19 20:42:06 2011

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

connected to target database: SUNU (DBID=555109830)
connected to auxiliary database: DBDEMO (not mounted)

RMAN> duplicate target database to dbdemo;

[oracle@rac1 dbdemo]$ . oraenv
ORACLE_SID = [dbdemo] ?
[oracle@rac1 dbdemo]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Thu May 19 21:20:23 2011

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


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options

SQL> select name from v$database;

NAME
---------
DBDEMO

Sunday, October 31, 2010

RMAN TSPITR DEMO

Recovery Manager (RMAN) automatic tablespace point-in-time recovery (commonly abbreviated TSPITR) enables you to quickly recover one or more tablespaces in an Oracle database to an earlier time, without affecting the state of the rest of the tablespaces and other objects in the database.for theoritical part please refer oracle documentation.

Here in this demo i am going to create and truncate a table in tablespace USERS for schema(username) RAJESH and recover truncated table TEST1 of users RAJESH schema in tablespace USERS.

We can use RMAN TSPITR in the following conditions

1. Recovering data lost after an erroneous TRUNCATE TABLE statement;
2. Recovering from logical corruption of a table;
3. Undoing the effects of an incorrect batch job or other DML statement that has affected only a subset of the database;
4. Recovering a logical schema to a point different from the rest of the physical database, when multiple schemas exist in separate tablespaces of one physical database.

SQL> select name from v$tablespace;

NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
USERS
TEMP

SQL> alter user rajesh identified by rajesh default tablespace users;

User altered.

SQL> conn rajesh/rajesh;
Connected.
SQL> create table test1(id number);

Table created.

SQL> insert into test1 values(123);

1 row created.

SQL> /

1 row created.

SQL> /

1 row created.

SQL> /

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test1;

        ID
----------
       123
       123
       123
       123

SQL>

[oracle@rac1 ~]$ . oraenv
ORACLE_SID = [cdbs1] ? rev1
[oracle@rac1 ~]$ rlrman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Sun Oct 31 15:48:18 2010

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

connected to target database: REV1 (DBID=1886963043)

RMAN> backup full database plus archivelog;


Starting backup at 31-OCT-10
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=153 devtype=DISK
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=18 recid=109 stamp=733321071
input archive log thread=1 sequence=19 recid=110 stamp=733321246
input archive log thread=1 sequence=20 recid=111 stamp=733321261
input archive log thread=1 sequence=21 recid=112 stamp=733351761
input archive log thread=1 sequence=22 recid=113 stamp=733351877
input archive log thread=1 sequence=23 recid=114 stamp=733851812
input archive log thread=1 sequence=24 recid=115 stamp=733851923
input archive log thread=1 sequence=25 recid=116 stamp=733852130
input archive log thread=1 sequence=26 recid=117 stamp=733852142
channel ORA_DISK_1: starting piece 1 at 31-OCT-10
channel ORA_DISK_1: finished piece 1 at 31-OCT-10
piece handle=/u01/app/oracle/backup/13lrrcfp_1_1 tag=TAG20101031T154911 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:05
Finished backup at 31-OCT-10

Starting backup at 31-OCT-10
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/rev1/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/rev1/sysaux01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/rev1/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/rev1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 31-OCT-10
channel ORA_DISK_1: finished piece 1 at 31-OCT-10
piece handle=/u01/app/oracle/backup/14lrrcg2_1_1 tag=TAG20101031T154920 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:36
Finished backup at 31-OCT-10

Starting backup at 31-OCT-10
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=27 recid=118 stamp=733852258
channel ORA_DISK_1: starting piece 1 at 31-OCT-10
channel ORA_DISK_1: finished piece 1 at 31-OCT-10
piece handle=/u01/app/oracle/backup/15lrrcj4_1_1 tag=TAG20101031T155059 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 31-OCT-10

Starting Control File and SPFILE Autobackup at 31-OCT-10
piece handle=/u01/app/oracle/flash_recovery_area/REV1/autobackup/2010_10_31/o1_mf_s_733852263_6dtjrkts_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 31-OCT-10

RMAN> exit


Recovery Manager complete.
[oracle@rac1 ~]$

SQL> conn sys/oracle as sysdba;
Connected.
SQL> alter system switch logfile;

System altered.

SQL> create tablespace demo datafile '/u01/app/oracle/oradata/rev1/demo01.dbf' size 2m;

Tablespace created.

SQL> create user sai identified by sai default tablespace demo;

User created.

SQL> grant connect, resource to sai;

Grant succeeded.

SQL> conn sai/sai;
Connected.
SQL> create table test2(id number);

Table created.

SQL> insert into test2 values(555);

1 row created.

SQL> /

1 row created.

SQL> /

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test2;

        ID
----------
       555
       555
       555

SQL> set time on;
15:54:48 SQL> conn rajesh/rajesh;
Connected.
15:54:57 SQL> select * from test1;

        ID
----------
       123
       123
       123
       123

15:55:15 SQL> truncate table test1;

Table truncated.

15:55:26 SQL> select * from test1;

no rows selected

15:55:32 SQL>

15:55:32 SQL> conn sys/oracle as sysdba;
Connected.
15:59:30 SQL> col name format a51;
15:59:45 SQL> col status for a10;
15:59:51 SQL> select name,status from v$datafile;

NAME                                                STATUS
--------------------------------------------------- ----------
/u01/app/oracle/oradata/rev1/system01.dbf           SYSTEM
/u01/app/oracle/oradata/rev1/undotbs01.dbf          ONLINE
/u01/app/oracle/oradata/rev1/sysaux01.dbf           ONLINE
/u01/app/oracle/oradata/rev1/users01.dbf            RECOVER
/u01/app/oracle/oradata/rev1/demo01.dbf             ONLINE


16:00:08 SQL> conn sai/sai;
Connected.
16:00:55 SQL> create table test3(id number);

Table created.

16:01:08 SQL> insert into test3 values(666);

1 row created.

16:01:22 SQL> /

1 row created.

16:01:22 SQL> commit;

Commit complete.

16:01:25 SQL> select * from test3;

        ID
----------
       666
       666

16:01:30 SQL>

[oracle@rac1 ~]$ . oraenv
ORACLE_SID = [rev1] ?
[oracle@rac1 ~]$ rlrman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Sun Oct 31 15:56:19 2010

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

connected to target database: REV1 (DBID=1886963043)

RMAN> recover tablespace USERS until time "to_date('31-OCT-2010 15:55:00','DD-MON-YYYY HH24:MI:SS')" AUXILIARY DESTINATION='/u01/app/oracle';

Starting recover at 31-OCT-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=136 devtype=DISK
RMAN-05026: WARNING: presuming following set of tablespaces applies to specified point in time

List of tablespaces expected to have UNDO segments
tablespace SYSTEM
tablespace UNDOTBS1

Creating automatic instance, with SID='huEl'

initialization parameters used for automatic instance:
db_name=REV1
compatible=10.2.0.1.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_REV1_huEl
large_pool_size=1M
shared_pool_size=110M
#No auxiliary parameter file used
db_create_file_dest=/u01/app/oracle
control_files=/u01/app/oracle/cntrl_tspitr_REV1_huEl.f


starting up automatic instance REV1

Oracle instance started

Total System Global Area     201326592 bytes

Fixed Size                     1218508 bytes
Variable Size                146802740 bytes
Database Buffers              50331648 bytes
Redo Buffers                   2973696 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  time "to_date('31-OCT-2010 15:55:00','DD-MON-YYYY HH24:MI:SS')";
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
}
executing Memory Script

executing command: SET until clause

Starting restore at 31-OCT-10
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=36 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/REV1/autobackup/2010_10_31/o1_mf_s_733852408_6dtjx0yz_.bkp
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/REV1/autobackup/2010_10_31/o1_mf_s_733852408_6dtjx0yz_.bkp tag=TAG20101031T155328
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
output filename=/u01/app/oracle/cntrl_tspitr_REV1_huEl.f
Finished restore at 31-OCT-10

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
released channel: ORA_DISK_1
released channel: ORA_AUX_DISK_1

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  time "to_date('31-OCT-2010 15:55:00','DD-MON-YYYY HH24:MI:SS')";
plsql <<<-- tspitr_2
declare
  sqlstatement       varchar2(512);
  offline_not_needed exception;
  pragma exception_init(offline_not_needed, -01539);
begin
  sqlstatement := 'alter tablespace '||  'USERS' ||' offline for recover';
  krmicd.writeMsg(6162, sqlstatement);
  krmicd.execSql(sqlstatement);
exception
  when offline_not_needed then
    null;
end; >>>;
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  4 to
 "/u01/app/oracle/oradata/rev1/users01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 4;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  4 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "USERS", "SYSTEM", "UNDOTBS1" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

sql statement: alter tablespace USERS offline for recover

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /u01/app/oracle/TSPITR_REV1_HUEL/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 31-OCT-10
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=40 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/TSPITR_REV1_HUEL/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /u01/app/oracle/TSPITR_REV1_HUEL/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/rev1/users01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/backup/14lrrcg2_1_1
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/backup/14lrrcg2_1_1 tag=TAG20101031T154920
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:17
Finished restore at 31-OCT-10

datafile 1 switched to datafile copy
input datafile copy recid=17 stamp=733852877 filename=/u01/app/oracle/TSPITR_REV1_HUEL/datafile/o1_mf_system_6dtk9896_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=18 stamp=733852877 filename=/u01/app/oracle/TSPITR_REV1_HUEL/datafile/o1_mf_undotbs1_6dtk98by_.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  4 online

Starting recover at 31-OCT-10
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 27 is already on disk as file /u01/app/oracle/flash_recovery_area/REV1/archivelog/2010_10_31/o1_mf_1_27_6dtjrbnj_.arc
archive log thread 1 sequence 28 is already on disk as file /u01/app/oracle/flash_recovery_area/REV1/archivelog/2010_10_31/o1_mf_1_28_6dtk80s9_.arc
archive log filename=/u01/app/oracle/flash_recovery_area/REV1/archivelog/2010_10_31/o1_mf_1_27_6dtjrbnj_.arc thread=1 sequence=27
archive log filename=/u01/app/oracle/flash_recovery_area/REV1/archivelog/2010_10_31/o1_mf_1_28_6dtk80s9_.arc thread=1 sequence=28
media recovery complete, elapsed time: 00:00:03
Finished recover at 31-OCT-10

database opened

contents of Memory Script:
{
# export the tablespaces in the recovery set
host 'exp userid =\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/product/10.2.0/db_1/bin/oracle\)\(ARGV0=oraclehuEl\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=huEl^'\)\)\(CONNECT_DATA=\(SID=huEl\)\)\) as sysdba\" point_in_time_recover=y tablespaces= USERS file=
tspitr_a.dmp';
# shutdown clone before import
shutdown clone immediate
# import the tablespaces in the recovery set
host 'imp userid =\"/@ as sysdba\" point_in_time_recover=y file=
tspitr_a.dmp';
# online/offline the tablespace imported
sql "alter tablespace  USERS online";
sql "alter tablespace  USERS offline";
# enable autobackups in case user does open resetlogs from RMAN after TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script


Export: Release 10.2.0.1.0 - Production on Sun Oct 31 16:02:07 2010

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


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning and OLAP options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses WE8ISO8859P1 character set (possible charset conversion)
Note: table data (rows) will not be exported

About to export Tablespace Point-in-time Recovery objects...
For tablespace USERS ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                              A
EXP-00091: Exporting questionable statistics.
. . exporting table                            NEW
EXP-00091: Exporting questionable statistics.
. . exporting table                          TEST1
. exporting referential integrity constraints
. exporting triggers
. end point-in-time recovery
Export terminated successfully with warnings.
host command complete

database closed
database dismounted
Oracle instance shut down


Import: Release 10.2.0.1.0 - Production on Sun Oct 31 16:02:54 2010

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


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning and OLAP options

Export file created by EXPORT:V10.02.01 via conventional path
About to import Tablespace Point-in-time Recovery objects...
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses WE8ISO8859P1 character set (possible charset conversion)
. importing SYS's objects into SYS
. importing SCOTT's objects into SCOTT
. . importing table                            "A"
. importing RAJESH's objects into RAJESH
. . importing table                          "NEW"
. . importing table                        "TEST1"
. importing SYS's objects into SYS
Import terminated successfully without warnings.
host command complete

sql statement: alter tablespace  USERS online

sql statement: alter tablespace  USERS offline

sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/app/oracle/cntrl_tspitr_REV1_huEl.f deleted
auxiliary instance file /u01/app/oracle/TSPITR_REV1_HUEL/datafile/o1_mf_system_6dtk9896_.dbf deleted
auxiliary instance file /u01/app/oracle/TSPITR_REV1_HUEL/datafile/o1_mf_undotbs1_6dtk98by_.dbf deleted
auxiliary instance file /u01/app/oracle/TSPITR_REV1_HUEL/datafile/o1_mf_temp_6dtkdg6g_.tmp deleted
auxiliary instance file /u01/app/oracle/TSPITR_REV1_HUEL/onlinelog/o1_mf_1_6dtkd95j_.log deleted
auxiliary instance file /u01/app/oracle/TSPITR_REV1_HUEL/onlinelog/o1_mf_2_6dtkdbmb_.log deleted
auxiliary instance file /u01/app/oracle/TSPITR_REV1_HUEL/onlinelog/o1_mf_3_6dtkdbrn_.log deleted
Finished recover at 31-OCT-10

RMAN>

16:03:06 SQL> select name,status from v$datafile;

NAME                                                STATUS
--------------------------------------------------- ----------
/u01/app/oracle/oradata/rev1/system01.dbf           SYSTEM
/u01/app/oracle/oradata/rev1/undotbs01.dbf          ONLINE
/u01/app/oracle/oradata/rev1/sysaux01.dbf           ONLINE
/u01/app/oracle/oradata/rev1/users01.dbf            OFFLINE
/u01/app/oracle/oradata/rev1/demo01.dbf             ONLINE

16:03:06 SQL> select name,status from v$datafile;

NAME                                                STATUS
--------------------------------------------------- ----------
/u01/app/oracle/oradata/rev1/system01.dbf           SYSTEM
/u01/app/oracle/oradata/rev1/undotbs01.dbf          ONLINE
/u01/app/oracle/oradata/rev1/sysaux01.dbf           ONLINE
/u01/app/oracle/oradata/rev1/users01.dbf            OFFLINE
/u01/app/oracle/oradata/rev1/demo01.dbf             ONLINE

16:03:45 SQL> conn rajesh/rajesh;
Connected.
16:05:26 SQL> select * from test1;
select * from test1
              *
ERROR at line 1:
ORA-00376: file 4 cannot be read at this time
ORA-01110: data file 4: '/u01/app/oracle/oradata/rev1/users01.dbf'


16:05:32 SQL> conn sys/oracle as sysdba;
Connected.
16:05:42 SQL> alter tablespace users online;

Tablespace altered.

16:05:52 SQL> conn rajesh/rajesh;
Connected.
16:05:58 SQL> select * from test1;

        ID
----------
       123
       123
       123
       123

16:06:05 SQL> conn sai/sai;
Connected.
16:06:11 SQL> select * from test2;

        ID
----------
       555
       555
       555

16:06:16 SQL> select * from test3;

        ID
----------
       666
       666

16:06:20 SQL> conn sys/oracle as sysdba;
Connected.
16:06:32 SQL> select name,status from v$datafile;

NAME                                                STATUS
--------------------------------------------------- ----------
/u01/app/oracle/oradata/rev1/system01.dbf           SYSTEM
/u01/app/oracle/oradata/rev1/undotbs01.dbf          ONLINE
/u01/app/oracle/oradata/rev1/sysaux01.dbf           ONLINE
/u01/app/oracle/oradata/rev1/users01.dbf            ONLINE
/u01/app/oracle/oradata/rev1/demo01.dbf             ONLINE

16:06:38 SQL>

hope, this will helps you.

reference:
http://download.oracle.com/docs/cd/B14117_01/server.101/b10734/rcmtspit.htm

Tuesday, August 31, 2010

restore the server parameter file(spfile) from RMAN backup

1.Connect to target Database with RMAN.

i)If you have lost your spfile and dont have pfile then, follow the steps to recover spfile using RMAN.

RMAN>CONNECT TARGET /

ii)If your database is not up and you don't use recovery catalog then use,
RMAN>CONNECT TARGET /
RMAN>SET DBID=3148849783

2)Start the instance with dummy parameter file.
RMAN>STARTUP FORCE NOMOUNT

Example:

3)Restore server parameter file.
To restore in default location,
RMAN> RESTORE SPFILE FROM AUTOBACKUP;

To restore in another location,
RMAN> RESTORE SPFILE TO 'new_location' FROM AUTOBACKUP;
RMAN> restore spfile to '/tmp/spfilejay.ora' from autobackup;

If you want to restore to a pfile then use,
RMAN> restore spfile to pfile '/tmp/initjay.ora';

4)Restore Spfile from control file autobackup;
RMAN> run
2> { set controlfile autobackup format for device type disk to '/u01/app/oracle/backup/JAY_%F';
3> restore spfile from autobackup;
4> }

Note after restore spfile from RMAN shutdown and startup the database
else you will receive the error message
ORA-00205: error in identifying control file, check alert log for more info


1. Restore spfile from autobackup;
RMAN> set dbid=3148849783

executing command: SET DBID

RMAN> startup force nomount;

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initjay.ora'

starting Oracle instance without parameter file for retrival of spfile
Oracle instance started

Total System Global Area 159383552 bytes

Fixed Size 1218268 bytes
Variable Size 54528292 bytes
Database Buffers 100663296 bytes
Redo Buffers 2973696 bytes

RMAN> restore spfile from autobackup;

2. Restore spfile to non-default location
RMAN> restore spfile to '/tmp/spfilejay.ora' from autobackup;

Starting restore at 31-AUG-10
using channel ORA_DISK_1

recovery area destination: /u01/app/oracle/flash_recovery_area
database name (or database unique name) used for search: JAY
channel ORA_DISK_1: no autobackups found in the recovery area
channel ORA_DISK_1: looking for autobackup on day: 20100831
channel ORA_DISK_1: autobackup found: /u01/app/oracle/backup/JAY_c-3148849783-20100831-00
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 31-AUG-10

3. If you want to restore to a pfile from restored spfile

RMAN> restore spfile to pfile '/tmp/initjay.ora';

Starting restore at 31-AUG-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=139 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: restoring SPFILE to PFILE
output filename=/tmp/initjay.ora
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/backup/JAY_c-3148849783-20100831-00
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/backup/JAY_c-3148849783-20100831-00 tag=TAG20100831T174354
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
Finished restore at 31-AUG-10

4.Restore spfile from Controlfile AutoBackup
RMAN> set dbid=3148849783

executing command: SET DBID

RMAN> startup force nomount;

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initjay.ora'

starting Oracle instance without parameter file for retrival of spfile
Oracle instance started

Total System Global Area 159383552 bytes

Fixed Size 1218268 bytes
Variable Size 54528292 bytes
Database Buffers 100663296 bytes
Redo Buffers 2973696 bytes

RMAN> run
2> { set controlfile autobackup format for device type disk to '/u01/app/oracle/backup/JAY_%F';
3> restore spfile from autobackup; 4> }

executing command: SET CONTROLFILE AUTOBACKUP FORMAT

Starting restore at 31-AUG-10
using channel ORA_DISK_1

channel ORA_DISK_1: looking for autobackup on day: 20100831
channel ORA_DISK_1: autobackup found: /u01/app/oracle/backup/JAY_c-3148849783-20100831-00
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 31-AUG-10




Reference:
Oracle® Database Backup and Recovery Basics 10g Release 2 (10.2)

ORA-00283: ORA-00314: ORA-00312: Error and solution

While trying to restore controlfile from backup , while recovery i got the error

ORA-00283: recovery session canceled due to errors
ORA-00314: log 2 of thread 1, expected sequence# 2 doesn't match 11
ORA-00312: online log 2 thread 1: '/u01/app/oracle/oradata/jay/redo02.log'

Reason:

In any case, the ArchiveLog must be backed up. Else, a RESTORE alone cannot do a RECOVER.

If your database backup did not include the ArchiveLogs, then the backup you created does not have the Redo information that Oracle must apply to the Database Backup. That is why you got the "unknown log'.
Also, if the controlfile backup is before the archivelog backup, the controlfile, even when restored, is not aware of the archivelogs in the backup created subsequent to it.
RMAN can still do a RECOVER , implicitly using the "BACKUP CONTROLFILE" and doing a rollforward but it needs to have to restore the ArchiveLog first -- and the information about which Backupset contains the ArchiveLog is not available to it. You would need to CATALOG the ArchiveLog BackupSet and then restore the archivelogs from there.
(If you use an RMAN Recovery Catalog database, then of course, the Catalog has information about the ArchiveLogs and the BackupSets containing the ArchiveLogs so RMAN queries the Catalog to identify the BackupSets and extracts the necessary ArchiveLogs from the Backupsets).

Solution:
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     11
Next log sequence to archive   13
Current log sequence           13
SQL> ! rm -rf /u01/app/oracle/oradata/jay/control*

SQL> shu immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  444596224 bytes
Fixed Size                  1219904 bytes
Variable Size             188744384 bytes
Database Buffers          251658240 bytes
Redo Buffers                2973696 bytes
ORA-00205: error in identifying control file, check alert log for more info


[oracle@rac1 ~]$ rlrman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Tue Aug 31 11:44:44 2010

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

connected to target database: jay (not mounted)

RMAN> restore controlfile from '/u01/control01.ctl';

Starting restore at 31-AUG-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK

channel ORA_DISK_1: copied control file copy
output filename=/u01/app/oracle/oradata/jay/control01.ctl
output filename=/u01/app/oracle/oradata/jay/control02.ctl
output filename=/u01/app/oracle/oradata/jay/control03.ctl
Finished restore at 31-AUG-10

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> alter database open resetlogs;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 08/31/2010 11:45:45
ORA-01139: RESETLOGS option only valid after an incomplete database recovery

RMAN> alter database open;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 08/31/2010 11:45:51
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/u01/app/oracle/oradata/jay/system01.dbf'
ORA-01207: file is more recent than control file - old control file

RMAN> recover database;

Starting recover at 31-AUG-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 08/31/2010 11:46:04
RMAN-06094: datafile 1 must be restored

RMAN> restore database;

Starting restore at 31-AUG-10
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to /u01/app/oracle/oradata/jay/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/jay/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/jay/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/backup/jay/1mlmljvq_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/backup/jay/1mlmljvq_1_1 tag=TAG20100830T185905
channel ORA_DISK_1: restore complete, elapsed time: 00:00:46
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/jay/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/backup/jay/1vlmncgc_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/backup/jay/1vlmncgc_1_1 tag=TAG20100831T110340
channel ORA_DISK_1: restore complete, elapsed time: 00:01:37
Finished restore at 31-AUG-10

RMAN> recover database;

Starting recover at 31-AUG-10
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 2 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_30/o1_mf_1_2_67qdks9h_.arc
archive log thread 1 sequence 3 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_30/o1_mf_1_3_67qfn02l_.arc
archive log thread 1 sequence 4 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_30/o1_mf_1_4_67qfn0cq_.arc
archive log thread 1 sequence 5 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_30/o1_mf_1_5_67qfmzj5_.arc
archive log thread 1 sequence 1 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_30/o1_mf_1_1_67qgpfo4_.arc
archive log thread 1 sequence 2 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_2_67s357q5_.arc
archive log thread 1 sequence 3 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_3_67s357v5_.arc
archive log thread 1 sequence 4 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_4_67s357hd_.arc
archive log thread 1 sequence 1 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_1_67s44djv_.arc
archive log thread 1 sequence 2 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_2_67s44dr5_.arc
archive log thread 1 sequence 3 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_3_67s44dwq_.arc
archive log thread 1 sequence 1 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_1_67s4jbd0_.arc
archive log thread 1 sequence 2 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_2_67s4jc79_.arc
archive log thread 1 sequence 3 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_3_67s4jgmp_.arc
archive log thread 1 sequence 4 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_4_67s4jgsl_.arc
archive log thread 1 sequence 5 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_5_67s4jmr8_.arc
archive log thread 1 sequence 6 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_6_67s4jmvt_.arc
archive log thread 1 sequence 7 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_7_67s4jrxw_.arc
archive log thread 1 sequence 8 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_8_67s4js5b_.arc
archive log thread 1 sequence 9 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_9_67s633xq_.arc
archive log thread 1 sequence 10 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_10_67s6340m_.arc
archive log thread 1 sequence 11 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_11_67s633qq_.arc
archive log thread 1 sequence 1 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_1_67s6698c_.arc
archive log thread 1 sequence 2 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_2_67s66btj_.arc
archive log thread 1 sequence 3 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_3_67s66jb0_.arc
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_30/o1_mf_1_2_67qdks9h_.arc thread=1 sequence=2
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_30/o1_mf_1_3_67qfn02l_.arc thread=1 sequence=3
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_30/o1_mf_1_4_67qfn0cq_.arc thread=1 sequence=4
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_30/o1_mf_1_5_67qfmzj5_.arc thread=1 sequence=5
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_30/o1_mf_1_1_67qgpfo4_.arc thread=1 sequence=1
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_2_67s357q5_.arc thread=1 sequence=2
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_3_67s357v5_.arc thread=1 sequence=3
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_4_67s357hd_.arc thread=1 sequence=4
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_1_67s44djv_.arc thread=1 sequence=1
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_2_67s44dr5_.arc thread=1 sequence=2
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_3_67s44dwq_.arc thread=1 sequence=3
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_1_67s4jbd0_.arc thread=1 sequence=1
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_2_67s4jc79_.arc thread=1 sequence=2
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_3_67s4jgmp_.arc thread=1 sequence=3
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_4_67s4jgsl_.arc thread=1 sequence=4
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_5_67s4jmr8_.arc thread=1 sequence=5
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_6_67s4jmvt_.arc thread=1 sequence=6
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_7_67s4jrxw_.arc thread=1 sequence=7
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_8_67s4js5b_.arc thread=1 sequence=8
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_9_67s633xq_.arc thread=1 sequence=9
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_10_67s6340m_.arc thread=1 sequence=10
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_11_67s633qq_.arc thread=1 sequence=11
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_1_67s6698c_.arc thread=1 sequence=1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 08/31/2010 11:53:18
ORA-00283: recovery session canceled due to errors
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile '/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_1_67s6698c_.arc'
ORA-00283: recovery session canceled due to errors
ORA-00314: log 2 of thread 1, expected sequence# 2 doesn't match 11
ORA-00312: online log 2 thread 1: '/u01/app/oracle/oradata/jay/redo02.log'

RMAN> exit


Recovery Manager complete.

SQL> shu immediate
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  444596224 bytes
Fixed Size                  1219904 bytes
Variable Size             188744384 bytes
Database Buffers          251658240 bytes
Redo Buffers                2973696 bytes
Database mounted.
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/u01/app/oracle/oradata/jay/system01.dbf'


SQL> alter database clear logfile '/u01/app/oracle/oradata/jay/redo02.log'; 
Database altered.


SQL> alter database open; 
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/u01/app/oracle/oradata/jay/system01.dbf'


SQL>  recover database until cancel;
ORA-00279: change 696770 generated at 08/31/2010 11:23:13 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_31/o1_mf_1_2_%u_.arc
ORA-00280: change 696770 for thread 1 is in sequence #2


Specify log: {=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.
SQL> alter database open resetlogs;

Database altered.

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     1
Next log sequence to archive   1
Current log sequence           1
SQL>

Saturday, August 28, 2010

Disaster recovery using RMAN Demo


As part of disaster recovery exercise or to test the validity of a RMAN backup,  a full restore and recovery of databases can be performed on scratch or test servers utilising the production RMAN backups which have been restored from the tape backups on these test or scratch servers.

This note will illustrate the above procedure by detailing the steps required to restore the backup of a production database 
1.  same server with same location
2.  Different server with same location

The following assumptions are made in this note:

1.The RMAN backups have been restored from tape backups to the same backup location on the test server as the production server where the backup was originally taken
2.The identical directory structure as is present on production has been created on the test server. This will apply to not only the location of the database files (data, control files, redo log files), but also to the bdump,cdump, udump and adump locations. 
3.Controlfile autobackup has been enabled. This is important.

#Overview

Restore the spfile from the autobackup
Restore the controlfile from the autobackup
Restore the data files
Recover by applying archived redo log files
Open the database with resetlogs

1.Restore the SPFILE

[oracle@rac1 backup]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Sat Aug 28 03:12:17 2010

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

connected to target database (not started)

RMAN> set dbid=3148849783 
executing command: SET DBID

RMAN> startup force nomount; 
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initjay.ora'

starting Oracle instance without parameter file for retrival of spfile
Oracle instance started

Total System Global Area     159383552 bytes

Fixed Size                     1218268 bytes
Variable Size                 54528292 bytes
Database Buffers             100663296 bytes
Redo Buffers                   2973696 bytes

RMAN> run 
2> { set controlfile autobackup format for device type disk to '/u01/app/oracle/backup/JAY_%F';
3> RESTORE SPFILE FROM AUTOBACKUP; 
4> } 
executing command: SET CONTROLFILE AUTOBACKUP FORMAT
using target database control file instead of recovery catalog

Starting restore at 28-AUG-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=36 devtype=DISK

channel ORA_DISK_1: looking for autobackup on day: 20100828
channel ORA_DISK_1: autobackup found: /u01/app/oracle/backup/JAY_c-3148849783-20100828-03
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 28-AUG-10

RMAN>
RMAN> shutdown immediate

Oracle instance shut down

2.Restore the Control File

RMAN> startup nomount

connected to target database (not started)
Oracle instance started

Total System Global Area     444596224 bytes

Fixed Size                     1219904 bytes
Variable Size                130024128 bytes
Database Buffers             310378496 bytes
Redo Buffers                   2973696 bytes

RMAN> set dbid=3148849783 
executing command: SET DBID

RMAN> run
 2> { set controlfile autobackup format for device type disk to '/u01/app/oracle/backup/JAY_%F';
3> RESTORE controlfile FROM AUTOBACKUP; 
4> }

executing command: SET CONTROLFILE AUTOBACKUP FORMAT

Starting restore at 28-AUG-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK

recovery area destination: /u01/app/oracle/flash_recovery_area
database name (or database unique name) used for search: JAY
channel ORA_DISK_1: autobackup found in the recovery area
channel ORA_DISK_1: autobackup found: /u01/app/oracle/flash_recovery_area/JAY/autobackup/2010_08_28/o1_mf_s_728189319_67jbxhyh_.bkp
channel ORA_DISK_1: control file restore from autobackup complete
output filename=/u01/app/oracle/oradata/jay/control01.ctl
output filename=/u01/app/oracle/oradata/jay/control02.ctl
output filename=/u01/app/oracle/oradata/jay/control03.ctl
Finished restore at 28-AUG-10


3.Restore the database


RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> restore database;

Starting restore at 28-AUG-10
Starting implicit crosscheck backup at 28-AUG-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
Crosschecked 8 objects
Finished implicit crosscheck backup at 28-AUG-10

Starting implicit crosscheck copy at 28-AUG-10
using channel ORA_DISK_1
Finished implicit crosscheck copy at 28-AUG-10

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/flash_recovery_area/JAY/autobackup/2010_08_28/o1_mf_s_728189319_67jbxhyh_.bkp
File Name: /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_26_67jc8po5_.arc
File Name: /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_24_67jc5rko_.arc
File Name: /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_27_67jc90og_.arc
File Name: /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_25_67jc6knx_.arc
File Name: /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_23_67jc4rpk_.arc

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/jay/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/jay/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/jay/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/jay/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/backup/JAY_0mlmei9b_1_1.bckp
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/backup/JAY_0mlmei9b_1_1.bckp tag=TAG20100828T024706channel ORA_DISK_1: restore complete, elapsed time: 00:01:47
Finished restore at 28-AUG-10

4.Recover the database

RMAN> recover database;
Starting recover at 28-AUG-10
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 22 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_22_67jbxb7n_.arc
archive log thread 1 sequence 23 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_23_67jc4rpk_.arc
archive log thread 1 sequence 24 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_24_67jc5rko_.arc
archive log thread 1 sequence 25 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_25_67jc6knx_.arc
archive log thread 1 sequence 26 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_26_67jc8po5_.arc
archive log thread 1 sequence 27 is already on disk as file /u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_27_67jc90og_.arc
archive log thread 1 sequence 28 is already on disk as file /u01/app/oracle/oradata/jay/redo03.log
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_22_67jbxb7n_.arc thread=1 sequence=22
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_23_67jc4rpk_.arc thread=1 sequence=23
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_24_67jc5rko_.arc thread=1 sequence=24
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_25_67jc6knx_.arc thread=1 sequence=25
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_26_67jc8po5_.arc thread=1 sequence=26
archive log filename=/u01/app/oracle/flash_recovery_area/JAY/archivelog/2010_08_28/o1_mf_1_27_67jc90og_.arc thread=1 sequence=27
archive log filename=/u01/app/oracle/oradata/jay/redo03.log thread=1 sequence=28media recovery complete, elapsed time: 00:00:06
Finished recover at 28-AUG-10 
 
 The recovery will fail at a point where it cannot restore any more archived redo log
files.
I had full backup so no error else it gives error , no problem just exit from rman relogin 
and open the database with resetlog.
 
RMAN> sql 'alter database open resetlogs';
sql statement: alter database open resetlogs

RMAN> exit


Recovery Manager complete.

5.Verify the database
[oracle@rac1 backup]$ sqlplus '/as sysdba'

SQL*Plus: Release 10.2.0.1.0 - Production on Sat Aug 28 03:22:35 2010

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


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning and OLAP options

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     0
Next log sequence to archive   1
Current log sequence           1
SQL> select name,dbid from v$database;

NAME            DBID
--------- ----------
JAY       3148849783

SQL>


Saturday, May 8, 2010

Block Recovery using RMAN Backup

Block media recovery recovers an individual corrupt datablock or set of datablocks within a datafile. In cases when a small number of blocks require media recovery, you can selectively restore and recover damaged blocks rather than whole datafiles.
More theoretical information read

Here , I have done block recover using rman with datafile number and corrupted block number. using this there is no need of taking datafile offline.
you can perform this with smile steps,

for experiment i have created a user KIRAN and created a table DEMO_CORRUPT, corrupting datafile of tablespace users using operating system dd command, then i have recovered the corrupted blocks using RMAN Blockrecover command.

step 1: creating user and table in that schema.
step 2: taking rman backup for that particular tablespace or datafile.
step 3: corrupting datafile block using linux command dd(testing purpose only).
step 4: recover corrupted block using rman.
step 5: check the recovered table in that schema.

SQL> CREATE USER kiran IDENTIFIED BY kiran;

User created.

SQL> GRANT DBA TO kiran;

Grant succeeded.

SQL> CONN kiran/kiran;
Connected.
SQL> CREATE TABLE demo_corrupt(id NUMBER);

Table created.

SQL> INSERT INTO  demo_corrupt VALUES (1);

1 row created.

SQL> COMMIT;

Commit complete.

SQL> COLUMN segment_name format a15
SQL>
SQL> SELECT segment_name,tablespace_name
  2  FROM dba_segments
  3  WHERE segment_name='DEMO_CORRUPT';

SEGMENT_NAME    TABLESPACE_NAME
--------------- ------------------------------
DEMO_CORRUPT    USERS

SQL>

SQL> COLUMN tablespace_name FORMAT a10
SQL> COL name FORMAT a43
SQL>
SQL> SELECT segment_name, a.tablespace_name, b.name
  2  FROM dba_segments a, v$datafile b
  3  WHERE a.header_file=b.file#
  4  AND a.segment_name='DEMO_CORRUPT'
  5  ;

SEGMENT_NAME    TABLESPACE NAME
--------------- ---------- -------------------------------------------
DEMO_CORRUPT    USERS      /u01/app/oracle/oradata/orcl/users01.dbf

SQL>

[oracle@cdbs1 ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Wed May 5 18:46:01 2010

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

connected to target database: ORCL (DBID=1245940166)
RMAN> BACKUP TABLESPACE USERS;

Starting backup at 05-MAY-10
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 05-MAY-10
channel ORA_DISK_1: finished piece 1 at 05-MAY-10
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2010_05_05/o1_mf_nnndf_TAG20100505T185519_5y2wg0gj_.bkp tag=TAG20100505T185519 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 05-MAY-10
RMAN> exit


Recovery Manager complete.


SQL> SELECT header_block from dba_segments
  2  WHERE segment_name='DEMO_CORRUPT';

HEADER_BLOCK
------------
          59

SQL>  

[oracle@cdbs1 ~]$ dd of=/u01/app/oracle/oradata/orcl/users01.dbf bs=8192 conv=notrunc seek=60 < corruption testing by rajesh
> EOF
0+1 records in
0+1 records out
[oracle@cdbs1 ~]$

SQL> CONN kiran/kiran;
Connected.
SQL> ALTER SYSTEM FLUSH BUFFER_CACHE;

System altered.

SQL> SELECT * FROM demo_corrupt;
SELECT * FROM demo_corrupt
              *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 4, block # 60)
ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'


SQL> 

oracle@cdbs1 ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Wed May 5 19:03:38 2010

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

bconnected to target database: ORCL (DBID=1245940166)

RMAN>
RMAN> BLOCKRECOVER DATAFILE 4 BLOCK 60;

Starting blockrecover at 05-MAY-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=143 devtype=DISK

channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00004
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2010_05_05/o1_mf_nnndf_TAG20100505T185519_5y2wg0gj_.bkp
channel ORA_DISK_1: restored block(s) from backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2010_05_05/o1_mf_nnndf_TAG20100505T185519_5y2wg0gj_.bkp tag=TAG20100505T185519
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:02

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

Finished blockrecover at 05-MAY-10

RMAN> 

SQL> CONN kiran/kiran;
Connected.
SQL> SELECT * FROM demo_corrupt;

        ID
----------
         1
Regards,
Rajeshkumar Govindarajan.

Complete Recovery With RMAN Backup.

BACKUP AND RECOVERY SCENARIOS Complete Recovery With RMAN Backup.
previous post i have posted a complete recovery with user-managed backup,
here we are going to see the complete recovery using rman backup.
you can perform complete recovery in the following 5 situations.
  RMAN Recovery Scenarios of complete recovery.
1. Complete Closed Database Recovery. System datafile is missing
2. Complete Open Database Recovery. Non system datafile is missing
3. Complete Open Database Recovery (when the database is initially closed). Non system datafile is missing
4. Recovery of a Datafile that has no backups.
5. Restore and Recovery of a Datafile to a different location.
1.Complete Closed Database Recovery. System Datafile is missing
   In this case complete recovery is performed, only the system datafile is missing,
   so the database can be opened without reseting the redologs.
       1.  rman target /
       2.  startup mount;
       3.  restore database or datafile file#;
       4.  recover database or datafile file#;
       5.  alter database open;
workshop1:
SQL> create user sweety identified by sweety;

User created.

SQL> grant dba to sweety;

Grant succeeded.

SQL> shu immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> host rm -rf /u01/app/oracle/oradata/testdb/system01.dbf

SQL> startup
ORACLE instance started.

Total System Global Area  444596224 bytes
Fixed Size                  1219904 bytes
Variable Size             130024128 bytes
Database Buffers          310378496 bytes
Redo Buffers                2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/testdb/system01.dbf'


SQL> shutdown immediate
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL>

[oracle@cdbs1 ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Fri May 7 23:53:51 2010

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

connected to target database (not started)

RMAN> startup mount

Oracle instance started
database mounted

Total System Global Area     444596224 bytes

Fixed Size                     1219904 bytes
Variable Size                130024128 bytes
Database Buffers             310378496 bytes
Redo Buffers                   2973696 bytes

RMAN> RESTORE DATABASE;

Starting restore at 07-MAY-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/testdb/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/testdb/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/testdb/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/testdb/users01.dbf
restoring datafile 00005 to /u03/oradata/test01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/TESTDB/backupset/2010_05_07/o1_mf_nnndf_TAG20100507T232259_5y8nvxt2_.bkp
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/TESTDB/backupset/2010_05_07/o1_mf_nnndf_TAG20100507T232259_5y8nvxt2_.bkp tag=TAG20100507T232259
channel ORA_DISK_1: restore complete, elapsed time: 00:02:52
Finished restore at 07-MAY-10

RMAN> RECOVER DATABASE;

Starting recover at 07-MAY-10
using channel ORA_DISK_1

starting media recovery


RMAN> sql 'alter database open';

sql statement: alter database open

RMAN>
SQL> conn sys/oracle as sysdba;
Connected.
SQL> col name format a45
SQL> select name , status from v$datafile;

NAME                                          STATUS
--------------------------------------------- -------
/u01/app/oracle/oradata/testdb/system01.dbf   SYSTEM
/u01/app/oracle/oradata/testdb/undotbs01.dbf  ONLINE
/u01/app/oracle/oradata/testdb/sysaux01.dbf   ONLINE
/u01/app/oracle/oradata/testdb/users01.dbf    ONLINE
/u03/oradata/test01.dbf                       ONLINE

SQL> select username from dba_users
  2  where username='SWEETY';

USERNAME
------------------------------
SWEETY
2.Complete Open Database Recovery. Non system datafile is missing,
database is up
1. rman target /
2. sql 'alter tablespace offline immediate'; 
                                or
     sql 'alter database datafile file# offline;
3. restore datafile 3;
4. recover datafile 3;
5. sql 'alter tablespace online';
                          or

      sql 'alter database datafile file# online;
workshop2:

 

SQL> conn sweety/sweety;
Connected.
SQL> create table demo(id number);

Table created.

SQL> insert into demo values(123);

1 row created.

SQL> commit;

Commit complete.

SQL> conn sys/oracle as sysdba;
Connected.
SQL> select username,default_tablespace from dba_users   2  where username='SWEETY';

USERNAME                       DEFAULT_TABLESPACE
------------------------------ ------------------------------
SWEETY                         USERS

SQL> host rm -rf /u01/app/oracle/oradata/testdb/users01.dbf

SQL> conn sweety/sweety
Connected.
SQL> alter system flush buffer_cache;

System altered.

SQL> select * from demo;
select * from demo
              *
ERROR at line 1:
ORA-01116: error in opening database file 4
ORA-01110: data file 4: '/u01/app/oracle/oradata/testdb/users01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3

[oracle@cdbs1 ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Sat May 8 01:35:09 2010

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

connected to target database: TESTDB (DBID=2501713962)

RMAN> sql 'alter database datafile 4 offline';

using target database control file instead of recovery catalog
sql statement: alter database datafile 4 offline

RMAN> restore datafile 4;

Starting restore at 08-MAY-10
using channel ORA_DISK_1
...
channel ORA_DISK_1: restore complete, elapsed time: 00:00:09
Finished restore at 08-MAY-10

RMAN> recover datafile 4;

Starting recover at 08-MAY-10
using channel ORA_DISK_1

starting media recovery
......
media recovery complete, elapsed time: 00:00:05
Finished recover at 08-MAY-10

RMAN> sql 'alter database datafile 4 online';

sql statement: alter database datafile 4 online

RMAN>exit

SQL> conn sweety/sweety;
Connected.
SQL> select * from demo;

        ID
----------
       123

SQL>


3.Complete Open Database Recovery (when the database is initially closed).
Non system datafile is missing
A user datafile is reported missing when trying to startup the database. The datafile can be turned offline and the database started up. Restore and
recovery are performed using Rman. After recovery is performed the datafile can be turned online again.
1. sqlplus /nolog
2. connect / as sysdba
3. startup mount
4. alter database datafile '' offline;
5. alter database open;
6. exit;
7. rman target /
8. restore datafile '';
9. recover datafile '';
10. sql 'alter tablespace online';



workshop3:
 

SQL> conn sweety/sweety;
Connected.

SQL> create table test ( testid number);

Table created.

SQL> insert into test values(54321);

1 row created.

SQL> commit;

Commit complete.

SQL> conn sys/oracle as sysdba;
Connected.
SQL>shu immediate
SQL> host rm -rf /u01/app/oracle/oradata/testdb/users01.dbf

SQL> startup
ORACLE instance started.

Total System Global Area  444596224 bytes
Fixed Size                  1219904 bytes
Variable Size             138412736 bytes
Database Buffers          301989888 bytes
Redo Buffers                2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/testdb/users01.dbf'

SQL> alter database datafile 4 offline;

Database altered.

SQL> alter database open;

Database altered.

[oracle@cdbs1 ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Sat May 8 01:51:45 2010

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

connected to target database: TESTDB (DBID=2501713962)

RMAN> restore datafile 4;

Starting restore at 08-MAY-10
using target database control file instead of recovery catalog
.....
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
Finished restore at 08-MAY-10

RMAN> recover datafile 4;

Starting recover at 08-MAY-10
using channel ORA_DISK_1

starting media recovery
.....
media recovery complete, elapsed time: 00:00:08
Finished recover at 08-MAY-10

RMAN> exit

SQL> alter database datafile 4 online;

Database altered.

SQL> conn sweety/sweety;
Connected.
SQL> select * from test;

    TESTID
----------
     54321

4.Recovery of a Datafile that has no backups (database is up).
If a non system datafile that was not backed up since the last backup is missing,
recovery can be performed if all archived logs since the creation
of the missing datafile exist. Since the database is up you can check the tablespace name and put it offline. The option offline immediate is used
to avoid that the update of the datafile header.
Pre requisites: All relevant archived logs.
1. sqlplus '/ as sysdba'
2. alter tablespace offline immediate;
3. alter database create datafile '/user/oradata/u01/dbtst/newdata01.dbf;
4. exit
5. rman target /
6. recover tablespace ;
7. sql 'alter tablespace online';
If the create datafile command needs to be executed to place the datafile on a
location different than the original use:
alter database create datafile '/user/oradata/u01/dbtst/newdata01.dbf' as
'/user/oradata/u02/dbtst/newdata01.dbf'

restriction: controlfile creation time must be prior than datafile creation time.
for more reference refer previous blog post.(user-managed complete recovery).
workshop4:
SQL> create user john identified by john
  2  default tablespace testing;

User created.

SQL> grant dba to john;

Grant succeeded.

SQL> conn john/john;
Connected.
SQL> create table test_tb( testid number);

Table created.

SQL> insert into test_tb values(1001);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test_tb;

    TESTID
----------
      1001

SQL> conn sys/oracle as sysdba;
Connected.
SQL> host rm -rf /u03/oradata/test01.dbf

SQL> alter system flush buffer_cache;

System altered.

SQL> conn john/john;
Connected.
SQL> select * from test_tb;
select * from test_tb
              *
ERROR at line 1:
ORA-01116: error in opening database file 5
ORA-01110: data file 5: '/u03/oradata/test01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
SQL> conn sys/oracle as sysdba;
Connected.
SQL> alter tablespace testing offline immediate;

Tablespace altered.
---if you want to create datafile in same location
SQL> alter database create datafile '/u03/oradata/test01.dbf';

Database altered.
---if you want to create a datafile in different location(disk).
SQL> alter database create datafile '/u03/oradata/test01.dbf' as '/u01/app/oracle/oradata/testdb/test01.dbf';

Database altered.
[oracle@cdbs1 ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Sat May 8 02:15:28 2010

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

connected to target database: TESTDB (DBID=2501713962)

RMAN> recover tablespace testing;

Starting recover at 08-MAY-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=145 devtype=DISK

starting media recovery

SQL> alter tablespace testing online;

Tablespace altered.

SQL> conn john/john;
Connected.
SQL> select * from test_tb;

    TESTID
----------
      1001

5.Restore and Recovery of a Datafile to a different location. Database is up.
If a non system datafile is missing and its original location not available, restore can be made to a different location and recovery performed.
Pre requisites: All relevant archived logs, complete cold or hot backup.
1. Use OS commands to restore the missing or corrupted datafile to the new
location, ie:
cp -p /user/backup/uman/user01.dbf /user/oradata/u02/dbtst/user01.dbf
2. alter tablespace offline immediate;
3. alter tablespace rename datafile
'/user/oradata/u01/dbtst/user01.dbf' to '/user/oradata/u02/dbtst/user01.dbf';
4. rman target /
5. recover tablespace ;
6. sql 'alter tablespace online';

workshop5: 

follow the same example workshop4 for workshop 5 except creating new datafile, here you have to copy the recent backup file to the new disk location and perform recovery. thats it , rest of the procedures are same.

regards,
Rajeshkumar Govindarajan.

Friday, May 7, 2010

Complete Recovery With User-managed Backup with Examples

BACKUP AND RECOVERY SCENARIOS
Complete Recovery With User-managed Backup.
you can perform complete recovery in the below 5 situations.

User Managed Recovery Scenarios of complete recovery.
   1. Complete Closed Database Recovery. System datafile is missing(with recent backups)                                                                                                   
   2. Complete Open Database Recovery. Non system datafile is missing(with backups).                                                                                                       
   3. Complete Open Database Recovery (when the database is initially closed). Non system datafile is missing(with backups)                       
  4. Recovery of a Missing Datafile that has no backups.(Disk corrupted and no backups available)
 restriction: datafile should be created after controlfile creation.(i.e,controlfile creation time is prior than datafile creation time).
you cannot recover or create datafile without backup in the following situation:
SQL> select CONTROLFILE_CREATED from v$database;
CONTROLFILE_CREATED
--------------------
07-MAY-2010 01:23:43  
SQL> select creation_time,name from v$datafile;
CREATION_TIME        NAME
-------------------- ---------------------------------------------
30-JUN-2005 19:10:11 /u01/app/oracle/oradata/testdb/system01.dbf
30-JUN-2005 19:55:01 /u01/app/oracle/oradata/testdb/undotbs01.dbf
30-JUN-2005 19:10:27 /u01/app/oracle/oradata/testdb/sysaux01.dbf
30-JUN-2005 19:10:40 /u01/app/oracle/oradata/testdb/users01.dbf 

  5. Restore and Recovery of a Datafile to a different location.(Disk corrupted having recent backup and recover the datafile in new Disk location).

  User Managed Recovery Scenarios
User managed recovery scenarios do require that the database is in archive log mode, and that backups of all datafiles and control files are made with the tablespaces set to begin backup, if the database is open while the copy is made. At the end of the copy of each tablespace it is necessaire to take it out of backup mode. Alternatively complete backups can be made with the database shutdown. Online redologs can be optionally backed up.
Files to be copied:
select name from v$datafile;
select member from v$logfile; # optional
select name from v$controlfile;
1.Complete Closed Database Recovery. System tablespace is missing
   If the system tablespace is missing or corrupted the database cannot be started up
   so a complete closed database recovery must be performed.
   Pre requisites: A closed or open database backup and archived logs.
        1. Use OS commands to restore the missing or corrupted system datafile to its original location from recent backup, ie:
           cp -p /user/backup/uman/system01.dbf  /user/oradata/u01/dbtst/system01.dbf
        2. startup mount;
        3. recover datafile 1;
        4. alter database open;
workshop1: system datafile recovery with recent backup


SQL> create user rajesh identified by rajesh;
User created.
SQL> grant dba to rajesh;
Grant succeeded.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
i manually deleted the datafile system01.dbf for testing purpose only
SQL> startup
ORACLE instance started.
Total System Global Area  444596224 bytes
Fixed Size                  1219904 bytes
Variable Size             138412736 bytes
Database Buffers          301989888 bytes
Redo Buffers                2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/testdb/system01.dbf'


SQL> shutdown immediate
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> host cp /u01/app/oracle/oradata/backup/system01.dbf /u01/app/oracle/oradata/testdb/system01.dbf
 system datafile restored from recent backup

SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 7 12:51:16 2010

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

Enter user-name: sys as sysdba
Enter password:
Connected to an idle instance.

SQL> startup mount
ORACLE instance started.

Total System Global Area  444596224 bytes
Fixed Size                  1219904 bytes
Variable Size             138412736 bytes
Database Buffers          301989888 bytes
Redo Buffers                2973696 bytes
Database mounted.
SQL> recover datafile 1;
ORA-00279: change 454383 generated at 05/07/2010 01:40:11 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_7_%u_.arc
ORA-00280: change 454383 for thread 1 is in sequence #7


Specify log: {=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 456007 generated at 05/07/2010 12:46:10 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_8_%u_.arc
ORA-00280: change 456007 for thread 1 is in sequence #8
ORA-00278: log file
'/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_7_5y7hkty0_.arc' no longer needed for this recovery
.
.
.
ORA-00279: change 456039 generated at 05/07/2010 12:46:22 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_11_%u_.arc
ORA-00280: change 456039 for thread 1 is in sequence #11
ORA-00278: log file
'/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_10_5y7hl7dr_.arc' no longer needed for this recovery


Log applied.
Media recovery complete.
SQL> alter database open;

Database altered.

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     12
Next log sequence to archive   14
Current log sequence           14
SQL> select username from dba_users
  2  where username='RAJESH';

USERNAME
------------------------------
RAJESH 

2.Complete Open Database Recovery. Non system tablespace is missing
   If a non system tablespace is missing or corrupted while the database is open,   recovery can be performed while the database remain open.
   Pre requisites: A closed or open database backup and archived logs.
        1. Use OS commands to restore the missing or corrupted datafile to its original location, ie:
           cp -p /user/backup/uman/user01.dbf /user/oradata/u01/dbtst/user01.dbf

        2. alter tablespace offline immediate;
        3. recover tablespace ;
        4. alter tablespace online;

workshop2: Non-system datafile recovery from recent backup when database is open 
SQL> ALTER USER rajesh DEFAULT TABLESPACE users;

User altered.

SQL> conn rajesh/rajesh;
Connected.
SQL> create table demo(id number);

Table created.

SQL> insert into demo values(123);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from demo;

        ID
----------
       123

SQL> conn sys/oracle as sysdba;
Connected.
SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     14
Next log sequence to archive   16
Current log sequence           16
i manually deleted the datafile users01.dbf for testing purpose only
SQL> conn rajesh/rajesh;
Connected.
SQL> alter system flush buffer_cache;

System altered.

SQL> select * from demo;
select * from demo
              *
ERROR at line 1:
ORA-00376: file 4 cannot be read at this time
ORA-01110: data file 4: '/u01/app/oracle/oradata/testdb/users01.dbf'


SQL> conn sys/oracle as sysdba;
Connected.
SQL> host cp -p /u01/app/oracle/oradata/backup/users01.dbf /u01/app/oracle/oradata/testdb/users01.dbf
restore the users01.dbf datafile from recent backup to the testdb folder

SQL> alter tablespace users offline immediate;

Tablespace altered.

SQL> recover tablespace users;
ORA-00279: change 454383 generated at 05/07/2010 01:40:11 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_7_%u_.arc
ORA-00280: change 454383 for thread 1 is in sequence #7


Specify log: {=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 456007 generated at 05/07/2010 12:46:10 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_8_%u_.arc
ORA-00280: change 456007 for thread 1 is in sequence #8
ORA-00278: log file
'/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_7_5y7hkty0_.arc' no longer needed for this recovery
.....
......
ORA-00279: change 456044 generated at 05/07/2010 12:46:28 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_13_%u_.arc
ORA-00280: change 456044 for thread 1 is in sequence #13
ORA-00278: log file
'/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_12_5y7hldl2_.arc' no longer needed for this recovery


Log applied.
Media recovery complete.
SQL> alter tablespace users online;

Tablespace altered.

SQL> conn rajesh/rajesh;
Connected.
SQL> select * from demo;

        ID
----------
       123 
3.Complete Open Database Recovery (when the database is initially closed).Non system datafile is missing
    If a non system tablespace is missing or corrupted and the database crashed, recovery can be performed after the database is open.
    Pre requisites: A closed or open database backup and archived logs.
 1.   startup; (you will get ora-1157 ora-1110 and the name of the missing datafile, the database will remain mounted)
 2.   alter database datafile3 offline; (tablespace cannot be used because the database is not open)
 3.   alter database open;
 4.   Use OS commands to restore the missing or corrupted datafile to its original location, ie:
    cp -p /user/backup/uman/user01.dbf /user/oradata/u01/dbtst/user01.dbf
 5.   recover datafile 3;
 6.   alter tablespace online;
workshop 3:Non system datafile is missing


SQL> conn sys/oracle as sysdba;
Connected.
SQL> alter system switch logfile;

System altered.

SQL> select username,default_tablespace from dba_users
  2  where username='RAJESH';

USERNAME                       DEFAULT_TABLESPACE
------------------------------ ------------------------------
RAJESH                         USERS

SQL> conn rajesh/rajesh;
Connected.
SQL> create table testtbl (id number);

Table created.

SQL> insert into testtbl values(786);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from testtbl;

        ID
----------
       786

SQL> conn sys/oracle as sysdba;
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> --manually deleting the users01.dbf datafile from testdb folder
warning:for testing purpose only
SQL> host rm -rf /u01/app/oracle/oradata/testdb/users01.dbf

SQL> startup
ORACLE instance started.

Total System Global Area  444596224 bytes
Fixed Size                  1219904 bytes
Variable Size             142607040 bytes
Database Buffers          297795584 bytes
Redo Buffers                2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/testdb/users01.dbf'


SQL> alter database datafile 4 offline;

Database altered.

SQL> alter database open;

Database altered.

SQL> host cp -p /u01/app/oracle/oradata/backup/users01.dbf /u01/app/oracle/oradata/testdb/users01.dbf
copying user01.dbf from the recent backup to the testdb folder
SQL> recover datafile 4;
ORA-00279: change 454383 generated at 05/07/2010 01:40:11 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_7_%u_.arc
ORA-00280: change 454383 for thread 1 is in sequence #7


Specify log: { =suggested | filename | AUTO | CANCEL} auto
ORA-00279: change 456007 generated at 05/07/2010 12:46:10 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_8_%u_.arc
ORA-00280: change 456007 for thread 1 is in sequence #8
ORA-00278: log file
'/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_7_5y7hkty0_.arc' no longer needed for this recovery
......
.........
ORA-00279: change 456046 generated at 05/07/2010 12:46:29 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_14_%u_.arc
ORA-00280: change 456046 for thread 1 is in sequence #14
ORA-00278: log file
'/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_13_5y7hlfbc_.arc' no longer needed for this recovery


Log applied.
Media recovery complete.
SQL> alter database datafile 4 online;

Database altered.

SQL> conn rajesh/rajesh;
Connected.
SQL> select * from testtbl;

        ID
----------
       786

4.Recovery of a Missing Datafile that has no backups (database is open). 
If a non system datafile that was not backed up since the last backup is missing,

recovery can be performed if all archived logs since the creation
of the missing datafile exist.
Pre requisites: All relevant archived logs.
1. alter tablespace offline immediate;
2. alter database create datafile '/user/oradata/u01/dbtst/newdata01.dbf';
3. recover tablespace ;
4. alter tablespace online;

If the create datafile command needs to be executed to place the datafile on a location different than the original use:
alter database create datafile '/user/oradata/u01/dbtst/newdata01.dbf' as
'/user/oradata/u02/dbtst/newdata01.dbf'

restriction: datafile should be created after controlfile creation.(i.e,controlfile creation time is prior than datafile creation time).
workshop 4: Missing Non-system Datafile having no backups
SQL> alter session set nls_date_format='DD-MON-YYYY hh24:mi:ss';

Session altered.

SQL> select controlfile_created from v$database;

CONTROLFILE_CREATED
--------------------
07-MAY-2010 16:27:22

SQL> col name format a45
SQL> select creation_time,name from v$datafile;

CREATION_TIME        NAME
-------------------- ---------------------------------------------
30-JUN-2005 19:10:11 /u01/app/oracle/oradata/testdb/system01.dbf
30-JUN-2005 19:55:01 /u01/app/oracle/oradata/testdb/undotbs01.dbf
30-JUN-2005 19:10:27 /u01/app/oracle/oradata/testdb/sysaux01.dbf
30-JUN-2005 19:10:40 /u01/app/oracle/oradata/testdb/users01.dbf
you cannot re-create the any one of the listed above datafile , without backup.
SQL> create tablespace testing datafile
  2  '/u01/app/oracle/oradata/testdb/test01.dbf' size 2m;

Tablespace created.

SQL> select creation_time,name from v$datafile;

CREATION_TIME        NAME
-------------------- ---------------------------------------------
30-JUN-2005 19:10:11 /u01/app/oracle/oradata/testdb/system01.dbf
30-JUN-2005 19:55:01 /u01/app/oracle/oradata/testdb/undotbs01.dbf
30-JUN-2005 19:10:27 /u01/app/oracle/oradata/testdb/sysaux01.dbf
30-JUN-2005 19:10:40 /u01/app/oracle/oradata/testdb/users01.dbf
07-MAY-2010 16:32:07 /u01/app/oracle/oradata/testdb/test01.dbf 
we can re-create test01.dbf file without backup.
SQL> select controlfile_created from v$database;

CONTROLFILE_CREATED
--------------------
07-MAY-2010 16:27:22

---we can recover the datafile test01.dbf without backup using
create datafile command in recovery
---in this example i am going to create a table in testing tablespace 
and deleted the test01.dbf datafile and recover it without backup and 
create datafile recovery command.

SQL> create user jay identified by jay
  2  default tablespace testing;

User created.

SQL> grant dba to jay;

Grant succeeded.

SQL> select username,default_tablespace from dba_users
  2  where username='JAY';

USERNAME                       DEFAULT_TABLESPACE
------------------------------ ------------------------------
JAY                            TESTING

SQL> conn jay/jay;
Connected.
SQL> create table demo (id number);

Table created.

SQL> insert into demo values(321);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from demo;

        ID
----------
       321

SQL> conn sys/oracle as sysdba;
Connected.
SQL> host rm -rf /u01/app/oracle/oradata/testdb/test01.dbf
---manually deleting datafile test01.dbf for testing purpose

SQL> conn jay/jay;
Connected.
SQL> select * from demo;

        ID
----------
       321

SQL> alter system flush buffer_cache;

System altered.

SQL> select * from demo;
select * from demo
*
ERROR at line 1:
ORA-01116: error in opening database file 5
ORA-01110: data file 5: '/u01/app/oracle/oradata/testdb/test01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3


SQL> alter database datafile 5 offline;

Database altered.
----TO CREATE A NEW RECOVERED DATAFILE IN SAME LOCATION.
SQL> alter database create datafile '/u01/app/oracle/oradata/testdb/test01.dbf';
Database altered.
----TO CREATE A NEW RECOVERED DATAFILE IN DIFFERENT LOCATION.
SQL> alter database create datafile '/u01/app/oracle/oradata/testdb/test01.dbf' as '/u03/oradata/test01.dbf';

Database altered.

SQL> recover datafile 5;
ORA-00279: change 454443 generated at 05/07/2010 16:32:07 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_8_%u_.arc
ORA-00280: change 454443 for thread 1 is in sequence #8


Specify log: {=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 454869 generated at 05/07/2010 16:41:38 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_9_%u_.arc
ORA-00280: change 454869 for thread 1 is in sequence #9
ORA-00278: log file
'/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_8_5y7xcbrm_.arc' no longer needed for this recovery
.....
.......
ORA-00279: change 454874 generated at 05/07/2010 16:41:45 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_11_%u_.arc
ORA-00280: change 454874 for thread 1 is in sequence #11
ORA-00278: log file
'/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_10_5y7xck8j_.arc' no longer needed for this recovery


Log applied.
Media recovery complete.
SQL> alter database datafile 5 online;

Database altered.

SQL> conn jay/jay;
Connected.
SQL> select * from demo;

        ID
----------
       321

SQL>


5.Restore and Recovery of a Datafile to a different location.
If a non system datafile is missing and its original location not available, restore can be made to a different location and recovery performed.
Pre requisites: All relevant archived logs.

1. Use OS commands to restore the missing or corrupted datafile to the new location, ie:
cp -p /user/backup/uman/user01.dbf /user/oradata/u02/dbtst/user01.dbf
2. alter tablespace offline immediate;
3. alter tablespace rename datafile
'/user/oradata/u01/dbtst/user01.dbf' to '/user/oradata/u02/dbtst/user01.dbf';
4. recover tablespace ;
5. alter tablespace online;
workshop 5:
SQL> create user lachu identified by lachu
  2  default tablespace users;

User created.

SQL> grant dba to lachu;

Grant succeeded.

SQL> conn lachu/lachu;
Connected.
SQL> create table test_tb(id number);

Table created.

SQL> insert into test_tb values(123);

1 row created.

SQL> commit;

Commit complete.

SQL> conn sys/oracle as sysdba;
Connected.
SQL> ---manually deleting users01.dbf datafile for testing purpose
SQL> host rm -rf '/u01/app/oracle/oradata/testdb/users01.dbf'

SQL> conn lachu/lachu;
Connected.
SQL> select * from tab;

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
TEST_TB                        TABLE
SQL> select * from test_tb;
select * from test_tb
              *
ERROR at line 1:
ORA-00376: file 4 cannot be read at this time
ORA-01110: data file 4: '/u01/app/oracle/oradata/testdb/users01.dbf'


SQL> conn sys/oracle as sysdba;
Connected.
SQL> alter database datafile 4 offline;

Database altered.

SQL> host cp -p /u01/app/oracle/oradata/backup/users01.dbf /u03/oradata/users01.dbf
--restore datafile user01.dbf to new disk from the recent backup of the database.

SQL> alter tablespace users rename datafile
  2  '/u01/app/oracle/oradata/testdb/users01.dbf' to '/u03/oradata/users01.dbf';
Tablespace altered.

SQL> recover datafile 4;
ORA-00279: change 454383 generated at 05/07/2010 01:40:11 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_7_%u_.arc
ORA-00280: change 454383 for thread 1 is in sequence #7


Specify log: {=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 456007 generated at 05/07/2010 12:46:10 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_8_%u_.arc
ORA-00280: change 456007 for thread 1 is in sequence #8
ORA-00278: log file
'/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_7_5y7hkty0_.arc' no longer needed for this recovery
....
......
ORA-00279: change 457480 generated at 05/07/2010 13:09:30 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_15_%u_.arc
ORA-00280: change 457480 for thread 1 is in sequence #15
ORA-00278: log file
'/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2010_05_07/o1_mf_1_14_5y7jxlvg_.arc' no longer needed for this recovery


Log applied.
Media recovery complete.
SQL> alter database datafile 4 online;

Database altered.

SQL> select name from v$datafile;

NAME
---------------------------------------------
/u01/app/oracle/oradata/testdb/system01.dbf
/u01/app/oracle/oradata/testdb/undotbs01.dbf
/u01/app/oracle/oradata/testdb/sysaux01.dbf
/u03/oradata/users01.dbf ----------restored in new location (disk)

SQL> conn lachu/lachu;
Connected.
SQL> select * from tab;

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
TEST_TB                        TABLE

SQL> select * from test_tb;

        ID
----------
       123

regards,
rajeshkumar govindarajan
free counters
 
Share/Bookmark