Wednesday, December 16, 2015

EXADATA Smart Scan Overview

n  Table and Index scans: Scans are performed inside Exadata Storage rather than transporting all data to database server.
n  Predicate Filtering: Only requesting rows are returned to the database server rather than all rows in a table.
n  Column Filtering: Only requested columns are returned to the database server rather than all table columns.
n  Join Filtering: Join processing using Bloom Filters are offloaded to exadata server.
n  Smart scan can also be applied to encrypted and compressed data.

Smart Scan Requirements:
Smart Scan optimization is a run time decision. Smart scan is not governed by optimizer, but it is influenced by results of query optimization.

n  Query specific requirements
---- Smart Scan is only possible for Full Table or Index scans
---- Can be used only for direct path reads. (A direct read is a physical I/O from a data file that bypasses the buffer cache and reads the data block directly into process-private memory.)
n  Additional general requirements
--- Smart Scan must be enabled with in database. CELL_OFFLOAD_PROCESSING parameter controls smart scan. Default value is TRUE. Can be set dynamically using alter session or alter system.
---- Each segment being scanned must be on a disk group that is completely stored on exadata cells.


Situations Preventing Smart Scan

n  Scan on clustered table
n  Scan on Index Organized Table.
n  Fast Full Scan on Compressed Index
n  Fast Full scan on a reverse key index
n  More than 255 columns are referenced by query.

n  Optimized wants to scan to return rows in ROWID order.

Thursday, October 29, 2015

Upgrading from Oracle 11gR2 to Oracle 12c using Full Transportable Export/Import

********************************************************************************
**************** Oracle Database 12c: Full Transportable Export/Import *********
********************************************************************************

-- Full transportable export is available starting with Oracle Database 11g Release 2 (11.2.0.3). Full transportable import is available starting with Oracle Database 12c.

-- The Full Transportable Export and Import feature combines the best features of TTS/XTTS and Data Pump. 

-- Full transportable export/import moves all of the system, user, and application metadata needed for a database migration

--  Parameters to initiate "Full Transportable Export". These parameter values tell Data Pump to use full transportable rather than conventional export methods.

TRANSPORTABLE=ALWAYS and FULL=Y

-- In addition, there is a special consideration if the COMPATIBLE database initialization parameter of the source database is not set to a value of at least 12.0. This would be true, for example, if you perform a full transportable export from Oracle Database 11g Release 2 (11.2.0.3). In this case, you must also specify the Data Pump parameter VERSION=12 to denote the fact that the result of the export will be imported into an Oracle Database 12c Release 1 (12.1) or later database.

-- Invoking Full Transportable Import

In case of using dump,  file-based full transportable import thus requires only that you specify the dumpfile name and the list of user tablespace data files to be transported using the TRANSPORT_DATAFILES=<datafile_names> parameter.
Because while importing a dump file, Oracle Data Pump is able to determine whether a dump file was produced by a conventional or full transportable export

--- Without dump file (importing over NETWORK_LINK)

• FULL=Y TRANSPORTABLE=ALWAYS as specified for a full transportable export
• TRANSPORT_DATAFILES=<datafile_names> as used in a file-based full transportable import
• VERSION=12 if the COMPATIBLE setting for the source database is lower than 12.0. Note that the source database must be Oracle Database 11g Release 2 (11.2.0.3) or higher for a full transportable import
• NETWORK_LINK=<dblink_name> to specify the database link over which the data and metadata
are transferred from the source database.


************* Endian Convesion ***********

If the source platform and the target platform are of different endianness, then the data files being transported must be converted to the target platform format using either the RMAN CONVERT command or the GET_FILE or PUT_FILE procedures in the DBMS_FILE_TRANSFER package.

Note that encrypted tablespaces cannot be transported to a platform with different endianness

Example: Using Full Transportable to Move a Non-CDB into a CDB

Source - Oracle 11.2.0.3 running on Oracle Solaris x86
Target - Oracle 12c PDB inside of a CDB running on Oracle Linux

TABLE 1. SOURCE DATABASE TABLESPACES
TABLESPACE NAME ENCRYPTED? DATAFILE NAME
HR_1 Yes /u01/app/oracle/oradata/hr_db/hr_101.dbf
HR_2 No /u01/app/oracle/oradata/hr_db/hr_201.dbf
For this example we assume that the Oracle SID of the target database is HR_PDB, and that the data files for the target PDB are stored in the directory /u01/app/oracle/oradata/hr_pdb/ on the destination server.

STEP 1: Check the endianness of both platforms

SQL> SELECT d.PLATFORM_NAME, ENDIAN_FORMAT
FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d
WHERE tp.PLATFORM_ID = d.PLATFORM_ID;

Oracle Solaris x86 and Oracle Enterprise Linux have little endian format, so no
endian conversion is necessary.

STEP 2: Verify that the set of tablespaces to be transported is self-contained 

SQL> EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('hr_1,hr_2', TRUE);

SQL> SELECT * FROM TRANSPORT_SET_VIOLATIONS;

STEP 3: Create a directory object in the source database

SQL> CREATE DIRECTORY dp_dir AS ’/u01/app/datafiles’;

STEP 4: Place the hr_1 and hr_2 tablespaces in read-only mode 

SQL> ALTER TABLESPACE hr_1 READ ONLY;
SQL> ALTER TABLESPACE hr_2 READ ONLY;

STEP 5: Invoke full transportable export on the source database

Invoke the Data Pump export utility as a user with the DATAPUMP_EXP_FULL_DATABASE role.

$ expdp system/manager full=y transportable=always version=12 \
directory=dp_dir dumpfile=full_tts.dmp \
metrics=y exclude=statistics \
encryption_password=secret123word456 \
logfile=full_tts_export.log


STEP 6: Transport the tablespace data files and the export dump file from source to target

$ cd /u01/app/oracle/oradata/hr_pdb/
$ cp /net/<source-server>/u01/app/oracle/oradata/hr_db/hr_101.dbf .
$ cp /net/<source-server>/u01/app/oracle/oradata/hr_db/hr_201.dbf .
$ cp /net/<source-server>/u01/app/datafiles/full_tts.dmp

STEP 7: Create a directory object on the destination database 

SQL> CREATE DIRECTORY dp_dir AS '/u01/app/oracle/oradata/hr_pdb';
SQL> GRANT read, write on directory dp_dir to system;


