Wednesday, January 10, 2018

Recovery of a dropped tablespace

Recovery of a dropped tablespace

To recover from a case of a dropped tablespace, the Tablespace Point In Time Recovery (TSPITR) method cannot be used.

When you drop a tablespace, the controlfile will then no longer have any records of the tablespace which has been dropped. Attempts to use the RMAN RECOVER TABLESPACE command will return the RMAN error RMAN-06019 – “could not translate tablespace name” as shown below.


SQL> drop tablespace rman10 including contents and datafiles;

Tablespace dropped.

testdb:/u01/oracle/diag/rdbms/apex/apex/trace> rman target /

Recovery Manager: Release 10.2.0.4.0 - Production on Mon Jan 10 11:53:58 2009

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

connected to target database: TESTDB (DBID=2469552796)

RMAN> restore tablespace rman10;

Starting restore at 10-JAN-18
using target database control file instead of recovery catalog
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: sid=141 devtype=SBT_TAPE
channel ORA_SBT_TAPE_1: Data Protection for Oracle: version 5.5.1.0
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=140 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 10/01/2018 11:54:11
RMAN-20202: tablespace not found in the recovery catalog

So to recover from a dropped tablespace, we have two options:

1)  Do a point in time recovery of the whole database until the time the tablespace was dropped.
2)  Create a clone of the database from a valid backup, export the required tables from the tablespace which has been dropped, recreate the tablespace and then import the tables from the clone.

The first option will require an outage of the entire database and the entire database will be rolled back in tine in order to recover the tablespace.

Let us examine the first option using the example shown below:

In this example, CONTROLFILE AUTOBACKUP has been turned on and Flashback has been enabled for the database.
With Flashback enabled, the db_recovery_file_dest will have a sub-directory ‘autobackup’ as shown below for each day

We will Take full Backup.

backup database plus archivelog;

Starting backup at 10-JAN-18
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=28 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=24 STAMP=965056892
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2018_01_10/o1_mf_annnn_TAG20180110T152133_f5crk5bz_.bkp tag=TAG20180110T152133 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=13 RECID=15 STAMP=965046171
input archived log thread=1 sequence=14 RECID=22 STAMP=965047189
input archived log thread=1 sequence=15 RECID=23 STAMP=965047189
input archived log thread=1 sequence=16 RECID=21 STAMP=965047189
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2018_01_10/o1_mf_annnn_TAG20180110T152133_f5crk6g0_.bkp tag=TAG20180110T152133 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JAN-18

Starting backup at 10-JAN-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/drtbs1.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/orcl/drtbs2.
dbf
input datafile file number=00008 name=/u01/app/oracle/oradata/orcl/arul1.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2018_01_10/o1_mf_nnndf_TAG20180110T152135_f5crk7pb_.bkp tag=TAG20180110T152135 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
Finished backup at 10-JAN-18

Starting backup at 10-JAN-18
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=2 RECID=25 STAMP=965056950
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2018_01_10/o1_mf_annnn_TAG20180110T152230_f5crlyvl_.bkp tag=TAG20180110T152230 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JAN-18

Starting Control File and SPFILE Autobackup at 10-JAN-18
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/autobackup/2018_01_10/o1_mf_s_965056952_f5crm0dh_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 10-JAN-18


ttestdb:/u02/oradata/testdb/TESTDB/autobackup/2018_01_10> ls -lrt
total 63040
-rw-r-----    1 oracle   dba         6455296 Jan  10  10:22 o1_mf_s_693915680_57dlgcqh_.bkp
-rw-r-----    1 oracle   dba         6455296 Jan   10  11:49 o1_mf_s_693920955_57dqkw0j_.bkp
-rw-r-----    1 oracle   dba         6455296 Jan   10  13:28 o1_mf_s_693926889_57dxcbdx_.bkp
-rw-r-----    1 oracle   dba         6455296 Jan   10  14:18 o1_mf_s_693928526_57f094n9_.bkp
-rw-r-----    1 oracle   dba         6455296 Jan    10  14:20 o1_mf_s_693930026_57f0fbo2_.bkp

