Wednesday, August 7, 2013

RMAN-20001: target database not found in recovery catalog

Error: RMAN-20001: target database not found in recovery catalog

Details: This error occurs when attempting to backup the newly cloned database using RMAN

Cause:The database was not registered with recovery catalog.

Solution:Register the database with recovery catalog by performing the following steps:
  1. Set the environment to your target database:
    > . oraenv
    > DBName
    
  2. Connect to RMAN:
    > rman target /
    
  3. Connect to catalog as rman user:
    RMAN> connect catalog rmanuser/pwd@RMANDB
    
  4. Register target database:
    RMAN> register database;
    

The output will be:
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
Note: The database you are registering must not be a standby database, since standby database gets registered automatically whenever primary database is registered. Also the database must not be already registered in the recovery catalog. List of databases in recovery catalog can be retrieved byt loging in to RMAN repository and runnning:
select name, dbid from rc_database
where name=@DB_SID;

Tuesday, July 9, 2013

Automatic Diagnostic Repository (ADR)

Starting with Oracle 11g R1, traditional *_DUMP_DEST parameters are ignored and the trace location is decided based on DIAGNOSTIC_DEST parameter. If this parameter is not set explicitly, it defaults to ORACLE_BASE environment variable if this is set, if this is not set, then it defaults to ORACLE_HOME/log.

DIAGNOSTIC_DEST is the ADR root directory also known as ADR base.

Each instance's diagnostic data is stored in its own ADR home directory. Under ADR base there are multiple ADR homes. Each ADR home is the root directory for all traces within particular instance.

ADR base/diag
        /rdbms
                /dbname
                            /alerts
                            /cdump
                            /incident
                            /trace


show parameter diag - displays the ADR base

Friday, June 28, 2013

How to import an Oracle database schema to another database with a different schema name

During import, whenever your source schema name is different from target schema name, use REMAP_SCHEMA parameter:
impdp system/pwd dumpfile=sourceschema.dmp directory=DATA_PUMP_DIR schemas=sourceschema logfile=sourceschema_imp.log remap_schema=sourceschema:targetschema

Thursday, June 27, 2013

How to connect to an Oracle database hosted on a different server from ksh script

This can be done two ways, by providing tns string inside the script or by placing it into tnsnames.ora file:
FILE1=output.log
sql="INSERT INTO TABLE1(...)VALUES(...);"
sqlplus 'username/pwd@@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myHostname)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=myDB)))' << EOF > $FILE1
$sql
commit;
exit;
EOF


FILE1=output.log
sql="INSERT INTO TABLE1(...)VALUES(...);"
sqlplus 'username/pwd@DB_ALIAS' << EOF > $FILE1
$sql
commit;
exit;
EOF

Wednesday, June 26, 2013

How to store sqlplus output into a single or multiple variables via ksh script

db_status=`sqlplus -s "/ as sysdba" <<EOF
       set heading off feedback off verify off
       select status from v\$instance;
       exit
EOF`
echo $db_status
The above works for when you want to retrieve a single value. If you want to retrieve multiple values, use:
output=`sqlplus -s "/ as sysdba" <<EOF
       set heading off feedback off verify off
       select host_name, instance_name, status from v\\$instance;
       exit
EOF`

var1=`echo $output | awk '{print $1}'`
var2=`echo $output | awk '{print $2}'`
var3=`echo $output | awk '{print $3}'`
echo $var1
echo $var2
echo $var3
You can also put your sql statement into a file with .sql extension. Something like that:
set head off
set verify off
set feedback off
set pages 0

SELECT field1, field2, field3 
FROM Table1;

exit;
And then read the script values into variables:
sqlplus -s "/ as sysdba" @script2run.sql.sql | read var1 var2 var3

Tuesday, June 25, 2013

Fixing warnings and errors after running impdp

First check the registry to see if the list of invalid objects by running the query below and see which objects have status set to INVALID:
SELECT comp_id, version, status FROM dba_registry;
or simply do:
SELECT COUNT(*) FROM dba_registry WHERE status='INVALID';
If there are any invalid objects, run utlrp script located in which is located in $ORACLE_HOME/rdbms/admin/utlrp.sql. This scrip will recompile inalid objects.
@?/rdbms/admin/utlrp.sql
The line above will run the script.

Next step is to check dba_registry again to see if all invalid objects have been fixed.

Tuesday, June 11, 2013

How to use grep command to exclude the lines beginning with a pattern

For instance when reading from a file you want to exclude all the comments i.e. lines beginning with hash sign (#), then use -v switch for grep command:
grep -v "^\#" $FILENAME