Friday, November 30, 2012

CLONING OF DATABASE BY RMAN



                                             CLONING OF DATABASE BY RMAN

1) PRIMIARYDATABASE NAME: PROD (172.16.1.145)
2) DUPLICATEDATABASE NAME: DUP (172.16.1.142)

------------------------------------------------------------------------------------------------------------

STEPS1: CONFIGURE THE TNSNAMES.ORA IN PRIMARY:
TO_DUP =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.1.142)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = dup)
)
)

------------------------------------------------------------------------------------------------------------

STEPS2: CONFIGURE THE LISTNER.ORA IN TARGET SIDE:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = dup)
(ORACLE_HOME = /oracle/app/oracle/product/10.2.0)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = RHEL)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)

------------------------------------------------------------------------------------------------------------

STEP3 : create password file in duplicate database side
$] $ORACLE_HOME/dbs/orapwd file=orapwdup password=oracle123 entries=5 force=y

------------------------------------------------------------------------------------------------------------

STEP4: COPY intiprod.ora from primary to standby database.
Dbs]$ Scp initprod.ora 172.16.1.142:$ORACLE_HOME/dbs

------------------------------------------------------------------------------------------------------------

STEP5: rename the initprod to initdup.ora in duplicate database.
Dbs]$ mv initprod.ora initdup.ora

------------------------------------------------------------------------------------------------------------

STEP 6: create new folder in primary as well as duplicate databases.
]$ Mkdir /oracle/backup_file

------------------------------------------------------------------------------------------------------------

SETP7: ASSIGN THE LOCATION OF BACKUP FILE IN RMAN PARAMETER AND ALSO CHANGE
CONTROLFILE AUTO BACKUP TO ON
RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/oracle/backup_files/prod_backup_%U';
RMAN>CONFIGURE CONTROLFILE AUTOBACKUP ON;

------------------------------------------------------------------------------------------------------------

STEP8: create the required folders according the initdup.ora file

------------------------------------------------------------------------------------------------------------

STEP9:
Include db_file_name_convert and log_file_name_convert parameters in initdup .ora file to avoid
the duplication of data files.
Db_file_name_convert=(‘/oracle/app/oracle/oradata/prod’,’/oracle/app/oracle/oradata/dup’)
Log_file_name_convert=(‘/oracle/app/oracle/oradata/prod’,’/oracle/app/oracle/oradata/dup’)

------------------------------------------------------------------------------------------------------------

STEP10: start the duplicate database in nomount stage
SQL> startup nomount
ORACLE instance started.
Total System Global Area 377487360 bytes
Fixed Size 1219520 bytes
Variable Size 113247296 bytes
Database Buffers 260046848 bytes
Redo Buffers 2973696 bytes

------------------------------------------------------------------------------------------------------------

SETP11: GO TO PRIMARY DATABASE TAKE THE BACKUP OF PRIMARY DATABASE
RMAN> BACKUP DATABAE PLUS ARCHIVELOG

------------------------------------------------------------------------------------------------------------

SETP12: THIS BACKUP WILL STORE IN FILE /ORACLE/BACKUP_FILES FOLDER OF PRIMARY DATABASE.

------------------------------------------------------------------------------------------------------------

STEP13: COPT THIS BACKUP TO THE DUPLICATE DATABASE IN THE LOCATION
/ORACLE/BACKUP_FILES:
/ORACLE/BACKUP_FILE$] SCP * 172.16.1.142:/ORCALE/BACKUP_FILES

------------------------------------------------------------------------------------------------------------

STEP 14: NOW GO TO RMAN IN PRIMARY SIDE
$] RMAN TARGET /
STEP 15: GIVE THE AUXILIARY COMMAND SO THAT IT CONNECT DUPLICATE DATABASE
RMAN> connect auxiliary sys/oracle123@to_dup

------------------------------------------------------------------------------------------------------------

STEP16: give the duplicate command so the all the primary database data will transfer to duplicate
database remotely.
Rman>Duplicate target database to ‘dup’;

------------------------------------------------------------------------------------------------------------