When we drop the tablespace we are changing the structure of the database and since controlfile autobackup has been turned on, we see another backup file has been created in the autobackup location in the flash recovery area on disk.

Now we create tablespace..

SQL> create tablespace arul datafile '/u01/app/oracle/oradata/orcl/arul1.dbf'  
size 100M  extent management local;

SQL> drop tablespace arul including contents and datafiles;

Tablespace dropped.

Now We check valid backup

testdb:/u02/oradata/testdb/TESTDB/autobackup/2009_08_03> ls -lrt
total 75648
-rw-r-----    1 oracle   dba         6455296 Jan  10  10:22 o1_mf_s_693915680_57dlgcqh_.bkp
-rw-r-----    1 oracle   dba         6455296 Jan   10  11:49 o1_mf_s_693920955_57dqkw0j_.bkp
-rw-r-----    1 oracle   dba         6455296 Jan   10  3 13:28 o1_mf_s_693926889_57dxcbdx_.bkp
-rw-r-----    1 oracle   dba         6455296 Jan   10  14:18 o1_mf_s_693928526_57f094n9_.bkp
-rw-r-----    1 oracle   dba         6455296 Jan   10  14:20 o1_mf_s_693930026_57f0fbo2_.bkp
-rw-r-----    1 oracle   dba         6455296 Aug  3 14:38 o1_mf_s_693931114_57f1hbmo_.bkp

We then shutdown the database, startup in nomount mode and attempt to restore the controlfile from autobackup.

The most recent controlfile autobackup has been restored, but since this has been taken after the tablespace was dropped, the tablespace which has been dropped (ARUL) is not referenced in the control file that we just restored. If we try to restore and recover the database, the dropped tablespace will not be restored.

 SQL> shutdown immediate;

SQL> startup nomount;
ORACLE instance started.

Total System Global Area  264241152 bytes
Fixed Size                  2083304 bytes
Variable Size             142607896 bytes
Database Buffers          113246208 bytes
Redo Buffers                6303744 bytes

RMAN> restore controlfile from autobackup;

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

recovery area destination: /u02/oradata/testdb/
database name (or database unique name) used for search: TESTDB
channel ORA_DISK_1: autobackup found in the recovery area
channel ORA_DISK_1: autobackup found: /u02/oradata/testdb/TESTDB/autobackup/2009_08_03/o1_mf_s_693931114_57f1hbmo_.bkp
channel ORA_DISK_1: control file restore from autobackup complete
output filename=/u02/oradata/testdb/control01.ctl
output filename=/u02/oradata/testdb/control02.ctl
output filename=/u02/oradata/testdb/control03.ctl
Finished restore at 10-JAN-18

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> report schema;
...

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    1230     SYSTEM               ***     /u02/oradata/testdb/system01.dbf
2    1700     UNDOTBS1             ***     /u02/oradata/testdb/undotbs01.dbf
3    370      SYSAUX               ***     /u02/oradata/testdb/sysaux01.dbf
4    280      USERS                ***     /u02/oradata/backup/bkp.04klgv2b
5    131      EXAMPLE              ***     /u02/oradata/testdb/example01.dbf
6    150      USERS                ***     /u02/oradata/backup/bkp.06klgv3k
9    100      USERS                ***     /u02/oradata/backup/bkp.08klgv4i


We will need to restore a backup of the controlfile which contains records for the tablespace ARUL. We use the RESTORE CONTROLFILE FROM command to restore a specific controlfile autobackup.

RMAN>  restore controlfile from '/u02/oradata/testdb/TESTDB/autobackup/2018_01_10/o1_mf_s_693930026_57f0fbo2_.bkp';

Starting restore at 10-JAN-18
using channel ORA_DISK_1

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u02/oradata/testdb/control01.ctl
output filename=/u02/oradata/testdb/control02.ctl
output filename=/u02/oradata/testdb/control03.ctl
Finished restore at 10-JAN-18

