In sweet memories of my ever loving brother "kutty thambi " ARUN KUMAR

Sunday, October 31, 2010

Recover a missing/excluded datafile after re-create new control file from controlfile trace file

This is the situation in which lost all control file, and DBA accidently create control file (recreated) with old controlfile trace file backup. After recover,DBA found some datafile is missing.
Here is the steps to recover those missing database datafiles.
16:33:32 SQL> select file#,name from v$datafile;

     FILE# NAME
---------- ---------------------------------------------------
         1 /u01/app/oracle/oradata/rev1/system01.dbf
         2 /u01/app/oracle/oradata/rev1/undotbs01.dbf
         3 /u01/app/oracle/oradata/rev1/sysaux01.dbf
         4 /u01/app/oracle/oradata/rev1/users01.dbf

16:33:43 SQL> set time off;
SQL> set time off;
SQL> select file#,name from v$datafile;

     FILE# NAME
---------- ---------------------------------------------------
         1 /u01/app/oracle/oradata/rev1/system01.dbf
         2 /u01/app/oracle/oradata/rev1/undotbs01.dbf
         3 /u01/app/oracle/oradata/rev1/sysaux01.dbf
         4 /u01/app/oracle/oradata/rev1/users01.dbf

SQL> alter database backup controlfile to trace;

Database altered.

SQL> alter database backup controlfile to trace;

Database altered.

SQL> alter system switch logfile;

System altered.



SQL> alter database backup controlfile to trace;

Database altered.

SQL>

[oracle@rac1 udump]$ cp rev1_ora_6901.trc /home/oracle/Desktop/ctlnew.sql

[oracle@rac1 udump]$ pwd
/u01/app/oracle/admin/rev1/udump
[oracle@rac1 udump]$


SQL> alter tablespace users add datafile '/u01/app/oracle/oradata/rev1/users02.dbf' size 2m;

Tablespace altered.

SQL> select file#,name from v$datafile; 
     FILE# NAME
---------- ---------------------------------------------------
         1 /u01/app/oracle/oradata/rev1/system01.dbf
         2 /u01/app/oracle/oradata/rev1/undotbs01.dbf
         3 /u01/app/oracle/oradata/rev1/sysaux01.dbf
         4 /u01/app/oracle/oradata/rev1/users01.dbf
         5 /u01/app/oracle/oradata/rev1/users02.dbf

SQL>
CREATE CONTROLFILE REUSE DATABASE "REV1" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u01/app/oracle/oradata/rev1/redo01.log'  SIZE 5M,
  GROUP 2 '/u01/app/oracle/oradata/rev1/redo02.log'  SIZE 5M,
  GROUP 3 '/u01/app/oracle/oradata/rev1/redo03.log'  SIZE 5M
-- STANDBY LOGFILE
DATAFILE
  '/u01/app/oracle/oradata/rev1/system01.dbf',
  '/u01/app/oracle/oradata/rev1/undotbs01.dbf',
  '/u01/app/oracle/oradata/rev1/sysaux01.dbf',
  '/u01/app/oracle/oradata/rev1/users01.dbf'
CHARACTER SET WE8ISO8859P1
;
SQL> shu immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