STEP 8: Invoke full transportable import on the destination database
Invoke the Data Pump import utility as a user with DATAPUMP_IMP_FULL_DATABASE role.

$ impdp system/manager@hr_pdb directory=dp_dir \
dumpfile=full_tts.dmp logfile=full_tts_imp.log \
metrics=y \
encryption_password=secret123word456 \
transport_datafiles='/u01/app/oracle/oradata/hr_pdb/hr_101.dbf',\
'/u01/app/oracle/oradata/hr_pdb/hr_201.dbf' 





Friday, December 5, 2014

Checking Optimizer Compatibility

Sometime optimizer may not be compatible.  It is usually the result of an in-place upgrade or patch. The result is that the production server may behave differently from the development and test servers. 

To check the compatibility you can run below query.

set serveroutput on
DECLARE
ver VARCHAR2(30);
compat VARCHAR2(30);
BEGIN
dbms_utility.db_version(ver, compat);
dbms_output.put_line('Version: ' || ver ||' compatible: ' || compat);
END;
/
Version: 11.2.0.4.0 compatible: 11.2.0.0.0

PL/SQL procedure successfully completed.


Thursday, November 27, 2014

Troubleshooting Log File Sync Waits

If you notice a very large number of waits with a short average wait time per wait, that’s an indication that too many commit statements are being issued by the database. You must change the commit behavior by batching the commits.
Instead of committing after each row, for example, you can specify that the commits occur after every 500 rows.

If you notice that the large amount of wait time accumulated due to the redo log file sync event was caused by long waits for writing to the redo log file (high average time waited for this event), it’s more a matter of how fast your I/O subsystem is. You can alternate the redo log files on various disks to reduce contention. You can also see if you can dedicate disks entirely for the redo logs instead of allowing other files on those disks—this will reduce I/O contention when the LGWR is writing the buffers to disk. Finally, as a long-term solution, you can look into placing redo logs on faster devices, say, by moving them from a RAID 5 to a RAID 1 device.

How It Works

Oracle (actually the LGWR background process) automatically flushes a session’s redo information to the redo log file whenever a session issues a COMMIT statement. The database writes commit records to disk before it returns control to the client. The server process thus waits for the completion of the write to the redo log. 


The log file sync wait event includes the wait during the writing of the log buffer to disk by LGWR and the posting of that information to the session. The server process will have to wait until it gets confirmation that the LGWR process has completed writing the log buffer contents out to the redo log file.

The log file sync events are caused by contention during the writing of the log buffer contents to the redo log files. Check the V$SESSION_WAIT view to ascertain whether Oracle is incrementing the SEQ# column. If Oracle is incrementing this column, it means that the LGWR process is the culprit, as it may be stuck.

P1 = buffer#
All changes up to this buffer number (in the log buffer) must be flushed to disk and the writes confirmed to ensure that the transaction is committed and will be kept on an instance crash. The wait is for LGWR to flush up to this 

As the log file sync wait event is caused by contention caused by the LGWR process, see if you can use the NOLOGGING option to get rid of these waits. Of course, in a production system, you can’t use the NOLOGGING option when the database is processing user requests, so this option is of limited use in most cases.

Troubleshooting Buffer Busy Wait Events

The Buffer Busy Waits Oracle metric occur when an Oracle session needs to access a block in the buffer cache, but cannot because the buffer copy of the data block is locked. 

What causes the buffer busy wait event 

1. The block is being read into the buffer by another session, so the waiting session must wait for the block read to complete.

2. Another session has the buffer block locked in a mode that is incompatible with the waiting session's request.

While the block is being changed, the block is marked as unreadable by others. The changes that are being made should last under a few hundredths of a second, for example, a disk read should be under 20 milliseconds and a block modification should be under one millisecond. Therefore it will take a lot of buffer busy waits to cause a problem, but some examples of this are:

1. Hot block issue, such as the first block on the free list of a table, with high concurrent inserts. All users will insert into that block at the same time, until it fills up, then users start inserting into the next free block on the list, and so on.
2. Multiple users running an inefficient SQL statement performing a full table scan on the same large table at the same time. One user will read the block off disk, and the other users will wait on buffer busy waits (or read by other session in 10g and higher) for the physical I/O to complete.

Find more  information of buffer busy waits

col event for a30
select event,p1 file#,p2 block#
from v$session_wait
where sid in
(select sid from v$session where username='&username')
/

To get more information about the SQL statement being executed and the block being waited for, trace the session or gather data from V$SESSION V$SESSION_WAIT 

SELECT s.sql_hash_value, sw.p1 file#, sw.p2 block#, sw.p3 reason
FROM v$session_wait sw, v$session s
WHERE sw.event = 'buffer busy waits'
AND sw.sid = s.sid
/

P1 stands for File id 
P2 stands for Block id
P3 stands for reason code


Now determine the object being waited for, use the P1 (file_number) and P2 (block_number) information from the above query:

col owner for a10
col segment_name for a15
select owner, segment_name
from dba_extents
where file_id = &p1
and &p2 between block_id and block_id+blocks-1
/

Troubleshooting buffer busy waits

Now you know the database object for this wait, consider the following causes of contention and their solutions

Undo Header – If using Automatic Undo Management, increase the size of the undo tablespace. 

Data Block- Data blocks are the blocks that hold the row data in a table or index. The typical problem is that multiple sessions are requesting a block that is either not in cache or in an incompatible mode (read by other session in 10g and higher).

Tune inefficient queries that read too many blocks into the buffer cache. These queries could flush out blocks that may be useful for other sessions in the buffer cache. By tuning queries, the number of blocks that need to be read into the cache is minimized, reducing aging out of the existing “good” blocks in the cache.

Resolve Hot Blocks – If the queries above consistently return the same block or set of blocks, this is considered a hot block scenario. Delete some of the hot rows and insert them back into the table. Most of the time, the rows will be placed in a different block. The DBA may need to adjust PCTFREE and/or PCTUSED to ensure the rows are placed into a different block. Also talk with the developers to understand why a set of blocks are hot.

Place Table in Memory – Cache the table or keep the table in the KEEP POOL. When multiple sessions are requesting the blocks that reside in the disk, it takes too much time for a session to read it into the buffer cache. Other session(s) that need the same block will register ‘buffer busy wait’. If the block is already in buffer cache, however, this possibility is eliminated. Another alternative is to increase the buffer cache size. A larger buffer cache means less I/O from disk. This reduces situations where one session is reading a block from the disk subsystem and other sessions are waiting for the block.