RMAN> report schema;
.....

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    1230     SYSTEM               ***     /u02/oradata/testdb/system01.dbf
2    1700     UNDOTBS1             ***     /u02/oradata/testdb/undotbs01.dbf
3    370      SYSAUX               ***     /u02/oradata/testdb/sysaux01.dbf
4    280      USERS                ***     /u02/oradata/backup/bkp.04klgv2b
5    131      EXAMPLE              ***     /u02/oradata/testdb/example01.dbf
6    150      USERS                ***     /u02/oradata/backup/bkp.06klgv3k
7    0        ARUL                 ***     /u02/oradata/testdb/arul01.dbf
9    100      USERS                ***     /u02/oradata/backup/bkp.08klgv4i


The alert log will also show the time when the tablespace was dropped. We can also see that a controlfile autobackup has taken place after the tablespace was dropped.

drop tablespace arul including contents and datafiles
Mon Jan  10 14:38:34 2018
Deleted file /u02/oradata/testdb/arul01.dbf
Starting control autobackup
Control autobackup written to DISK device
        handle '/u02/oradata/testdb/TESTDB/autobackup/2018_01_10/o1_mf_s_693931114_57f1hbmo_.bkp'
Completed: drop tablespace arul including contents and datafiles


Now that we know the time the tablespace was dropped, we can do a point in time recovery of the DATABASE in order to recover the tablespace which has been dropped.

RMAN> run {
2> set until time "to_date('10-JAN-2018 14:38:00','DD-MON-YYYY HH24:Mi:SS')";
3> restore database;
4> recover database;
5> }

executing command: SET until clause
using target database control file instead of recovery catalog

Starting restore at 10-JAN-18
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: sid=159 devtype=SBT_TAPE
channel ORA_SBT_TAPE_1: Data Protection for Oracle: version 5.5.1.0
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK

channel ORA_DISK_1: restoring datafile 00004
input datafile copy recid=14 stamp=693929215 filename=/u02/oradata/testdb/users01.dbf
destination for restore of datafile 00004: /u02/oradata/backup/bkp.04klgv2b
channel ORA_SBT_TAPE_1: starting datafile backupset restore
channel ORA_SBT_TAPE_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u02/oradata/testdb/system01.dbf
restoring datafile 00002 to /u02/oradata/testdb/undotbs01.dbf
restoring datafile 00003 to /u02/oradata/testdb/sysaux01.dbf
restoring datafile 00005 to /u02/oradata/testdb/example01.dbf
restoring datafile 00007 to /u02/oradata/testdb/arul01.dbf
channel ORA_SBT_TAPE_1: reading from backup piece 0gkloo6p_1_1
channel ORA_DISK_1: copied datafile copy of datafile 00004
output filename=/u02/oradata/backup/bkp.04klgv2b recid=21 stamp=693932732
channel ORA_DISK_1: restoring datafile 00006
input datafile copy recid=13 stamp=693929146 filename=/u02/oradata/testdb/users02.dbf
destination for restore of datafile 00006: /u02/oradata/backup/bkp.06klgv3k
channel ORA_DISK_1: copied datafile copy of datafile 00006
output filename=/u02/oradata/backup/bkp.06klgv3k recid=23 stamp=693932755
channel ORA_DISK_1: restoring datafile 00009
input datafile copy recid=10 stamp=693929108 filename=/u02/oradata/testdb/users03.dbf
destination for restore of datafile 00009: /u02/oradata/backup/bkp.08klgv4i
channel ORA_DISK_1: copied datafile copy of datafile 00009
output filename=/u02/oradata/backup/bkp.08klgv4i recid=26 stamp=693932809
channel ORA_SBT_TAPE_1: restored backup piece 1
piece handle=0gkloo6p_1_1 tag=TAG20090803T113241
channel ORA_SBT_TAPE_1: restore complete, elapsed time: 00:02:40
Finished restore at 10-JAN-18