[oracle@rac1 udump]$ rm -rf /u01/app/oracle/oradata/rev1/*.ctl

[oracle@rac1 udump]$ rm -rf /u01/app/oracle/oradata/rev1/*.ctl
[oracle@rac1 rev1]$ pwd
/u01/app/oracle/oradata/rev1
[oracle@rac1 rev1]$ ls -ltr
total 791480
-rw-r-----  1 oracle oinstall 104865792 Oct 31 15:44 temp01.dbf
-rw-r-----  1 oracle oinstall   5243392 Oct 31 16:30 redo02.log
-rw-r-----  1 oracle oinstall   5243392 Oct 31 16:39 redo03.log
-rw-r-----  1 oracle oinstall   2105344 Oct 31 16:53 users02.dbf
-rw-r-----  1 oracle oinstall  10493952 Oct 31 16:53 users01.dbf
-rw-r-----  1 oracle oinstall  26222592 Oct 31 16:53 undotbs01.dbf
-rw-r-----  1 oracle oinstall 503324672 Oct 31 16:53 system01.dbf
-rw-r-----  1 oracle oinstall 251666432 Oct 31 16:53 sysaux01.dbf
-rw-r-----  1 oracle oinstall   5243392 Oct 31 16:53 redo01.log
[oracle@rac1 rev1]$


SQL> startup
ORACLE instance started.

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

SQL> select status from v$instance;

STATUS
----------
STARTED

SQL> shu immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.

Total System Global Area  444596224 bytes
Fixed Size                  1219904 bytes
Variable Size             146801344 bytes
Database Buffers          293601280 bytes
Redo Buffers                2973696 bytes

SQL> @/home/oracle/Desktop/recreate_ctlfile.sql

Control file created.


SQL> recover database using backup controlfile;
ORA-00279: change 810892 generated at 10/31/2010 16:53:26 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/REV1/archivelog/2010_10_31/o1_mf_1_7_%u_.arcORA-00280: change 810892 for thread 1 is in sequence #7


Specify log: {=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: cannot open archived log
'/u01/app/oracle/flash_recovery_area/REV1/archivelog/2010_10_31/o1_mf_1_7_%u_.arc'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3


ORA-00308: cannot open archived log
'/u01/app/oracle/flash_recovery_area/REV1/archivelog/2010_10_31/o1_mf_1_7_%u_.arc'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3

SQL> recover database using backup controlfile;
ORA-00279: change 810892 generated at 10/31/2010 16:53:26 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/REV1/archivelog/2010_10_31/o1_mf_1_7_%u_.arcORA-00280: change 810892 for thread 1 is in sequence #7


Specify log: {=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/oradata/rev1/redo01.log
Log applied.
Media recovery complete.

SQL> alter database open resetlogs;

Database altered.
SQL> col name format a55
SQL> select file#,name from v$datafile;

     FILE# NAME
---------- -------------------------------------------------------
         1 /u01/app/oracle/oradata/rev1/system01.dbf
         2 /u01/app/oracle/oradata/rev1/undotbs01.dbf
         3 /u01/app/oracle/oradata/rev1/sysaux01.dbf
         4 /u01/app/oracle/oradata/rev1/users01.dbf
         5 /u01/app/oracle/product/10.2.0/db_1/dbs/MISSING00005

SQL> alter database rename file '/u01/app/oracle/product/10.2.0/db_1/dbs/MISSING00005' to '/u01/app/oracle/oradata/rev1/users02.dbf';

Database altered.

SQL> recover datafile 5;
ORA-00279: change 810892 generated at 10/31/2010 16:53:26 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/REV1/archivelog/2010_10_31/o1_mf_1_7_%u_.arcORA-00280: change 810892 for thread 1 is in sequence #7


Specify log: {=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/oradata/rev1/redo01.log ORA-00342: archived log does not have expected resetlogs SCN 805021
ORA-00334: archived log: '/u01/app/oracle/oradata/rev1/redo01.log'


SQL> recover datafile 5;
ORA-00279: change 810892 generated at 10/31/2010 16:53:26 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/REV1/archivelog/2010_10_31/o1_mf_1_7_%u_.arcORA-00280: change 810892 for thread 1 is in sequence #7


Specify log: {=suggested | filename | AUTO | CANCEL}
auto
Log applied.
Media recovery complete.
SQL> select * from v$recover_file;

no rows selected

SQL> select file#,name from v$datafile; 
     FILE# NAME
---------- -------------------------------------------------------
         1 /u01/app/oracle/oradata/rev1/system01.dbf
         2 /u01/app/oracle/oradata/rev1/undotbs01.dbf
         3 /u01/app/oracle/oradata/rev1/sysaux01.dbf
         4 /u01/app/oracle/oradata/rev1/users01.dbf
         5 /u01/app/oracle/oradata/rev1/users02.dbf

SQL> select file#,name,status from v$datafile;

     FILE# NAME                                                    STATUS
---------- ------------------------------------------------------- ----------
         1 /u01/app/oracle/oradata/rev1/system01.dbf               SYSTEM
         2 /u01/app/oracle/oradata/rev1/undotbs01.dbf              ONLINE
         3 /u01/app/oracle/oradata/rev1/sysaux01.dbf               ONLINE
         4 /u01/app/oracle/oradata/rev1/users01.dbf                ONLINE
         5 /u01/app/oracle/oradata/rev1/users02.dbf                OFFLINE

SQL>
SQL> alter database datafile 5 online;

Database altered.

SQL> alter system switch logfile;

System altered.

reference:
http://hemantoracledba.blogspot.com/2010/08/adding-datafile-that-had-been-excluded.html

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

Monday, October 25, 2010

RMAN-03002 : ORA-01119: error in creating database file ORA-27038:

this is one of the interview question
your database corrupted/lost after adding a datafile to database you are only  having the backup of database before adding the datafile, the newly added datafile is not available in the backupset , what will happen how will you recover? Is the new added datafile will be available after the restore backup command?

the answer is yes the control contains the information about the newly added datafile so RMAN creates a new datafile with the same name and location and applies logs to the datafile to recover. it is similar to sql statement alter database create datafile statement.
here is an demo.
SQL> select name from v$datafile; 
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/rev1/system01.dbf
/u01/app/oracle/oradata/rev1/undotbs01.dbf
/u01/app/oracle/oradata/rev1/sysaux01.dbf
/u01/app/oracle/oradata/rev1/users01.dbf


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

Recovery Manager: Release 10.2.0.1.0 - Production on Mon Oct 25 20:48:50 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 25-OCT-10
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=137 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
channel ORA_DISK_1: starting piece 1 at 25-OCT-10
channel ORA_DISK_1: finished piece 1 at 25-OCT-10
piece handle=/u01/app/oracle/backup/0slrc3qs_1_1 tag=TAG20101025T204929 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:05
Finished backup at 25-OCT-10

Starting backup at 25-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 25-OCT-10
channel ORA_DISK_1: finished piece 1 at 25-OCT-10
piece handle=/u01/app/oracle/backup/0tlrc3r5_1_1 tag=TAG20101025T204939 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:36
Finished backup at 25-OCT-10

Starting backup at 25-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=22 recid=113 stamp=733351877
channel ORA_DISK_1: starting piece 1 at 25-OCT-10
channel ORA_DISK_1: finished piece 1 at 25-OCT-10
piece handle=/u01/app/oracle/backup/0ulrc3u7_1_1 tag=TAG20101025T205118 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 25-OCT-10

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

RMAN>

SQL> ALTER TABLESPACE USERS ADD DATAFILE '/u01/app/oracle/oradata/rev1/users02.dbf' SIZE 2m;

Tablespace altered.

SQL> select name from v$datafile; 
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/rev1/system01.dbf
/u01/app/oracle/oradata/rev1/undotbs01.dbf
/u01/app/oracle/oradata/rev1/sysaux01.dbf
/u01/app/oracle/oradata/rev1/users01.dbf
/u01/app/oracle/oradata/rev1/users02.dbf

[oracle@rac1 ~]$ rlrman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Mon Oct 25 21:03:50 2010

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

connected to target database: REV1 (DBID=1886963043)

RMAN> restore database;

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

creating datafile fno=5 name=/u01/app/oracle/oradata/rev1/users02.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 10/25/2010 21:14:13
ORA-01119: error in creating database file '/u01/app/oracle/oradata/rev1/users02.dbf'
ORA-27038: created file already exists
Additional information: 1


SQL> ! mv /u01/app/oracle/oradata/rev1/users02.dbf /u01/app/oracle/user02.dbf

RMAN> restore database;

Starting restore at 25-OCT-10
using channel ORA_DISK_1

creating datafile fno=5 name=/u01/app/oracle/oradata/rev1/users02.dbf
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/rev1/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/rev1/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/rev1/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/rev1/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/backup/0tlrc3r5_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/backup/0tlrc3r5_1_1 tag=TAG20101025T204939
channel ORA_DISK_1: restore complete, elapsed time: 00:01:26
Finished restore at 25-OCT-10

RMAN> recover database;

Starting recover at 25-OCT-10
using channel ORA_DISK_1

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

Finished recover at 25-OCT-10

RMAN>

RMAN> sql 'alter database open';

sql statement: alter database open
RMAN> exit


Recovery Manager complete.
SQL> select status from v$instance;

STATUS
------------
OPEN

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/rev1/system01.dbf
/u01/app/oracle/oradata/rev1/undotbs01.dbf
/u01/app/oracle/oradata/rev1/sysaux01.dbf
/u01/app/oracle/oradata/rev1/users01.dbf
/u01/app/oracle/oradata/rev1/users02.dbf


hope, this will helps you.

reference:
http://forums.oracle.com/forums/thread.jspa?messageID=3687911
 
Share/Bookmark