Fix Low Cardinality Indexes – Look for ways to reduce the number of low cardinality indexes, i.e. an index with a low number of unique values that could result in excessive block reads. This can especially be problematic when concurrent DML operates on table with low cardinality indexes and cause contention on a few index blocks.

Data Segment Header- Each segment has one header block that contains segment information, e.g. free and available block details and the highwater mark. At times, this block can be a point of contention when multiple sessions are attempting to insert/delete into/from the same table.

Friday, August 23, 2013

Using DBMS_STATS to backup and restore statistics

1) Check last analyzed date of scott schema tables

SQL> select table_name, last_analyzed from DBA_TABLES WHERE OWNER='SCOTT';

TABLE_NAME                     LAST_ANAL
------------------------------ ---------
TEMP                           18-AUG-13
SALGRADE                       18-AUG-13
BONUS                          18-AUG-13
EMP                            18-AUG-13
DEPT                           18-AUG-13


2) Create stat table in users Tablespace

SQL> exec dbms_stats.create_stat_table(ownname => 'SCOTT', stattab => 'stats_bkp_scott', tblspace => 'USERS');

PL/SQL procedure successfully completed.


3) Take the statistics backup of scott schema in stat table

SQL> exec dbms_stats.export_schema_stats(ownname => 'SCOTT', stattab => 'stats_bkp_scott');

PL/SQL procedure successfully completed.


4) Gather the statistics

SQL> exec dbms_stats.gather_table_stats(ownname=>'SCOTT', tabname=>'EMP', cascade=>true, method_opt => 'for all indexed columns',granularity =>'all',estimate_percent=> 30,degree=>12);

PL/SQL procedure successfully completed.

5) Check the last analyzed date of tables

SQL> select table_name, last_analyzed from DBA_TABLES WHERE OWNER='SCOTT';

TABLE_NAME                     LAST_ANAL
------------------------------ ---------
STATS_BKP_SCOTT
DEPT                           23-AUG-13
EMP                            23-AUG-13
BONUS                          18-AUG-13
SALGRADE                       18-AUG-13
TEMP                           18-AUG-13

6 rows selected.

6) Import/Revert the statistics of one/two table from the backup

SQL> exec dbms_stats.import_table_stats(ownname=>'SCOTT', tabname=>'EMP', statown=>'SCOTT', stattab=>'stats_bkp_scott', cascade=>true);

PL/SQL procedure successfully completed.

7) Check the last analyzed date of the tables

SQL>  select table_name, last_analyzed from DBA_TABLES WHERE OWNER='SCOTT';

TABLE_NAME                     LAST_ANAL
------------------------------ ---------
STATS_BKP_SCOTT
TEMP                           18-AUG-13
SALGRADE                       18-AUG-13
BONUS                          18-AUG-13
EMP                            18-AUG-13
DEPT                           23-AUG-13

6 rows selected.

8) Revert the statistics of whole schema from the backup

SQL> EXECUTE DBMS_STATS.IMPORT_SCHEMA_STATS ('SCOTT','stats_bkp_scott');

PL/SQL procedure successfully completed.


9) Check the last analyzed date of the tables

SQL> select table_name, last_analyzed from DBA_TABLES WHERE OWNER='SCOTT';

TABLE_NAME                     LAST_ANAL
------------------------------ ---------
STATS_BKP_SCOTT
DEPT                           18-AUG-13
EMP                            18-AUG-13
BONUS                          18-AUG-13
SALGRADE                       18-AUG-13
TEMP                           18-AUG-13

6 rows selected.




Tuesday, March 12, 2013

Using RMAN Incremental Backups to Roll Forward a Physical Standby Database

In this article, we will show the steps that can be used to resolve problems if a physical standby database has lost or corrupted archived redo data or has an unresolvable archive gap.



1). Check the CURRENT_SCN on Primary and Standby

--On Primary
SQL> select current_scn from v$database;

CURRENT_SCN
-----------
     871303

--On Standby
SQL> select current_scn from v$database;

CURRENT_SCN
-----------
     859798

2). On the standby database, stop the Managed Recovery Process.
SQL> alter database recover managed standby database cancel;

3). Take "FROM SCN" backup of Primary Database
RMAN> backup incremental from scn 859790 database format '/u01/stnd_backp_%U.bak';

4). Create Standby Controlfile at Primary:
SQL> alter database create standby controlfile as /u01/stnd_cntl.ctl';

5).Copy the backup files and control file to standby server.

scp oracle@192.168.195.128:/u01/stnd* /u01/

At Standby copy controlfiles to their loactaion:

cp stnd_cntl.ctl /u01/app/oracle/oradata/HCLDB/control01.ctl
cp stnd_cntl.ctl /u01/app/oracle/flash_recovery_area/HCLDB/control02.ctl

6). Mount the standby database using backup controlfile.
SQL> startup nomount
SQL> alter database mount standby database;

7).Catalog the backupieces which you have copied from primary server to standby server using below command on standby server.

RMAN> catalog start with '/u01/stnd_backp_0fo4apn7_1_1.bak';
RMAN> catalog start with '/u01/stnd_backp_0go4apov_1_1.bak';

8). Recover the standby database with the cataloged incremental backup.
RMAN> recover database noredo;

**You must also specify NOREDO if the online logs are available but the redo cannot be applied to the incrementals.
**If you do not specify NOREDO, then RMAN searches for redo logs after applying the incremental backup, and issues an error message when it does not find them.