Starting recover at 10-JAN-18
using channel ORA_SBT_TAPE_1
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 8 is already on disk as file /u02/oradata/testdb/arch/arch.8.1.693662800.log
archive log thread 1 sequence 9 is already on disk as file /u02/oradata/testdb/arch/arch.9.1.693662800.log
archive log thread 1 sequence 10 is already on disk as file /u02/oradata/testdb/arch/arch.10.1.693662800.log
archive log thread 1 sequence 1 is already on disk as file /u02/oradata/testdb/redo01.log
archive log thread 1 sequence 2 is already on disk as file /u02/oradata/testdb/redo02.log
archive log filename=/u02/oradata/testdb/arch/arch.8.1.693662800.log thread=1 sequence=8
archive log filename=/u02/oradata/testdb/arch/arch.9.1.693662800.log thread=1 sequence=9
archive log filename=/u02/oradata/testdb/arch/arch.10.1.693662800.log thread=1 sequence=10
archive log filename=/u02/oradata/testdb/redo01.log thread=1 sequence=1
archive log filename=/u02/oradata/testdb/redo02.log thread=1 sequence=2
media recovery complete, elapsed time: 00:00:06
Finished recover at 10-JAN-18

RMAN>

RMAN> alter database open resetlogs;

database opened

We can now see that the tablespace which has been dropped has been recovered

SQL> select file_name,bytes from dba_data_files where
  2  tablespace_name='ARUL';

FILE_NAME
--------------------------------------------------------------------------------
     BYTES
----------
/u02/oradata/testdb/arul01.dbf
  37748736


Tuesday, January 9, 2018

Recovering Datafile for which no backup exist

 Recovering Datafile for which no backup exist (In 10G Database Using RMAN).
 
 


Step 1: Confirm Database Name and Identify Tablespace Name to be used for DR Test.

SQL> select INSTANCE_NAME, VERSION from v$instance;

INSTANCE_NAME    VERSION
---------------- -----------------
opsdba           10.2.0.2.0


SQL> select name from v$tablespace;

NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
USERS
TEMP1

SQL> select file_name from dba_data_files;

FILE_NAME
----------------------------------------------------------------------
----------
/u02/ORACLE/opsdba/users01.dbf
/u02/ORACLE/opsdba/sysaux01.dbf
/u02/ORACLE/opsdba/undotbs01.dbf
/u02/ORACLE/opsdba/system01.dbf
/u02/ORACLE/opsdba/users05.dbf
/u02/ORACLE/opsdba/users02.dbf
/u02/ORACLE/opsdba/users03.dbf
/u02/ORACLE/opsdba/users06.dbf
/u02/ORACLE/opsdba/users07.dbf
/u02/ORACLE/opsdba/users04.dbf

10 rows selected.

Step 2: Create a new tablespace with 1 Datafile which will be used for recovery exercise.

SQL> create tablespace drtbs datafile '/u02/ORACLE/opsdba/drtbs1.dbf'
size 100M  extent management local;

Tablespace created.

SQL> select name from v$tablespace;

NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
USERS
DRTBS
TEMP1

6 rows selected.

SQL>  select file_name from dba_data_files where tablespace_name=
'DRTBS';

FILE_NAME
--------------------------------------------------------------
/u02/ORACLE/opsdba/drtbs1.dbf

SQL> exit

Step 3: Take a full Backup of Database & Archive log.

RMAN> backup database plus archivelog;