duplicate target DATABASE TO ‘dup’;
Starting Duplicate Db at 03-OCT-11
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=36 devtype=DISK
contents OF Memory Script:
{
SET until scn 550170;
SET newname FOR datafile 1 TO "/u01/oracle/dup/system01.dbf";
SET newname FOR datafile 2 TO "/u01/oracle/dup/undotbs01.dbf";
SET newname FOR datafile 3 TO "/u01/oracle/dup/sysaux01.dbf";
SET newname FOR datafile 4 TO "/u01/oracle/dup/users01.dbf";
restore
CHECK readonly
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 03-OCT-11
USING channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) TO restore FROM backup SET
restoring datafile 00001 TO /u01/oracle/dup/system01.dbf
restoring datafile 00002 TO /u01/oracle/dup/undotbs01.dbf
restoring datafile 00003 TO /u01/oracle/dup/sysaux01.dbf
restoring datafile 00004 TO /u01/oracle/dup/users01.dbf
channel ORA_AUX_DISK_1: reading FROM backup piece
/u01/oracle/fra/PROD/backupset/2011_10_03/o1_mf_nnndf_TAG20111003T101143_78lh8804_.bk
p
channel ORA_AUX_DISK_1: restored backup piece 1
piece
handle=/u01/oracle/fra/PROD/backupset/2011_10_03/o1_mf_nnndf_TAG20111003T101143_78lh8
804_.bkp tag=TAG20111003T101143
channel ORA_AUX_DISK_1: restore complete, elapsed TIME: 00:00:26
Finished restore at 03-OCT-11
SQL statement:
CREATE CONTROLFILE REUSE SET DATABASE "dup" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/u01/oracle/dup/redo01.log' ) SIZE 50 M REUSE,
GROUP 2 ( '/u01/oracle/dup/redo02.log' ) SIZE 50 M REUSE,
GROUP 3 ( '/u01/oracle/dup/redo03.log' ) SIZE 50 M REUSE
DATAFILE '/u01/oracle/dup/system01.dbf'
CHARACTER SET WE8ISO8859P1
contents OF Memory Script:
{
switch clone datafile ALL;
}
executing Memory Script
released channel: ORA_AUX_DISK_1
datafile 2 switched TO datafile copy
INPUT datafile copy recid=1 stamp=763553748 filename=/u01/oracle/dup/undotbs01.dbf
datafile 3 switched TO datafile copy
INPUT datafile copy recid=2 stamp=763553748 filename=/u01/oracle/dup/sysaux01.dbf
datafile 4 switched TO datafile copy
INPUT datafile copy recid=3 stamp=763553748 filename=/u01/oracle/dupdb/users01.dbf
contents OF Memory Script:
{
SET until scn 550170;
recover
clone DATABASE
DELETE archivelog;
}
executing Memory Script
executing command: SET until clause
Starting recover at 03-OCT-11
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=39 devtype=DISK
starting media recovery
archive log thread 1 SEQUENCE 2 IS already ON disk AS file
/u01/oracle/fra/PROD/archivelog/2011_10_03/o1_mf_1_2_78lh92ok_.arc
archive log filename=/u01/oracle/fra/PROD/archivelog/2011_10_03/o1_mf_1_2_78lh92ok_.arc
thread=1 SEQUENCE=2
media recovery complete, elapsed TIME: 00:00:02
Finished recover at 03-OCT-11
contents OF Memory Script:
{
shutdown clone;
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 524288000 bytes
Fixed SIZE 1220384 bytes
Variable SIZE 226492640 bytes
DATABASE Buffers 289406976 bytes
Redo Buffers 7168000 bytes
SQL statement: CREATE CONTROLFILE REUSE SET DATABASE "dup" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/u01/oracle/dup/redo01.log' ) SIZE 50 M REUSE,
GROUP 2 ( '/u01/oracle/dup/redo02.log' ) SIZE 50 M REUSE,
GROUP 3 ( '/u01/oracle/dup/redo03.log' ) SIZE 50 M REUSE
DATAFILE '/u01/oracle/dup/system01.dbf'
CHARACTER SET WE8ISO8859P1
contents OF Memory Script:
{
SET newname FOR tempfile 1 TO "/u01/oracle/dup/temp01.dbf";
switch clone tempfile ALL;
catalog clone datafilecopy "/u01/oracle/dup/undotbs01.dbf";
catalog clone datafilecopy "/u01/oracle/dup/sysaux01.dbf";
catalog clone datafilecopy "/u01/oracle/dup/users01.dbf";
switch clone datafile ALL;
}
executing Memory Script
executing command: SET NEWNAME
renamed TEMPORARY file 1 TO /u01/oracle/dup/temp01.dbf IN control file
cataloged datafile copy
datafile copy filename=/u01/oracle/dup/undotbs01.dbf recid=1 stamp=763553756
cataloged datafile copy
datafile copy filename=/u01/oracle/dup/sysaux01.dbf recid=2 stamp=763553756
cataloged datafile copy
datafile copy filename=/u01/oracle/dup/users01.dbf recid=3 stamp=763553756
datafile 2 switched TO datafile copy
INPUT datafile copy recid=1 stamp=763553756 filename=/u01/oracle/dup/undotbs01.dbf
datafile 3 switched TO datafile copy
INPUT datafile copy recid=2 stamp=763553756 filename=/u01/oracle/dup/sysaux01.dbf
datafile 4 switched TO datafile copy
INPUT datafile copy recid=3 stamp=763553756 filename=/u01/oracle/dup/users01.dbf
contents OF Memory Script:
{
ALTER clone DATABASE OPEN resetlogs;
}
executing Memory Script
DATABASE opened
Finished Duplicate Db at 30-MAY-12


                                                                                                       Prepared by anand.j


Thursday, October 4, 2012

ORA-39082 "..CREATE WITH COMPILATION WARNINGS"WHILE IMPORTING



ORA-39082 ".... created with compilation warnings" while Importing

. . imported "CLEPROD"."SCM_CORRECT_RESPONSE_SECOND"                 0 KB       0 rows
. . imported "CLEPROD"."SCM_GLOBAL_OBJECTIVE"                                        0 KB       0 rows
. . imported "CLEPROD"."SCM_GLOBAL_OBJ_PROGRESS_INFO"               0 KB       0 rows
. . imported "CLEPROD"."SCM_INTERACTION"                                                    0 KB       0 rows
. . imported "CLEPROD"."SCM_LEARNER_RESPONSE"                                     0 KB       0 rows
. . imported "CLEPROD"."SCM_LEARNER_RESPONSE_FIRST"                       0 KB       0 rows
. . imported "CLEPROD"."SCM_OBJECTIVE_PROGRESS_INFO"                    0 KB       0 rows

ORA-39082: Object type TRIGGER:"CLEPROD"."BEF_INS_ENTITYPROPS" created with compilation warnings
ORA-39082: Object type TRIGGER:"CLEPROD"."BEF_INS_ENTITYPROPS" created with compilation warnings
ORA-39082: Object type TRIGGER:"CLEPROD"."BEF_INS_ENTITYTAGAPPS" created with compilation warnings
ORA-39082: Object type TRIGGER:"CLEPROD"."BEF_INS_ENTITYTAGAPPS" created with compilation warnings
Processing object type SCHEMA_EXPORT/TABLE/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/POST_SCHEMA/PROCOBJ
Job "CLEPROD"."SYS_IMPORT_SCHEMA_01" completed with 6 error(s) at 08:39:47


All the above error ORA-30082 is a warning . This error occurs due to improper or re-order the sequence of importing the objects or due to the dependency on others objects . For example  , in above case data pump import create procedures before views, if our procedure have dependency on views then we will have the ORA-39082 compilation errors . There are various ways to solve these issues. 



1.)              Run  utlrp.sql  to recompile all invalid objects within the database after the import is complete. This script is in the $ORACLE_HOME\rdbms\admin  directory or alternatively we can use the built-in  DBMS_RECOMP package . This will usually clean up all the invalid objects. utlrp.sql  will compile objects in the database across schemas. In case of  Re-mapping objects from one schema to another and utlrp.sql  won't be able to compile them .
2.)               After the import is completed, recompile the every errors . This is useful when you have few errors. The below command are used to recompile the objects as 