9), Now check whether the standby database is properly synched or not
- On Primary database
SQL> select max(sequence#) from v$archived_log;

- On Standby database
SQL> select max(sequence#) from v$log_history;

10) On the standby database, start the MRP process.
SQL> alter database recover managed standby database disconnect from session;

Thursday, January 31, 2013

Step by Step - Physical Standby Setup using DUPLICATE in Oracle Database 11g Release 2


Step by Step - Physical Standby Setup using DUPLICATE in Oracle Database 11g Release 2

My Server Details:-
Primary Database - HCLDB - Sever - 192.168.195.128
Standby Database - HCLDB_STBY - Sever - 192.168.195.138
Oracle 11GR2 on RHEL5

Step1. Make sure your Primary DB is in Archivelog mode and Force logging is enabled if not put you DB in Archivelog mode

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   2
Current log sequence           2

**Enable forced logging by issuing the following command.

SQL> ALTER DATABASE FORCE LOGGING;

Database altered.

Step2. Check the setting for the DB_NAME and DB_UNIQUE_NAME parameters. In this case they are both set to "HCLDB" on the primary database.

SQL> show parameter db_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_name                              string      HCLDB
SQL> show parameter db_unique_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_unique_name                       string      HCLDB

Step3. The DB_UNIQUE_NAME values of the primary and standby database should be used in the DG_CONFIG setting of the LOG_ARCHIVE_CONFIG parameter.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(HCLDB,HCLDB_STBY)';

System altered.

Step4. Set suitable remote archive log destinations.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=HCLDB_STBY NOAFFIRM ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=HCLDB_STBY';

System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;

System altered.

Step5. Set LOG_ARCHIVE_FORMAT and LOG_ARCHIVE_MAX_PROCESSES parameters

SQL> ALTER SYSTEM SET LOG_ARCHIVE_FORMAT='%t_%s_%r.arc' SCOPE=SPFILE;
ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=30;
ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=SPFILE;

Step6. make sure the primary is ready to switch roles to become a standby

SQL> ALTER SYSTEM SET FAL_SERVER=HCLDB_STBY;
ALTER SYSTEM SET DB_FILE_NAME_CONVERT='HCLDB_STBY','HCLDB' SCOPE=SPFILE;
ALTER SYSTEM SET LOG_FILE_NAME_CONVERT='HCLDB_STBY','HCLDB'  SCOPE=SPFILE;
ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;

Step7. Configure tnsnames on both servers.

>>>> tnsnames.ora entry
-------------------------------------------------------------------
HCLDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.195.128)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = HCLDB)
    )
  )

HCLDB_STBY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.195.138)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = HCLDB_STBY)

    )
  )
-----------------------------------------------------------------------------

>>>>> listener.ora entry at Primary
------------------------------------------------------------------------------
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = HCLDB)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
      (SID_NAME = HCLDB)
    )
  )


LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.195.128)(PORT = 1521))
  )
-----------------------------------------------------------------------------------

>>>>>listener.ora entry at Standby
-------------------------------------------------------------------------------------
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = HCLDB_STBY)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
      (SID_NAME = HCLDB_STBY)
    )
  )


LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.195.138)(PORT = 1521))
  )
---------------------------------------------------------------------------------------

Start listenter on both servers and confirm with tnsping

Step8. Copy the Primary DB init file (initHCLDB) to Standby server and rename the init file to initHCLDB_STBY

scp oracle@192.168.195.128:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initHCLDB.ora /u01/app/oracle/product/11.2.0/dbhome_1/dbs/
cp initHCLDB.ora initHCLDB_STBY.ora

Step9. Create orapwd file at Standby DB
orapwd file=orapwHCLDB_STBY password=oracle entries=10

Step10. Connect to Standby server and start in NOMOUNT stage

[oracle@localhost dbs]$ . oraenv
ORACLE_SID = [HCLDB_STBY] ?
ORACLE_HOME = [/home/oracle] ? /u01/app/oracle/product/11.2.0/dbhome_1/
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1/ is /u01/app/oracle
[oracle@localhost dbs]$ sqlplus sys/oracle@HCLDB_STBY as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Thu Jan 31 16:09:45 2013

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

Connected to an idle instance.

SQL> startup nomount;
ORACLE instance started.

Total System Global Area  631914496 bytes
Fixed Size                  1338364 bytes
Variable Size             377488388 bytes
Database Buffers          247463936 bytes
Redo Buffers                5623808 bytes
SQL>

Step11. Connect to RMAN, specifying a full connect string for both the TARGET and AUXILLARY instances.

[oracle@localhost dbs]$ rman TARGET sys/oracle@HCLDB AUXILIARY sys/oracle@HCLDB_STBY

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Jan 31 16:10:50 2013

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

connected to target database: HCLDB (DBID=627848795)
connected to auxiliary database: HCLDB (not mounted)

RMAN> DUPLICATE TARGET DATABASE
  FOR STANDBY
  FROM ACTIVE DATABASE
  DORECOVER
  SPFILE
    SET db_unique_name='HCLDB_STBY' COMMENT 'Is standby'
    SET LOG_ARCHIVE_DEST_2='SERVICE=HCLDB ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=HCLDB'
    SET FAL_SERVER='HCLDB' COMMENT 'Is primary'
  NOFILENAMECHECK;2> 3> 4> 5> 6> 7> 8> 9>

Starting Duplicate Db at 31-JAN-13
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 device type=DISK

contents of Memory Script:
{
   backup as copy reuse
   targetfile  '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwHCLDB' auxiliary format
 '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwHCLDB_STBY'   targetfile
 '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileHCLDB.ora' auxiliary format
 '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileHCLDB_STBY.ora'   ;
   sql clone "alter system set spfile= ''/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileHCLDB_STBY.ora''";
}
executing Memory Script

Starting backup at 31-JAN-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=87 device type=DISK
Finished backup at 31-JAN-13

sql statement: alter system set spfile= ''/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileHCLDB_STBY.ora''