Starting backup at 28-JAN-07
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=154 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=1 recid=362 stamp=612901138
input archive log thread=1 sequence=2 recid=363 stamp=612901141
input archive log thread=1 sequence=3 recid=364 stamp=612901146
input archive log thread=1 sequence=4 recid=365 stamp=612943256
input archive log thread=1 sequence=5 recid=366 stamp=612976032
input archive log thread=1 sequence=6 recid=367 stamp=612976036
input archive log thread=1 sequence=7 recid=368 stamp=613049876
input archive log thread=1 sequence=8 recid=369 stamp=613049878
input archive log thread=1 sequence=9 recid=370 stamp=613049879
input archive log thread=1 sequence=10 recid=371 stamp=613049880
channel ORA_DISK_1: starting piece 1 at 28-JAN-07
channel ORA_DISK_1: finished piece 1 at 28-JAN-07
piece handle=/opt/oracle/backup/opsdba/OPSDBA.20070128.145.1.1.
613089429 tag=TAG20070128T223709 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:16
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=1 recid=372 stamp=613049882
input archive log thread=1 sequence=2 recid=373 stamp=613049884
input archive log thread=1 sequence=3 recid=374 stamp=613049885
input archive log thread=1 sequence=4 recid=375 stamp=613049887
input archive log thread=1 sequence=5 recid=376 stamp=613049888
input archive log thread=1 sequence=6 recid=377 stamp=613049889
input archive log thread=1 sequence=7 recid=378 stamp=613049890
channel ORA_DISK_1: starting piece 1 at 28-JAN-07
channel ORA_DISK_1: finished piece 1 at 28-JAN-07
piece handle=/opt/oracle/backup/opsdba/OPSDBA.20070128.146.1.1.
613089445 tag=TAG20070128T223709 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:08
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=1 recid=379 stamp=613089428
channel ORA_DISK_1: starting piece 1 at 28-JAN-07
channel ORA_DISK_1: finished piece 1 at 28-JAN-07
piece handle=/opt/oracle/backup/opsdba/OPSDBA.20070128.147.1.1.
613089453 tag=TAG20070128T223709 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 28-JAN-07

Starting backup at 28-JAN-07
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=/u02/ORACLE/opsdba/system01.dbf
input datafile fno=00003 name=/u02/ORACLE/opsdba/sysaux01.dbf
input datafile fno=00002 name=/u02/ORACLE/opsdba/undotbs01.dbf
input datafile fno=00011 name=/u02/ORACLE/opsdba/drtbs1.dbf
input datafile fno=00004 name=/u02/ORACLE/opsdba/users01.dbf
input datafile fno=00005 name=/u02/ORACLE/opsdba/users02.dbf
input datafile fno=00006 name=/u02/ORACLE/opsdba/users03.dbf
input datafile fno=00007 name=/u02/ORACLE/opsdba/users05.dbf
input datafile fno=00010 name=/u02/ORACLE/opsdba/users04.dbf
input datafile fno=00008 name=/u02/ORACLE/opsdba/users06.dbf
input datafile fno=00009 name=/u02/ORACLE/opsdba/users07.dbf
channel ORA_DISK_1: starting piece 1 at 28-JAN-07
channel ORA_DISK_1: finished piece 1 at 28-JAN-07
piece handle=/opt/oracle/backup/opsdba/OPSDBA.20070128.148.1.1.
613089455 tag=TAG20070128T223735 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
Finished backup at 28-JAN-07

Starting backup at 28-JAN-07
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=2 recid=380 stamp=613089480
channel ORA_DISK_1: starting piece 1 at 28-JAN-07
channel ORA_DISK_1: finished piece 1 at 28-JAN-07
piece handle=/opt/oracle/backup/opsdba/OPSDBA.20070128.149.1.1.
613089480 tag=TAG20070128T223800 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 28-JAN-07

Starting Control File and SPFILE Autobackup at 28-JAN-07
piece handle=/opt/oracle/product10gpr2/dbs/c-1493612009-20070128-03
comment=NONE
Finished Control File and SPFILE Autobackup at 28-JAN-07
RMAN>exit

Step 4: Add a New Datafile to that Tablespace and verify that the new file is now a member of that tablespace. Also switch few log files just for confirmation.

SQL> select file_name from dba_data_files where tablespace_name=
'DRTBS';

FILE_NAME
----------------------------------------------------------------------
----------
/u02/ORACLE/opsdba/drtbs1.dbf

SQL> alter tablespace drtbs add datafile '/u02/ORACLE/opsdba/drtbs2.
dbf' size 100m;

Tablespace altered.

SQL> select file_name from dba_data_files where tablespace_name=
'DRTBS';

FILE_NAME
----------------------------------------------------------------------
----------
/u02/ORACLE/opsdba/drtbs1.dbf
/u02/ORACLE/opsdba/drtbs2.dbf

SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

Step 5: Create a new Table in that tablespace and perform some DML operation. Also after DML operations switch some logfile.

SQL> create table t1(col1 number(10)) tablespace DRTBS;

Table created.

SQL> insert into t1 values (&a);
Enter value for a: 1
old   1: insert into t1 values(&a)
new   1: insert into t1 values(1)

1 row created.

SQL> /
Enter value for a: 2
old   1: insert into t1 values(&a)
new   1: insert into t1 values(2)

1 row created.

SQL> /
Enter value for a: 3
old   1: insert into t1 values(&a)
new   1: insert into t1 values(3)

1 row created.

SQL> /
Enter value for a: 4
old   1: insert into t1 values(&a)
new   1: insert into t1 values(4)

1 row created.

SQL> commit;
Commit complete.

SQL> select * from t1;

      COL1
----------
         1
         2
         3
         4

SQL> alter system switch logfile;

System altered.

Step 6: In the OS Level remove all files of that tablespace including the newly added one (whose backup does not exist).

opsdba:/opt/oracle>cd /u02/ORACLE/opsdba/
opsdba:/u02/ORACLE/opsdba>ls –lrt drtbs*.dbf
total 1441496
-rw-r-----    1 oracle   dba      104865792 Jan 28 22:38 drtbs1.dbf
-rw-r-----    1 oracle   dba      104865792 Jan 28 23:08 drtbs2.dbf
opsdba:/u02/ORACLE/opsdba>rm -r drtbs*.dbf
opsdba:/u02/ORACLE/opsdba>ls -lrt drtbs*.dbf
ls: drtbs*.dbf: No such file or directory
opsdba:/u02/ORACLE/opsdba>

Step 7: Try to bring the tablespace offline and we will get error message as follows.

opsdba:/u02/ORACLE/opsdba>sql

SQL> alter tablespace drtbs offline;
alter tablespace drtbs offline
*
ERROR at line 1:
ORA-01116: error in opening database file 11
ORA-01110: data file 11: '/u02/ORACLE/opsdba/drtbs1.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

Step 8: Now bring the Tablespace offline with IMMEDIATE option and confirm.

SQL> alter tablespace drtbs offline immediate;

Tablespace altered.

SQL> select TABLESPACE_NAME,STATUS from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
UNDOTBS1                       ONLINE
SYSAUX                         ONLINE
USERS                          ONLINE
TEMP1                          ONLINE
DRTBS                          OFFLINE
6 rows selected.

Step 9: Now connect to RMAN and Confirm that No backup exist for the Newly added Datafile. Then try to restore the TABLESPACE and we will see that RMAN is creating that newly added Datafile as a part of the restore process. This is a new feature in 10G.

SQL> select file_id, file_name from dba_data_files where
tablespace_name='DRTBS';

   FILE_ID
----------
FILE_NAME
----------------------------------------------------------------------
----------
        11
/u02/ORACLE/opsdba/drtbs1.dbf

        12
/u02/ORACLE/opsdba/drtbs2.dbf


SQL> exit;

opsdba:/u02/ORACLE/opsdba>rman target /

Recovery Manager: Release 10.2.0.2.0 - Production on Sun Jan 28 23:18:
09 2007

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

connected to target database: OPSDBA (DBID=1493612009)

RMAN> list backup of datafile 11;

using target database control file instead of recovery catalog

List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
129     Full    669.09M    DISK        00:00:15     28-JAN-07
        BP Key: 129   Status: AVAILABLE  Compressed: NO  Tag: TAG
20070128T223735
        Piece Name: /opt/oracle/backup/opsdba/OPSDBA.20070128.148.1.1.
613089455
  List of Datafiles in backup set 129
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  11      Full 2747296    28-JAN-07 /u02/ORACLE/opsdba/drtbs1.dbf

RMAN> list backup of datafile 12;

No output …

RMAN> restore tablespace drtbs;

Starting restore at 28-JAN-07
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=144 devtype=DISK

