Tuesday, May 10, 2011

Set Newname Flexibility in 11gR2

There   are  some  new  feature  added to  "set newname" command   to  make  it  more  flexible  in  11gR2 .Suppose  we  are restoring   datafiles  from  the  backup,  either on  the  same  server  or  a  different one such  as  staging.  If  the  filesystem  (or diskgroup)  names  are  identifical,  we  won’t have to change anything. But that  is  hardly  ever  the  case.  In  staging  the f ilesystems  may  be  different,  or  perhaps  we  are   restoring a   production  database  to  an  ASM   diskgroup  different  from  where  it  was  originally created.  In  that  case  we  have  to  let  RMAN  know  the  new  name of  the datafile. The  way  to  do  it  is using the SET NEWNAME command. 

Here is an example, we weill restored datafile 1,2  in ‘D’ drive which previous location was in ‘C’ drive . Here is  the rman set newname command .

RMAN> run {
                     set newname for datafile 1 to ‘D:\oradata\system_01.dbf’;
                     set newname for datafile 2 to ‘D:\oradata\sysaux_01.dbf’;
                      restore database;     
               }

Here  there  are  just  two  datafiles, but  what  if  we  have hundreds  or  even thousands ? It will not only be a herculean task to enter all that information but it will be error-prone as well. Instead of entering each datafile by name, now we can use a single set newname clause for a tablespace. Here is how we  can do it:

RMAN> run  {
                         set  newname  for  tablespace  examples  to  'D:\oradata\examples%b.dbf'; 
                        … 
                        … rest of the commands come here … 
              }

If the tablespace has more than one datafile, they will all be uniquely created. We can use this clause for the entire database as well:  
RMAN >  run 
                 {  
                     set newname for database to 'D:\oradata\%b' ; 
                 } 

The   term  %b  specifies  the  base  filename  without  the path,  e.g. ‘C:\oradata\file1.dbf  will be reconsidered  as  file1.dbf  in  %b. This  is  very useful  for  cases  where  we are moving the files to a different  directory. We  can also  use it  for creating image copies where we will create the backup in  a different  ocation  with  the same names as  the  parent  file  which  will  make  it easy  for identification.  Here are some more examples of the placeholders.

%f      ==     is the absolute file number 
%U    ==     is a system generated unique name similar to the  %U in backup formats
%I     ==     is the Database ID
%N   ==     is the tablespace name

Using these placeholders we can use just one SET NEWNAME command for the entire database – making the process not only easy but more accurate as well.                                                                                       



Enjoy        : -) 



How to Drop UNDO Tablespace


It is not an easy task to drop the undo tablespace . Once I have to delete the undo tablespace due to some reason and i  find that it is not straight forward to delete the undo tablespace . I got the following error while dropping the error :

SQL> select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME                FILE_NAME
------------------------------ ---------------------------------------------------------------------
USERS                               D:\ORACLE\ORADATA\NOIDA\USERS01.DBF
UNDOTBS1                       D:\ORACLE\ORADATA\NOIDA\UNDOTBS01.DBF
SYSAUX                             D:\ORACLE\ORADATA\NOIDA\SYSAUX01.DBF
SYSTEM                            D:\ORACLE\ORADATA\NOIDA\SYSTEM01.DBF
EXAMPLE                          D:\ORACLE\ORADATA\NOIDA\EXAMPLE01.DBF

SQL> drop tablespace undotbs1;
drop tablespace undotbs1
*
ERROR at line 1:
ORA-30013: undo tablespace 'UNDOTBS1' is currently in use

As the error indicate that the undo tablespace is in use so i issue the following command.

SQL> alter tablespace undotbs1  offline;
alter tablespace undotbs1  offline
*
ERROR at line 1:
ORA-30042: Cannot offline the undo tablespace.