contents of Memory Script:
{
   sql clone "alter system set  db_unique_name =
 ''HCLDB_STBY'' comment=
 ''Is standby'' scope=spfile";
   sql clone "alter system set  LOG_ARCHIVE_DEST_2 =
 ''SERVICE=HCLDB ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=HCLDB'' comment=
 '''' scope=spfile";
   sql clone "alter system set  FAL_SERVER =
 ''HCLDB'' comment=
 ''Is primary'' scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

sql statement: alter system set  db_unique_name =  ''HCLDB_STBY'' comment= ''Is standby'' scope=spfile

sql statement: alter system set  LOG_ARCHIVE_DEST_2 =  ''SERVICE=HCLDB ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=HCLDB'' comment= '''' scope=spfile

sql statement: alter system set  FAL_SERVER =  ''HCLDB'' comment= ''Is primary'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     631914496 bytes

Fixed Size                     1338364 bytes
Variable Size                377488388 bytes
Database Buffers             247463936 bytes
Redo Buffers                   5623808 bytes

contents of Memory Script:
{
   backup as copy current controlfile for standby auxiliary format  '/u01/app/oracle/oradata/HCLDB/control01.ctl';
   restore clone controlfile to  '/u01/app/oracle/flash_recovery_area/HCLDB/control02.ctl' from
 '/u01/app/oracle/oradata/HCLDB/control01.ctl';
}
executing Memory Script

Starting backup at 31-JAN-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying standby control file
output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_HCLDB.f tag=TAG20130131T161147 RECID=1 STAMP=806170309
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 31-JAN-13

Starting restore at 31-JAN-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 device type=DISK

channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 31-JAN-13

contents of Memory Script:
{
   sql clone 'alter database mount standby database';
}
executing Memory Script

sql statement: alter database mount standby database
RMAN-05538: WARNING: implicitly using DB_FILE_NAME_CONVERT

contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/oradata/HCLDB/temp01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/HCLDB/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/HCLDB/sysaux01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/HCLDB/undotbs01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/HCLDB/users01.dbf";
   backup as copy reuse
   datafile  1 auxiliary format
 "/u01/app/oracle/oradata/HCLDB/system01.dbf"   datafile
 2 auxiliary format
 "/u01/app/oracle/oradata/HCLDB/sysaux01.dbf"   datafile
 3 auxiliary format
 "/u01/app/oracle/oradata/HCLDB/undotbs01.dbf"   datafile
 4 auxiliary format
 "/u01/app/oracle/oradata/HCLDB/users01.dbf"   ;
   sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/HCLDB/temp01.dbf in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 31-JAN-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/HCLDB/system01.dbf
output file name=/u01/app/oracle/oradata/HCLDB/system01.dbf tag=TAG20130131T161159
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/HCLDB/sysaux01.dbf
output file name=/u01/app/oracle/oradata/HCLDB/sysaux01.dbf tag=TAG20130131T161159
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:40
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/HCLDB/undotbs01.dbf
output file name=/u01/app/oracle/oradata/HCLDB/undotbs01.dbf tag=TAG20130131T161159
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/HCLDB/users01.dbf
output file name=/u01/app/oracle/oradata/HCLDB/users01.dbf tag=TAG20130131T161159
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 31-JAN-13

sql statement: alter system archive log current

contents of Memory Script:
{
   backup as copy reuse
   archivelog like  "/u01/app/oracle/flash_recovery_area/HCLDB/archivelog/2013_01_31/o1_mf_1_5_8jnlsxh1_.arc" auxiliary format
 "/u01/app/oracle/flash_recovery_area/HCLDB_STBY/archivelog/2013_01_31/o1_mf_1_5_%u_.arc"   ;
   catalog clone recovery area;
   switch clone datafile all;
}
executing Memory Script

Starting backup at 31-JAN-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=5 RECID=4 STAMP=806170517
output file name=/u01/app/oracle/flash_recovery_area/HCLDB_STBY/archivelog/2013_01_31/o1_mf_1_5_06o0qbsn_.arc RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
Finished backup at 31-JAN-13

searching for all files in the recovery area

List of Files Unknown to the Database
=====================================
File Name: /u01/app/oracle/flash_recovery_area/HCLDB_STBY/archivelog/2013_01_31/o1_mf_1_5_06o0qbsn_.arc
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/flash_recovery_area/HCLDB_STBY/archivelog/2013_01_31/o1_mf_1_5_06o0qbsn_.arc

datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=806170525 file name=/u01/app/oracle/oradata/HCLDB/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=806170525 file name=/u01/app/oracle/oradata/HCLDB/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=806170525 file name=/u01/app/oracle/oradata/HCLDB/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=806170525 file name=/u01/app/oracle/oradata/HCLDB/users01.dbf

contents of Memory Script:
{
   set until scn  786126;
   recover
   standby
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 31-JAN-13
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 5 is already on disk as file /u01/app/oracle/flash_recovery_area/HCLDB_STBY/archivelog/2013_01_31/o1_mf_1_5_06o0qbsn_.arc
archived log file name=/u01/app/oracle/flash_recovery_area/HCLDB_STBY/archivelog/2013_01_31/o1_mf_1_5_06o0qbsn_.arc thread=1 sequence=5
media recovery complete, elapsed time: 00:00:01
Finished recover at 31-JAN-13
Finished Duplicate Db at 31-JAN-13


Step12. Start Apply Process on Standby

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

Database altered.

 Verify the Physical Standby Database Is Performing Properly

--On primary check database protection mode

SQL> SELECT protection_mode,protection_level FROM v$database;

PROTECTION_MODE      PROTECTION_LEVEL
-------------------- --------------------
MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

--On standby:

SQL> alter session set nls_date_format='dd-mm-yyyy hh24:mi:ss';

Session altered.

SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;

 SEQUENCE# FIRST_TIME          NEXT_TIME
---------- ------------------- -------------------
         5 31-01-2013 16:06:14 31-01-2013 16:15:17

-- Verify that received redo has been applied.

SQL> SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;

 SEQUENCE# APPLIED
---------- ---------
         5 YES
         6 YES
         7 YES
         8 YES

--- check alert log of primary and standby


Open in Read Only Mode

-- cancel recovery

ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;


ALTER DATABASE OPEN READ ONLY;


Again Put in Recovery Mode

SHUTDOWN IMMEDIATE

STARTUP MOUNT

ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;



Sunday, January 27, 2013

Step by Step - Duplicating Oracle Database using RMAN Backup with connection to Target database


Step by Step Duplicating Oracle Database using RMAN Backup with connection to Target database:-
Details:

Oracle EE 11.2 on RHEL5
Target Server: 192.168.195.128
Clone Server: 192.168.195.137

As we are duplicating to a different we can use same SID for both Source and Clone. My source DBID is HCL

Step1. Put your target database in Archive log mode.

Step2. Start RMAN at Target and Configure CONTROLFILE AUTOBACKUP ON
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

Take Backup of Target database
RMAN> BACKUP DATABASE PLUS ARCHIVELOG

Step3. Configure tnsnames and listener at source and clone server as below:

At Source Server
--------------------------------------------------------------------
HCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.195.137)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = HCL)
    )
  )
---------------------------------------------------------------------
At Clone Server
----------------------------------------------------------------------
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = HCL)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
      (SID_NAME = HCL)
    )
  )


LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.195.137)(PORT = 1521))
  )
------------------------------------------------------------------------

Step4: create orapwd file at clone server's dbs directory
orapwd file=orapwHCL password=oracle entries=10

Step5. Create pfile of Target database and copy pfile to Clone Server's dbs directory
SQL> create pfile from spfile;