3.)              SQL> ALTER PACKAGE <SchemaName>.<PackageName> COMPILE;
4.)              SQL> ALTER PACKAGE <SchemaName>.<PackageName> COMPILE BODY;
5.)              SQL> ALTER PROCEDURE my_procedure COMPILE;
6.)              SQL> ALTER FUNCTION my_function COMPILE;
7.)              SQL> ALTER TRIGGER my_trigger COMPILE;
8.)              SQL> ALTER VIEW my_view COMPILE;
9.)              SQL> EXEC DBMS_UTILITY.compile_schema(schema => 'cleprod')
10.)         SQL> EXEC UTL_RECOMP.recomp_serial('cleprod') ;


Monday, July 23, 2012

BASH: SQPLUS COMMAND NOT FOUND


bash: sqlplus: command not found


Oracle S/W is installed on Unix server, but  below error message is there.

[oracle@~]$ sqlplus
-bash: sqlplus: command not found

Solution:
Go to ORACLE_HOME (Path oracle is installed)
[oracle@~]$ cd /opt/oracle/product/11.2.0/
[oracle@ dbhome_1]$ export ORACLE_HOME=/opt/oracle/product/11.2.0
[oracle@dbhome_1]$ cd bin/
[oracle@ bin]$ ./sqlplus

 SQL*Plus: Release 11.2.0.1.0 Production on Tue Oct 11 20:53:19 2011

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