creating datafile fno=12 name=/u02/ORACLE/opsdba/drtbs2.dbf
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00011 to /u02/ORACLE/opsdba/drtbs1.dbf
channel ORA_DISK_1: reading from backup piece /opt/oracle/backup/
opsdba/OPSDBA.20070128.148.1.1.613089455
channel ORA_DISK_1: restored backup piece 1
piece handle=/opt/oracle/backup/opsdba/OPSDBA.20070128.148.1.1.
613089455 tag=TAG20070128T223735
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
Finished restore at 28-JAN-07



opsdba:/u02/ORACLE/opsdba>rman target /


Step 10: Start Recovery of that Tablespace.

opsdba:/u02/ORACLE/opsdba>rman target /

Recovery Manager: Release 10.2.0.2.0 - Production on Sun Jan 28 23:49:33 2007

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

connected to target database: OPSDBA (DBID=1493612009)

RMAN> recover tablespace drtbs;

Starting recover at 28-JAN-07
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=154 devtype=DISK

starting media recovery
un Jan 28 23:22:36 2007
alter database recover logfile '/u02/ORACLE/opsdba/arch/arch_1_2_613052894.dbf'
Sun Jan 28 23:22:36 2007
Media Recovery Log /u02/ORACLE/opsdba/arch/arch_1_2_613052894.dbf
Sun Jan 28 23:22:36 2007
Recovery of Online Redo Log: Thread 1 Group 3 Seq 3 Reading mem 0
  Mem# 0 errs 0: /u02/ORACLE/opsdba/redo03.log
Sun Jan 28 23:22:36 2007
Recovery of Online Redo Log: Thread 1 Group 2 Seq 4 Reading mem 0
  Mem# 0 errs 0: /u02/ORACLE/opsdba/redo02.log
Sun Jan 28 23:22:36 2007
Recovery of Online Redo Log: Thread 1 Group 1 Seq 5 Reading mem 0
  Mem# 0 errs 0: /u02/ORACLE/opsdba/redo01.log
Sun Jan 28 23:22:36 2007
Media Recovery Complete (opsdba)
Completed: alter database recover logfile '/u02/ORACLE/opsdba/arch/arch_1_2_613052894.dbf'
Sun Jan 28 23:22:52 2007
media recovery complete, elapsed time: 00:00:00

Finished recover at 28-JAN-07

RMAN> exit


Recovery Manager complete.

Step 11: Bring the Tablespace online and confirm .
SQL> alter tablespace drtbs online;

Tablespace altered.

SQL> select TABLESPACE_NAME,STATUS from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
UNDOTBS1                       ONLINE
SYSAUX                         ONLINE
USERS                          ONLINE
TEMP1                          ONLINE
DRTBS                          ONLINE

6 rows selected.

SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> select * from t1;

      COL1
----------
         1
         2
         3
         4

SQL> select file_name from dba_data_files where tablespace_name=
'DRTBS';

FILE_NAME
----------------------------------------------------------------------
----------
/u02/ORACLE/opsdba/drtbs1.dbf
/u02/ORACLE/opsdba/drtbs2.dbf

SQL> exit


Step 12: As a standard practice immediately after the recovery please take a FULL DATABASE BACKUP.

opsdba:/u02/ORACLE/opsdba>rman target /

Recovery Manager: Release 10.2.0.2.0 - Production on Sun Jan 28 23:25:
01 2007

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

connected to target database: OPSDBA (DBID=1493612009)

RMAN> backup database plus archivelog;


Starting backup at 28-JAN-07
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=144 devtype=DISK

skipping archive log file /u02/ORACLE/opsdba/arch/arch_1_1_613052894.
dbf; already backed up 1 time(s)
skipping archive log file /u02/ORACLE/opsdba/arch/arch_1_2_613052894.
dbf; already backed up 1 time(s)
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=3 recid=381 stamp=613091353
input archive log thread=1 sequence=4 recid=382 stamp=613091355
input archive log thread=1 sequence=5 recid=383 stamp=613092208
input archive log thread=1 sequence=6 recid=384 stamp=613092210
input archive log thread=1 sequence=7 recid=385 stamp=613092318
channel ORA_DISK_1: starting piece 1 at 28-JAN-07
channel ORA_DISK_1: finished piece 1 at 28-JAN-07
piece handle=/opt/oracle/backup/opsdba/OPSDBA.20070128.154.1.1.
613092318 tag=TAG20070128T232518 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 28-JAN-07