Copy pfile to Clone Server
scp oracle@192.168.195.128:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initHCL.ora /u01/app/oracle/product/11.2.0/dbhome_1/dbs/

Step6. Create required directories at Clone server. Here I'm using same filesystem as source so no need to use DB_FILE_NAME_CONVERT

mkdir -p /u01/app/oracle/oradata/HCL
mkdir -p /u01/app/oracle/flash_recovery_area/HCL
mkdir -p /u01/app/oracle/admin/HCL
cd /u01/app/oracle/admin/HCL
mkdir adump dpdump

Step7. Copy backupfile to Clone Server from Source Server
scp -r oracle@192.168.195.128:/u01/app/oracle/flash_recovery_area/HCL/ /u01/app/oracle/flash_recovery_area/

Step8. At Remote Server set ORACLE_SID=HCL and start the Clone Server in NOMOUNT mode
SQL> STARTUP NOMOUNT;

Step9: start RMAN at source and connect RMAN to clone as well
At Source
RMAN TARGET /
connect auxiliary sys/oracle@HCL

***Make sure your Souce Database is in OPEN mode and Clone DB is in NOMOUNT Mode

Now run the Duplicate command # See the response as well

RMAN> DUPLICATE TARGET DATABASE TO HCL
NOFILENAMECHECK;2>

Starting Duplicate Db at 27-JAN-13
using channel ORA_AUX_DISK_1

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''HCL'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''HCL'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone primary controlfile;
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''HCL'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''HCL'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area     631914496 bytes

Fixed Size                     1338364 bytes
Variable Size                377488388 bytes
Database Buffers             247463936 bytes
Redo Buffers                   5623808 bytes

Starting restore at 27-JAN-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=18 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/HCL/autobackup/2013_01_27/o1_mf_s_805812962_8j9onctk_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/HCL/autobackup/2013_01_27/o1_mf_s_805812962_8j9onctk_.bkp tag=TAG20130127T125602
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/u01/app/oracle/oradata/HCL/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/HCL/control02.ctl
Finished restore at 27-JAN-13

database mounted