Therefore, to drop undo  tablespace, we have to perform following steps:

 1.) Create new undo tablespace
 2.) Make it defalut tablepsace and undo management manual by editting parameter file and restart it.
 3.) Check the all segment of old undo tablespace to be offline.
 4.) Drop the old tablespace.
 5.) Change undo management to auto by editting parameter file and restart the database

Step 1 : Create Tablespace   :  Create undo tablespace undotbs2    

SQL> create undo tablespace UNDOTBS2 datafile  'D:\ORACLE\ORADATA\NOIDA\UNDOTBS02.DBF'  size 100M;
Tablespace created.

Step 2 : Edit the parameter file

SQL> alter system set undo_tablespace=UNDOTBS2 ;
System altered.

SQL> alter system set undo_management=MANUAL scope=spfile;
System altered.

SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup
ORACLE instance started.
Total System Global Area  426852352 bytes
Fixed Size                  1333648 bytes
Variable Size             360711792 bytes
Database Buffers           58720256 bytes
Redo Buffers                6086656 bytes
Database mounted.
Database opened.
SQL> show parameter undo_tablespace
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace                      string      UNDOTBS2

Step 3: Check the all segment of old undo tablespace to be offline

SQL> select owner, segment_name, tablespace_name, status from dba_rollback_segs order by 3;

OWNER  SEGMENT_NAME                   TABLESPACE_NAME                STATUS
------ ------------------------------ ------------------------------ ----------------
SYS                 SYSTEM                                     SYSTEM                            ONLINE
PUBLIC       _SYSSMU10_1192467665$          UNDOTBS1                       OFFLINE
PUBLIC        _SYSSMU1_1192467665$           UNDOTBS1                       OFFLINE
PUBLIC        _SYSSMU2_1192467665$           UNDOTBS1                       OFFLINE
PUBLIC        _SYSSMU3_1192467665$           UNDOTBS1                       OFFLINE
PUBLIC        _SYSSMU4_1192467665$           UNDOTBS1                       OFFLINE
PUBLIC        _SYSSMU5_1192467665$           UNDOTBS1                       OFFLINE
PUBLIC        _SYSSMU6_1192467665$           UNDOTBS1                       OFFLINE
PUBLIC        _SYSSMU7_1192467665$           UNDOTBS1                       OFFLINE
PUBLIC        _SYSSMU8_1192467665$           UNDOTBS1                       OFFLINE
PUBLIC        _SYSSMU9_1192467665$           UNDOTBS1                       ONLINE
PUBLIC      _SYSSMU12_1304934663$          UNDOTBS2                        OFFLINE
PUBLIC      _SYSSMU13_1304934663$          UNDOTBS2                        OFFLINE
PUBLIC      _SYSSMU14_1304934663$          UNDOTBS2                        OFFLINE
PUBLIC      _SYSSMU15_1304934663$          UNDOTBS2                        OFFLINE
PUBLIC      _SYSSMU11_1304934663$          UNDOTBS2                        OFFLINE
PUBLIC      _SYSSMU17_1304934663$          UNDOTBS2                        OFFLINE
PUBLIC      _SYSSMU18_1304934663$          UNDOTBS2                        OFFLINE
PUBLIC      _SYSSMU19_1304934663$          UNDOTBS2                        OFFLINE
PUBLIC      _SYSSMU20_1304934663$          UNDOTBS2                        OFFLINE
PUBLIC      _SYSSMU16_1304934663$          UNDOTBS2                        OFFLINE

21 rows selected.

If any one the above segment is online then change it status to offline by using below command . 
SQL>alter rollback segment "_SYSSMU9_1192467665$" offline;

Step 4 : Drop old undo tablespace

SQL> drop tablespace UNDOTBS1 including contents and datafiles;
Tablespace dropped.

Step  5 : Change undo management to auto and restart the database

SQL> alter system set undo_management=auto scope=spfile;
System altered.

SQL> shut immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area  426852352 bytes
Fixed Size                  1333648 bytes
Variable Size             364906096 bytes
Database Buffers           54525952 bytes
Redo Buffers                6086656 bytes
Database mounted.
Database opened.