To   fix this add following entries into .bash_profile file at /home/oracle location.

Export ORACLE_HOME=/opt/oracle/product/11.2.0
Export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin

Monday, July 2, 2012

ORA-01919:



ORA-01919:

This example, tested on Oracle 10g , demonstrates the ORA-01919 error message, which some people find misleading. First create a user called ANAND, a role called newrole and another user called ANOTHER_USER

SQL> conn / as sysdba
Connected.
SQL> grant create session to anand
  2  identified by anand
  3  /

Grant succeeded.

SQL> create role newrole
  2  /

Role created.

SQL> create user another_user
  2  identified by another_user
  3  /

User created.

SQL>

Connect as ANAND then try to grant role NEWROLE to ANOTHER_USER. This fails but the error message is not helpful. Role NEWROLE  does exist but it has not been granted to ANAND yet:

SQL> conn anand/anand
Connected.
SQL> grant NEWROLE to another_user
  2  /
grant newrole to another_user
*
ERROR at line 1:
ORA-01919: role 'newrole' does not exist




SQL>

Grant the role NEWROLE to ANAND:

SQL> conn / as sysdba
Connected.
SQL> grant newrole to anand
  2  /

Grant succeeded.

SQL>

Then login as ANAND and try to grant NEWROLE to ANOTHER_USER again. This time the error message gives a better explanation:

SQL> conn anand/anand
Connected.
SQL> grant newrole to another_user
  2  /
grant blah to another_user
*
ERROR at line 1:
ORA-01932: ADMIN option not granted for role 'NEWROLE’

SQL>

Now grant the role to ANAND with the ADMIN option:

SQL> conn / as sysdba
Connected.
SQL> grant newrole  to anand with admin option
  2  /

Grant succeeded.

SQL>

Login as ANAND again. This time the GRANT statement works:

SQL> conn anand/anand
Connected.
SQL> grant newrole to another_user
  2  /

Grant succeeded.

SQL>

Thursday, June 28, 2012

IMPORT THE DATA WITHOUT EXPORTING ,DIRECTLY IMPORTING BY USING IMPDP


1   )   Importing the data from remotely without taking the export by database link :
Steps:
   Remote side :
·         Create a new user name called <prod>
Sql> Create user prod identified by prod;
·         Grant connect, resource ,dba   , imp_full_database,  exp_full_database to user prod;
·         Now log into user which we created
Conn prod/prod
·         Now create a db link
Create database link  <newlink>  connect scott identified by tiger using ‘remotedb’;
·         Now execute the impdb comment
$ ] Impdp prod/prod@testdb network_link=newlink schemas=scott remap_schema=scott:prod
--------------------------------------------------------------------------------------------------------
2)    Exporting data by expdp :

Expdp  username/password  dumpfile=<filename>   logfile=<filename> schemas=<schema name>  directory=<directory name>
For Example:
Expdp  scott/tiger   dumpfile=scott.dmp logfile=scott.log schemas=scott  directory=data


3)    Importing data by impdb:

Impdp username/username dumpfile=<filename> logfile=<filename> remap_schema=<from schema: to schema> directory=<directory name>
            For Example:
          Impdp  prod/prod  dumpfile=scott.dmp logfile=scott1.log remap_schema=scott:prod    schemas=scott