contents of Memory Script:
{
   set until scn  763666;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/HCL/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/HCL/sysaux01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/HCL/undotbs01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/HCL/users01.dbf";
   restore
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 27-JAN-13
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/HCL/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/HCL/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/HCL/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/HCL/users01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/HCL/backupset/2013_01_27/o1_mf_nnndf_TAG20130127T125432_8j9okjyl_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/HCL/backupset/2013_01_27/o1_mf_nnndf_TAG20130127T125432_8j9okjyl_.bkp tag=TAG20130127T125432
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:22
Finished restore at 27-JAN-13

contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=805814774 file name=/u01/app/oracle/oradata/HCL/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=805814774 file name=/u01/app/oracle/oradata/HCL/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=805814774 file name=/u01/app/oracle/oradata/HCL/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=805814774 file name=/u01/app/oracle/oradata/HCL/users01.dbf

contents of Memory Script:
{
   set until scn  763666;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 27-JAN-13
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 4 is already on disk as file /u01/app/oracle/flash_recovery_area/HCL/archivelog/2013_01_27/o1_mf_1_4_8j9on8j1_.arc
archived log file name=/u01/app/oracle/flash_recovery_area/HCL/archivelog/2013_01_27/o1_mf_1_4_8j9on8j1_.arc thread=1 sequence=4
media recovery complete, elapsed time: 00:00:00
Finished recover at 27-JAN-13

contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
   sql clone "alter system set  db_name =
 ''HCL'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     631914496 bytes

Fixed Size                     1338364 bytes
Variable Size                377488388 bytes
Database Buffers             247463936 bytes
Redo Buffers                   5623808 bytes

sql statement: alter system set  db_name =  ''HCL'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system reset  db_unique_name scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     631914496 bytes

Fixed Size                     1338364 bytes
Variable Size                377488388 bytes
Database Buffers             247463936 bytes
Redo Buffers                   5623808 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "HCL" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1  SIZE 50 M ,
  GROUP  2  SIZE 50 M ,
  GROUP  3  SIZE 50 M
 DATAFILE
  '/u01/app/oracle/oradata/HCL/system01.dbf'
 CHARACTER SET WE8MSWIN1252


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/oradata/HCL/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/HCL/sysaux01.dbf",
 "/u01/app/oracle/oradata/HCL/undotbs01.dbf",
 "/u01/app/oracle/oradata/HCL/users01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/HCL/temp01.dbf in control file

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/HCL/sysaux01.dbf RECID=1 STAMP=805814812
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/HCL/undotbs01.dbf RECID=2 STAMP=805814812
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/HCL/users01.dbf RECID=3 STAMP=805814812

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=805814812 file name=/u01/app/oracle/oradata/HCL/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=805814812 file name=/u01/app/oracle/oradata/HCL/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=805814812 file name=/u01/app/oracle/oradata/HCL/users01.dbf

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 27-JAN-13

RMAN>





Friday, January 18, 2013

RMAN : Recovery of a dropped tablespace


If a tablespace has been dropped, 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.

Step 1. Lets create a tablespace droptest first.
SQL> create tablespace droptest datafile '/u01/app/oracle/oradata/HCL/droptest01.dbf' size 50m;

Tablespace created.

Step 2. Delete this tablespace including contents and datafiles.
SQL> drop tablespace droptest including contents and datafiles;

Tablespace dropped.

Step 3. Now try to recover the dropped tablespace using RMAN
RMAN> recover tablespace droptest;

Starting recover at 18-JAN-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=43 device type=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/18/2013 20:43:24
RMAN-20202: Tablespace not found in the recovery catalog
RMAN-06019: could not translate tablespace name "DROPTEST"

RMAN>
See the error - RMAN-20202: Tablespace not found in the recovery catalog

Step 4. So to recover the 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 the outage of the entire database and the entire database will be rolled back in tine in order to recover the tablespace.The second option can be peformed online, but we will need to factor in the disk space requirements to create a clone of the database from which the tablespace has been dropped.

Step 5. Lets create the same tablespace again and take a full backup of database including controlfile.

SQL> create tablespace droptest datafile '/u01/app/oracle/oradata/HCL/droptest01.dbf' size 50m;

Tablespace created.

Take full backup.

RMAN> backup database plus archivelog;

Drop the tablespace DROPTEST again and we will recover it as below.

Step 6. Start the database in nomount stage and restore the controlfile from backup.
SQL> startup nomount
ORACLE instance started.

Total System Global Area  631914496 bytes
Fixed Size                  1338364 bytes
Variable Size             394265604 bytes
Database Buffers          230686720 bytes
Redo Buffers                5623808 bytes

Step 7. Next We need to restore controlfile from backup which contains metadata of tablespace DROPTEST.

RMAN> restore controlfile from autobackup;

Starting restore at 18-JAN-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=17 device type=DISK

recovery area destination: /u01/app/oracle/flash_recovery_area
database name (or database unique name) used for search: HCL
channel ORA_DISK_1: AUTOBACKUP /u01/app/oracle/flash_recovery_area/HCL/autobackup/2013_01_18/o1_mf_s_805064205_8hltfpnt_.bkp found in the recovery area
AUTOBACKUP search with format "%F" not attempted because DBID was not set
channel ORA_DISK_1: restoring control file from AUTOBACKUP /u01/app/oracle/flash_recovery_area/HCL/autobackup/2013_01_18/o1_mf_s_805064205_8hltfpnt_.bkp
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
output file name=/u01/app/oracle/oradata/HCL/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/HCL/control02.ctl
Finished restore at 18-JAN-13

Now restored controlfile contains the metadata of dropped Tablespace DROPTEST.

RMAN> report schema;

------

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    670      SYSTEM               ***     /u01/app/oracle/oradata/HCL/system01.dbf
2    450      SYSAUX               ***     /u01/app/oracle/oradata/HCL/sysaux01.dbf
3    30       UNDOTBS1             ***     /u01/app/oracle/oradata/HCL/undotbs01.dbf
4    5        USERS                ***     /u01/app/oracle/oradata/HCL/users01.dbf
5    0        DROPTEST             ***     /u01/app/oracle/oradata/HCL/droptest01.dbf
6    20       TEMP                 32767   /u01/app/oracle/oradata/HCL/temp01.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    20       TEMP                 32767       /u01/app/oracle/oradata/HCL/temp01.dbf



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

Fri Jan 18 21:01:20 2013
drop tablespace droptest including contents and datafiles
Deleted file /u01/app/oracle/oradata/HCL/droptest01.dbf
Completed: drop tablespace droptest including contents and datafiles

Step 7.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 {
set until time "to_date('18-JAN-2013 21:01:00','DD-MON-YYYY HH24:Mi:SS')";
restore database;
recover database;
}
2> 3> 4> 5>
executing command: SET until clause

Starting restore at 18-JAN-13
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/HCL/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/HCL/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/HCL/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/HCL/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/HCL/droptest01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/HCL/backupset/2013_01_18/o1_mf_nnndf_TAG20130118T205505_8hltbl5x_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/HCL/backupset/2013_01_18/o1_mf_nnndf_TAG20130118T205505_8hltbl5x_.bkp tag=TAG20130118T205505
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:28
Finished restore at 18-JAN-13

Starting recover at 18-JAN-13
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 2 is already on disk as file /u01/app/oracle/flash_recovery_area/HCL/archivelog/2013_01_18/o1_mf_1_2_8hltfmh8_.arc
archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oracle/oradata/HCL/redo03.log
archived log file name=/u01/app/oracle/flash_recovery_area/HCL/archivelog/2013_01_18/o1_mf_1_2_8hltfmh8_.arc thread=1 sequence=2
archived log file name=/u01/app/oracle/oradata/HCL/redo03.log thread=1 sequence=3
media recovery complete, elapsed time: 00:00:01
Finished recover at 18-JAN-13

RMAN> alter database open resetlogs;

database opened

Step 8 Now check the the restored tablespace.

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

FILE_NAME                                               BYTES
-------------------------------------------------- ----------
/u01/app/oracle/oradata/HCL/droptest01.dbf           52428800





RMAN 'Duplicate From Active Database'

Metalink notes - RMAN 'Duplicate From Active Database' Feature in 11G [ID 452868.1]

***Active database duplication Method***

Target Database- HCL
Auxiliary Database- AUX

Step1. Create a pfile for AUX database and create the required directory as well.

db_name='AUX'
diagnostic_dest='/u01/app/oracle'
DB_FILE_name_CONVERT=('/u01/app/oracle/oradata/HCL','/u01/app/oracle/oradata/AUX') 
LOG_FILE_NAME_CONVERT=( '/u01/app/oracle/oradata/HCL','/u01/app/oracle/oradata/AUX')
sga_target=377487360
control_files='/u01/app/oracle/oradata/AUX/control01.ctl'
compatible='11.2.0.0.0'

Step2. Create password file for Auxilary database

orapwd file=orapwAUX password=oracle entries=10

Step3. Configure Listener on Aux
====================================================
SID_LIST_LISTENER = 
  (SID_LIST = 
    (SID_DESC = 
      (GLOBAL_DBNAME = AUX) 
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1) 
      (SID_NAME = AUX) 
    ) 
  )


LISTENER = 
  (DESCRIPTION = 
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.195.128)(PORT = 1521)) 
  )
====================================================
Configure Configure Listener on Target
====================================================
SID_LIST_LISTENER = 
  (SID_LIST = 
    (SID_DESC = 
      (GLOBAL_DBNAME = HCL) 
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1) 
      (SID_NAME = HCL) 
    ) 
  )


LISTENER = 
  (DESCRIPTION = 
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.195.134)(PORT = 1521)) 
  )
===========================================================

Configure tnsname.ora (In the TARGET and AUXILIARY host)
=================================================================
AUX = 
  (DESCRIPTION = 
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.195.128)(PORT = 1521)) 
    (CONNECT_DATA = 
      (SERVER = DEDICATED) 
      (SERVICE_NAME = AUX) 
    ) 
  ) 


HCL = 
  (DESCRIPTION = 
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.195.134)(PORT = 1521)) 
    (CONNECT_DATA = 
      (SERVER = DEDICATED) 
      (SERVICE_NAME = HCL)
    ) 
  )
======================================================================
Execute on the TARGET and AUXILIARY host
% tnsping HCL
% tnsping AUX


Step4. Start Auxilary database to nomount stage
SQL> startup nomount pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initAUX.ora';
ORACLE instance started.

Total System Global Area  376635392 bytes
Fixed Size                  1336652 bytes
Variable Size             121637556 bytes
Database Buffers          247463936 bytes
Redo Buffers                6197248 bytes
SQL> exit