SQL> show parameter undo_tablespace
NAME                                       TYPE        VALUE
------------------------------------   ----------- ------------------------------
undo_tablespace                      string      UNDOTBS2


Enjoy      J J J


Exclude and Include parameter of Data Pump

The Exclude and Include feature of Data Pump can filter to load/unload certain objects .This so-called 'Metadata filtering' is implemented through the EXCLUDE and INCLUDE parameters.The INCLUDE and EXCLUDE parameters can be used to limit the export/import to specific objects. 

All object types for the given mode of export will be included except those specified in an EXCLUDE statement. If an object is excluded, all of its dependent objects are also excluded. For example, excluding a table will also exclude all indexes and triggers on the table.The name clause must be separated from the object type  with a colon and enclosed in double quotation marks, because single-quotation marks are required to delimit the name strings Double quotes and single quotes usage. 

The EXCLUDE and INCLUDE parameters are mutually exclusive i.e, It is not possible to specify both the INCLUDE parameter and the EXCLUDE parameter in the same job.

The basic syntax for both parameters is the same.

INCLUDE=object_type[:name_clause] [, ...]
EXCLUDE=object_type[:name_clause] [, ...]

Few examples are :

EXCLUDE=SEQUENCE, TABLE:"IN ('EMP', 'DEPT')"
EXCLUDE=INDEX:"= 'MY_INDX'"
INCLUDE=PROCEDURE:"LIKE 'MY_PROC_%'"
INCLUDE=FUNCTION, PACKAGE, TABLE:"= 'EMP'" 
INCLUDE=PROCEDURE:\"=\'PROC1\'\",FUNCTION:\"=\'FUNC1\'\"

To run this job without a parameter file, we need to escape the special characters. Incorrect escaping can result in errors.
for example  :   INCLUDE=TABLE:\"IN \(\'EMP\', \'DEP\'\)\"

To determine which objects are dependent, e.g. for a TABLE, we can run the following query,

SQL> select  named, object_path, comments FROM database_export_objects WHERE object_path LIKE 'TABLE/%';

While Excluding Users specifying EXCLUDE=USER excludes only the definitions of users, not the objects contained within users' schemas. To exclude a specific user and all objects of that user, specify a filter such as the following (where SCOTT is the schema name of the user we want to exclude):
EXCLUDE=SCHEMA:\"='SCOTT'\"
So, we can export as also use below command to execute export .

C:\> expdp system/xxxx directory=datapump dumpfile=expdp_scott.dmp  logfile=expdp_scott.log schemas=scott  INCLUDE=TABLE:\"IN \(SELECT object_name FROM scott.expdp_table WHERE owner=\'SCOTT\' AND object_type=\'TABLE\'\)\"


Enjoy   J J J




Saturday, May 7, 2011

How Data Pump Export Parameters Map to Those of the Original Export Utility

Here are the mapping of Data Pump Export parameters to original Export parameters. In some cases, because of feature redesign, the original Export parameter is no longer needed, so there is no Data Pump parameter to compare it to. Also, some of the parameter names may be the same, but the functionality is slightly different. The parameter are as 