Starting backup at 28-JAN-07
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=/u02/ORACLE/opsdba/system01.dbf
input datafile fno=00003 name=/u02/ORACLE/opsdba/sysaux01.dbf
input datafile fno=00002 name=/u02/ORACLE/opsdba/undotbs01.dbf
input datafile fno=00011 name=/u02/ORACLE/opsdba/drtbs1.dbf
input datafile fno=00012 name=/u02/ORACLE/opsdba/drtbs2.dbf
input datafile fno=00004 name=/u02/ORACLE/opsdba/users01.dbf
input datafile fno=00005 name=/u02/ORACLE/opsdba/users02.dbf
input datafile fno=00006 name=/u02/ORACLE/opsdba/users03.dbf
input datafile fno=00007 name=/u02/ORACLE/opsdba/users05.dbf
input datafile fno=00010 name=/u02/ORACLE/opsdba/users04.dbf
input datafile fno=00008 name=/u02/ORACLE/opsdba/users06.dbf
input datafile fno=00009 name=/u02/ORACLE/opsdba/users07.dbf
channel ORA_DISK_1: starting piece 1 at 28-JAN-07
channel ORA_DISK_1: finished piece 1 at 28-JAN-07
piece handle=/opt/oracle/backup/opsdba/OPSDBA.20070128.155.1.1.
613092320 tag=TAG20070128T232520 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
Finished backup at 28-JAN-07

Starting backup at 28-JAN-07
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=8 recid=386 stamp=613092345
channel ORA_DISK_1: starting piece 1 at 28-JAN-07
channel ORA_DISK_1: finished piece 1 at 28-JAN-07
piece handle=/opt/oracle/backup/opsdba/OPSDBA.20070128.156.1.1.
613092346 tag=TAG20070128T232545 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 28-JAN-07

Starting Control File and SPFILE Autobackup at 28-JAN-07
piece handle=/opt/oracle/product10gpr2/dbs/c-1493612009-20070128-07
comment=NONE
Finished Control File and SPFILE Autobackup at 28-JAN-07

RMAN> list backup of datafile 11;


List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
129     Full    669.09M    DISK        00:00:15     28-JAN-07
        BP Key: 129   Status: AVAILABLE  Compressed: NO  Tag: TAG
20070128T223735
        Piece Name: /opt/oracle/backup/opsdba/OPSDBA.20070128.148.1.1.
613089455
  List of Datafiles in backup set 129
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  11      Full 2747296    28-JAN-07 /u02/ORACLE/opsdba/drtbs1.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
136     Full    669.73M    DISK        00:00:21     28-JAN-07
        BP Key: 136   Status: AVAILABLE  Compressed: NO  Tag: TAG
20070128T232520
        Piece Name: /opt/oracle/backup/opsdba/OPSDBA.20070128.155.1.1.
613092320
  List of Datafiles in backup set 136
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  11      Full 2748771    28-JAN-07 /u02/ORACLE/opsdba/drtbs1.dbf

RMAN> list backup of datafile 12;


List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
136     Full    669.73M    DISK        00:00:21     28-JAN-07
        BP Key: 136   Status: AVAILABLE  Compressed: NO  Tag: TAG
20070128T232520
        Piece Name: /opt/oracle/backup/opsdba/OPSDBA.20070128.155.1.1.
613092320
  List of Datafiles in backup set 136
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  12      Full 2748771    28-JAN-07 /u02/ORACLE/opsdba/drtbs2.dbf




How to create user in MY SQL

Create  a new MySQL user Account mysql > CREATE USER ' newuser '@'localhost' IDENTIFIED BY ' password '...