Step.5 
Start RMAN to connect both DB Instances

RMAN> connect target sys/oracle@HCL

connected to target database: HCL (DBID=931429395)

RMAN> connect AUXILIARY sys/oracle@AUX

connected to auxiliary database: AUX (not mounted)

RMAN> 
=================

DUPLICATE TARGET DATABASE TO 'AUX' FROM ACTIVE DATABASE DB_FILE_NAME_CONVERT '/u01/app/oracle/oradata/HCL','/u01/app/oracle/oradata/AUX';

See output below

RMAN> DUPLICATE TARGET DATABASE TO 'AUX' FROM ACTIVE DATABASE DB_FILE_NAME_CONVERT '/u01/app/oracle/oradata/HCL','/u01/app/oracle/oradata/AUX';

Starting Duplicate Db at 13-JAN-13
using channel ORA_AUX_DISK_1

contents of Memory Script:
{
   sql clone "create spfile from memory";
}
executing Memory Script

sql statement: create spfile from memory

contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     376635392 bytes

Fixed Size                     1336652 bytes
Variable Size                125831860 bytes
Database Buffers             243269632 bytes
Redo Buffers                   6197248 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''HCL'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name = 
 ''AUX'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   backup as copy current controlfile auxiliary format  '/u01/app/oracle/oradata/AUX/control01.dbf';
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''HCL'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''AUX'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area     376635392 bytes

Fixed Size                     1336652 bytes
Variable Size                125831860 bytes
Database Buffers             243269632 bytes
Redo Buffers                   6197248 bytes

Starting backup at 13-JAN-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=39 device type=DISK
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_HCL.f tag=TAG20130113T173439 RECID=7 STAMP=804620080
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 13-JAN-13

database mounted

contents of Memory Script:
{
   set newname for datafile  1 to 
 "/u01/app/oracle/oradata/AUX/system01.dbf";
   set newname for datafile  2 to 
 "/u01/app/oracle/oradata/AUX/sysaux01.dbf";
   set newname for datafile  3 to 
 "/u01/app/oracle/oradata/AUX/undotbs01.dbf";
   set newname for datafile  4 to 
 "/u01/app/oracle/oradata/AUX/users01.dbf";
   backup as copy reuse
   datafile  1 auxiliary format 
 "/u01/app/oracle/oradata/AUX/system01.dbf"   datafile 
 2 auxiliary format 
 "/u01/app/oracle/oradata/AUX/sysaux01.dbf"   datafile 
 3 auxiliary format 
 "/u01/app/oracle/oradata/AUX/undotbs01.dbf"   datafile 
 4 auxiliary format 
 "/u01/app/oracle/oradata/AUX/users01.dbf"   ;
   sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 13-JAN-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/HCL/system01.dbf
output file name=/u01/app/oracle/oradata/AUX/system01.dbf tag=TAG20130113T173446
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/HCL/sysaux01.dbf
output file name=/u01/app/oracle/oradata/AUX/sysaux01.dbf tag=TAG20130113T173446
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:39
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/HCL/undotbs01.dbf
output file name=/u01/app/oracle/oradata/AUX/undotbs01.dbf tag=TAG20130113T173446
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/HCL/users01.dbf
output file name=/u01/app/oracle/oradata/AUX/users01.dbf tag=TAG20130113T173446
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 13-JAN-13

sql statement: alter system archive log current

contents of Memory Script:
{
   backup as copy reuse
   archivelog like  "/u01/app/oracle/flash_recovery_area/HCL/archivelog/2013_01_13/o1_mf_1_3_8h58tfxh_.arc" auxiliary format 
 "/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_3_804600981.dbf"   ;
   catalog clone archivelog  "/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_3_804600981.dbf";
   switch clone datafile all;
}
executing Memory Script

Starting backup at 13-JAN-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=3 RECID=2 STAMP=804620197
output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_3_804600981.dbf RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
Finished backup at 13-JAN-13

cataloged archived log
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_3_804600981.dbf RECID=2 STAMP=804620199

datafile 1 switched to datafile copy
input datafile copy RECID=7 STAMP=804620199 file name=/u01/app/oracle/oradata/AUX/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=8 STAMP=804620199 file name=/u01/app/oracle/oradata/AUX/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=9 STAMP=804620199 file name=/u01/app/oracle/oradata/AUX/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=10 STAMP=804620199 file name=/u01/app/oracle/oradata/AUX/users01.dbf

contents of Memory Script:
{
   set until scn  768903;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 13-JAN-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 device type=DISK

starting media recovery

archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_3_804600981.dbf
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_3_804600981.dbf thread=1 sequence=3
media recovery complete, elapsed time: 00:00:01
Finished recover at 13-JAN-13

contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
   sql clone "alter system set  db_name = 
 ''AUX'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     376635392 bytes

Fixed Size                     1336652 bytes
Variable Size                125831860 bytes
Database Buffers             243269632 bytes
Redo Buffers                   6197248 bytes

sql statement: alter system set  db_name =  ''AUX'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system reset  db_unique_name scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     376635392 bytes

Fixed Size                     1336652 bytes
Variable Size                125831860 bytes
Database Buffers             243269632 bytes
Redo Buffers                   6197248 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "AUX" RESETLOGS ARCHIVELOG 
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/u01/app/oracle/oradata/AUX/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/u01/app/oracle/oradata/AUX/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/u01/app/oracle/oradata/AUX/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/AUX/system01.dbf'
 CHARACTER SET WE8MSWIN1252


contents of Memory Script:
{
   set newname for tempfile  1 to 
 "/u01/app/oracle/oradata/AUX/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/AUX/sysaux01.dbf", 
 "/u01/app/oracle/oradata/AUX/undotbs01.dbf", 
 "/u01/app/oracle/oradata/AUX/users01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/AUX/temp01.dbf in control file

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/AUX/sysaux01.dbf RECID=1 STAMP=804620218
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/AUX/undotbs01.dbf RECID=2 STAMP=804620218
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/AUX/users01.dbf RECID=3 STAMP=804620218

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=804620218 file name=/u01/app/oracle/oradata/AUX/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=804620218 file name=/u01/app/oracle/oradata/AUX/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=804620218 file name=/u01/app/oracle/oradata/AUX/users01.dbf

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 13-JAN-13

RMAN>