Original Export Parameter
Comparable Data Pump Export Parameter
BUFFER
A parameter comparable to BUFFER is not needed.
COMPRESS
A parameter comparable to COMPRESS is not needed.
CONSISTENT
A parameter comparable to CONSISTENT is not needed. Use FLASHBACK_SCN and FLASHBACK_TIME for this functionality.
CONSTRAINTS
EXCLUDE=CONSTRAINT
DIRECT
A parameter comparable to DIRECT is not needed. Data Pump Export automatically chooses the best method (direct path mode or external tables mode).
FEEDBACK
STATUS
FILE
DUMPFILE
FILESIZE
FILESIZE
FLASHBACK_SCN
FLASHBACK_SCN
FLASHBACK_TIME
FLASHBACK_TIME
FULL
FULL
GRANTS
EXCLUDE=GRANT
HELP
HELP
INDEXES
EXCLUDE=INDEX
LOG
LOGFILE
OBJECT_CONSISTENT
A parameter comparable to OBJECT_CONSISTENT is not needed.
OWNER
SCHEMAS
PARFILE
PARFILE
QUERY
QUERY
RECORDLENGTH
A parameter comparable to RECORDLENGTH is not needed because sizing is done automatically.
RESUMABLE
A parameter comparable to RESUMABLE is not needed. This functionality is automatically provided for users who have been granted the EXP_FULL_DATABASE role.
RESUMABLE_NAME
A parameter comparable to RESUMABLE_NAME is not needed. This functionality is automatically provided for users who have been granted the EXP_FULL_DATABASE role.
RESUMABLE_TIMEOUT
A parameter comparable to RESUMABLE_TIMEOUT is not needed. This functionality is automatically provided for users who have been granted the EXP_FULL_DATABASE role.
ROWS=N
CONTENT=METADATA_ONLY
ROWS=Y
CONTENT=ALL
STATISTICS
A parameter comparable to STATISTICS is not needed. Statistics are always saved for tables.
TABLES
TABLES
TABLESPACES
TABLESPACES (Same parameter; slightly different behavior)
TRANSPORT_TABLESPACE
TRANSPORT_TABLESPACES (Same parameter; slightly different behavior)
TRIGGERS
EXCLUDE=TRIGGER
TTS_FULL_CHECK
TRANSPORT_FULL_CHECK
USERID
A parameter comparable to USERID is not needed. This information is supplied as the username and password when you invoke Export.
VOLSIZE
A parameter comparable to VOLSIZE is not needed.


Enjoy  :-) 

RMAN : Create Script Command


Create Script command is one of the Rman command which is used to stored script in recovery catalog.A stored script may be local or global. A local script is created for the current target database only, whereas a global script is available for use with any database registered in the recovery catalog.
We can use a stored script as an alternative to a command file for managing frequently used sequences of RMAN commands. The script is stored in the recovery catalog rather than on the file system.

The commands allowable within the brackets of the CREATE SCRIPT command are the same commands supported within a RUN block. Any command that is legal within a RUN command is permitted in the stored script.
Here, in this scenario we will perform the following steps :
1.) Create   Script
2.) Replace Script
3.) Execute Script 


Create Script  :  Assume that we want to create a local stored script for backing up database "noida". we start RMAN, connect to "noida" as TARGET, and connect to a recovery catalog. we create a stored script called rman_backup . 


C:\>rman
Recovery Manager: Release 11.1.0.6.0 - Production on Sat May 7 15:15:02 2011
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
RMAN> connect target sys/ramtech@noida
connected to target database: NOIDA (DBID=1503672566)
RMAN> connect catalog  rcat/rcat@catdb
connected to recovery catalog database

RMAN> Create script rman_backup
2> Comment "backup Whole Database and archived redo logs "
3> {
4> backup incremental level 0
5> format "D:\rman_bkp\%U"
6> Database plus archivelog;
7> }


Replace Scripts :  To update stored scripts, we use the REPLACE SCRIPT command. If we are replacing a local script, then we must be connected to the target database that we connected to when we created the script. If the script does not already exist, then RMAN creates it.

RMAN> replace script rman_backup 
{
  backup database plus archivelog  skip inaccessible ;
}
         We can update global scripts by specifying the GLOBAL keyword .

Execute Script :   We use the EXECUTE SCRIPT command to run a stored script. If GLOBAL is specified, then a global script with this name must already exist in the recovery catalog; otherwise, RMAN returns error RMAN-06004. If GLOBAL is not specified, then RMAN searches for a local stored script defined for the current target database. If no local script with this name is found, then RMAN searches for a global script by the same name and executes it if one is found.

To execute a stored script run EXECUTE SCRIPT. This command requires a RUN block, as shown in the following example:


RMAN> run  

  excute script rman_backup; 
}


Enjoy  : -)