Thursday, 22 August 2013

Flashback Drop Table in Oracle 10g

Flashback Table feature in Oracle Database 10g helps to reverses the effects of a DROP 
TABLE operation. Flashback Drop is faster or easier than any other recovery mechanism 
that can be used in that situation.
For example:

This statement places the EMPLOYEE_DEMO table, along with any indexes, constraints, 
or other dependent objects listed previously, in the recycle bin:

SQL> DROP TABLE EMPLOYEE_DEMO;

Table Dropped

Status after Drop:

SQL> Select * from tab;

TNAME TABTYPE CLUSTERID

—————————— ——- ———-

BIN$04LhcpndanfgMAAAAAANPw==$0 TABLE

The dropped table EMPLOYEE_DEMO, instead of completely disappearing, was renamed to a system-defined name. It stays in the same tablespace with the same structure as that of the original table. If there are indexes or triggers defined on the table, they are renamed too, using the same naming convention used by the table. Any dependent sources such as procedures are invalidated; the triggers and indexes of the original table are instead placed on the renamed table BIN$04LhcpndanfgMAAAAAANPw==$0, preserving the complete object structure of the dropped table.

View the object in Recycle Bin:

SQL> show recyclebin

ORIGINAL    NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME

——————————  —————————— ———— ——————

EMPLOYEE_DEMO   BIN$gk3lsj/3akk5hg3j2lkl5j3d==$0 TABLE 2012-05-01:20:17:22

SQL> SELECT object_name as recycle_name, original_name, type FROM recyclebin;

RECYCLE_NAME                      ORIGINAL_NAME          TYPE

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

BIN$gk3lsj/3akk5hg3j2lkl5j3d==$0  EMPLOYEE_DEMO          TABLE

BIN$JKS983293M1dsab4gsz/I249==$0  I_EMP_DEMO             INDEX

BIN$NR72JJN38KM1dsaM4gI348as==$0  LOB_EMP_DEMO           LOB

BIN$JKJ399SLKnaslkJSLK330SIK==$0  LOB_I_EMP_DEMO         LOB INDEX

This shows the original name of the table, EMPLOYEE_DEMO, as well as the new name in the recycle bin, which has the same name as the new table we saw created after the drop.

Note: the exact name may differ by platform.

Reverse the Drop command:

FLASHBACK TABLE "BIN$gk3lsj/3akk5hg3j2lkl5j3d==$0" TO BEFORE DROP;

SQL> FLASHBACK TABLE EMPLOYEE_DEMO TO BEFORE DROP;

FLASHBACK COMPLETE.

Assigning new name to the Flashbacked Table:

FLASHBACK TABLE "BIN$KSD8DB9L345KLA==$0" TO BEFORE DROP RENAME TO int2_admin_emp;

SQL> SELECT * FROM TAB;

TNAME TABTYPE CLUSTERID

—————————— ——- ———-

EMPLOYEE_DEMO TABLE

The table is reversed to its proper place. If you check the recycle bin now, it will be empty. Dropping a table will not directly free up space in the original tablespace. To free the space you need to purge it.

Completely drop or purging:

SQL>PURGE RECYCLEBIN;

SQL>DROP TABLE EMPLOYEE_DEMO PURGE;

SQL>PURGE TABLE "BIN$KSD8DB9L345KLA==$0";

If you are sure that you will not want to recover a table later, you can drop it immediately and permanently

Enabling and Disabling the Recycle Bin:

ALTER SESSION SET RECYCLEBIN=OFF;

ALTER SESSION SET RECYCLEBIN=OFF;

Either you can use it directly into the Pfile RECYCLEBIN=OFF

Restriction on Flashback Drop:

·   There is no fixed amount of space pre-allocated for the recycle bin. Therefore, there is no guaranteed minimum amount of time during which a dropped object will remain in the

·   Recycle bin. Dropped objects are kept in the recycle bin until such time as no new extents can be allocated in the tablespace to which the objects belong without growing the tablespace.

·   You can perform Flashback Query on tables in the recycle bin, but only by using the recycle bin name. You cannot use the original name of the table.

·   The recycle bin functionality is only available for non-system, locally managed tablespaces.

·   It is possible, however, that some dependent objects such as indexes may have been reclaimed due to space pressure. In such cases, the reclaimed dependent objects are not retrieved from the recycle bin.

·   The recycle bin does not preserve referential constraints on a table. If a table had referential constraints before it was dropped then recreate any referential constraints after you retrieve the table from the recycle bin with Flashback Drop.

·   Tables which have Fine-Grained Auditing (FGA) and Virtual Private Database (VPD) policies defined over them are not protected by the recycle bin.

·   Partitioned index-organized tables are not protected by the recycle..

Monday, 12 August 2013

Use of Oracle Flashback Version/Oracle Flashback Transactional Query

Consider the example when you are notice that the record payslip_number=21707 is missing from the HRMS.Pay_payment_detail table.
SELECT payslip_number, alw_ded_code, amount 
FROM pay_payment_detail where payslip_number=21707;

PAYSLIP_NUMBER ALW_     AMOUNT
-------------- ---- ----------
         21707 A010       2250
         21707 A020        375
         21707 A040        250
         21707 D016         35
         21707 G010        180
Delete  from pay_payment_detail
where payslip_number=21707;
commit;
By using oracle flash back query you can retrieves data as it existed at earlier time. The query explicitly references the past time through timestamp or SCN. It returns committed data that was current at that point in time.
For Example: Retrieving a lost row with oracle flashback query
SELECT payslip_number, alw_ded_code, amount 
FROM pay_payment_detail
AS OF TIMESTAMP  TO_TIMESTAMP('2013-06-24 07:20:00', 'YYYY-MM-DD HH:MI:SS')
 WHERE payslip_number = 21707;

PAYSLIP_NUMBER ALW_     AMOUNT
-------------- ---- ----------
         21707 A010       2250
         21707 A020        375
         21707 A040        250
         21707 D016         35
         21707 G010        180
INSERT INTO pay_payment_detail
  (SELECT * FROM pay_payment_detail
     AS OF TIMESTAMP
       TO_TIMESTAMP('2013-06-24 07:20:00', 'YYYY-MM-DD HH:MI:SS')
        WHERE payslip_number = 21707);

Check and commit the record after querying it.
Select * from pay_payment_detail
where payslip_number=21707;

PAYSLIP_NUMBER PAYMENT_TYPE ALW_DED_FLAG ALW_     AMOUNT   PRN_FLAG PRN_AMOUNT
-------------- ------------ ------------ ---- ---------- ---------- ----------
         21707            1            1 A010       2250          1          0
         21707            1            1 A020        375          1          0
         21707            1            1 A040        250          1          0
         21707            4            2 D016         35          1          0
         21707            1            2 G010        180          1          0
Then after you need to identify the following with Oracle Flashback Version query
The transaction identifier of the transaction that deleted the payslip_no record
The SQL statements necessary to undo the delete
The user who executed the transaction
SELECT versions_startscn, versions_starttime, versions_endscn, versions_endtime, versions_xid, versions_operation, payslip_number, amount 
FROM pay_payment_detail
VERSIONS BETWEEN TIMESTAMP 
TO_TIMESTAMP('‎2013-06-24 07:20:00', 'YYYY-MM-DD HH:MI:SS‎')  
AND TO_TIMESTAMP('‎2013-06-24 07:35:00', 'YYYY-MM-DD HH:MI:SS‎')
WHERE payslip_number = 21707;
SELECT xid, operation, start_scn, commit_scn, logon_user, undo_sql
FROM flashback_transaction_query
WHERE xid = HEXTORAW('000200030000002D');
To find the user id who is responsible for this change or delete
SELECT xid, logon_user
FROM flashback_transaction_query
WHERE xid IN (
  SELECT versions_xid FROM pay_payment_detail VERSIONS BETWEEN TIMESTAMP
  TO_TIMESTAMP('2013-06-24 07:20:00', 'YYYY-MM-DD HH:MI:SS') AND
  TO_TIMESTAMP('2013-06-24 07:35:00', 'YYYY-MM-DD HH:MI:SS'));

Note: You need to use Oracle Flashback Transaction Query with Oracle Flashback Version Query in the situation when two similar row of the same table is delete on different interval..

Tuesday, 6 August 2013

Steps for creating a Standby database Using RMAN - 10g dataguard

----------------------------------------------------------------------------------------------------------------------------
Primary database name:  prim on rac6 machine
Standby database name: stand on rac6 machine
----------------------------------------------------------------------------------------------------------------------------
The Enviroment :
     2 Linux servers, Oracle Distribution 2.6.9-55 EL i686 i386 GNU/Linux
     Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
     ssh is configured for user oracle on both nodes
     Oracle Home is on identical path on both nodes

Implementation notes:
     Once you have your primary database up and running these are the steps to follow:
     1.  Enable Forced Logging
     2.  Create a Password File
     3.  Configure a Standby Redo Log
     4.  Enable Archiving
     5.  Set Primary Database Initialization Parameters
     Having followed these steps to implement the Physical Standby you need to follow these steps:
     1. Create a Control File for the Standby Database
     2. Backup the Primary Database and transfer a copy to the Standby node.
     3. Prepare an Initialization Parameter File for the Standby Database
     4. Configure the listener and tnsnames to support the database on both nodes
     5. Set Up the Environment to Support the Standby Database on the standby node.
     6. Start the Physical Standby Database
     7. Verify the Physical Standby Database Is Performing Properly

----------------------------------------------------------------------------------------------------------------------------
Primary Database Steps
----------------------------------------------------------------------------------------------------------------------------

SQL> archive log list;
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     0
Current log sequence           1



SQL> select name from v$database;

NAME
---------
PRIM



SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/oracle/10gdg/oradata/prim/system01.dbf
/oracle/10gdg/oradata/prim/undotbs01.dbf
/oracle/10gdg/oradata/prim/sysaux01.dbf
/oracle/10gdg/oradata/prim/users01.dbf


SQL> show parameters unique

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_unique_name                       string      prim



----------------------------------------------------------------------------------------------------------------------------
Enable Forced Logging : In order to implement Standby Database we enable 'Forced Logging'. This option ensures that even in the event that a 'nologging' operation is done, force logging takes precedence and all operations are logged  into the redo logs.
----------------------------------------------------------------------------------------------------------------------------

SQL> ALTER DATABASE FORCE LOGGING;
  Database altered.

----------------------------------------------------------------------------------------------------------------------------
Create a Password File :  A password file must be created on the Primary and copied over to the Standby site. The sys password must be identical on both sites. This is a key pre requisite in order to be able to ship and apply archived logs from Primary to Standby.
----------------------------------------------------------------------------------------------------------------------------

[oracle@rac6 ~]$ cd $ORACLE_HOME/dbs
[oracle@rac6 dbs]$ orapwd file=orapwprim password=oracle force=y
SQL> select * from v$pwfile_users;

USERNAME              SYSDB SYSOP
------------------------------ ----- -----
SYS                            TRUE  TRUE


----------------------------------------------------------------------------------------------------------------------------
Configure a Standby Redo Log :  A Standby Redo log is added to enable Data Guard Maximum Availability and Maximum Protection modes. It is important to configure the Standby Redo Logs (SRL) with the same size as the online redo logs. If you are not using OMF's you then must pass the full qualified name.
----------------------------------------------------------------------------------------------------------------------------
SQL> select group#,type,member from v$logfile;

    GROUP# TYPE    MEMBER
---------- ------- ----------------------------------------
         3 ONLINE  /oracle/10gdg/oradata/prim/redo03.log
         2 ONLINE  /oracle/10gdg/oradata/prim/redo02.log
         1 ONLINE  /oracle/10gdg/oradata/prim/redo01.log     


SQL> select bytes from v$log;

  BYTES
----------
  52428800
  52428800
  52428800

SQL> ALTER DATABASE ADD STANDBY LOGFILE 
GROUP 4  'oracle/10gdg/oradata/prim/redo04.log' size 50m;


Database altered.


SQL> SELECT GROUP#,TYPE,MEMBER FROM V$LOGFILE;

       GROUP# TYPE    MEMBER
---------- ------- ----------------------------------------
         3 ONLINE  /oracle/10gdg/oradata/prim/redo03.log
         2 ONLINE  /oracle/10gdg/oradata/prim/redo02.log
         1 ONLINE  /oracle/10gdg/oradata/prim/redo01.log
         4 STANDBY /oracle/10gdg/oradata/prim/redo04.log

Note: you have to create this standby redolog in standby database also.
----------------------------------------------------------------------------------------------------------------------------
Set Primary Database Initialization Parameters :  Data Guard must use spfile, in order to configure it we create and configure the standby parameters on a regular pfile, and once it is ready we convert it to an spfile. Several init.ora parameters control the behavior of a Data Guard environment. In this example the Primary database init.ora is configured so that it can hold both roles, as Primary or Standby.
----------------------------------------------------------------------------------------------------------------------------

SQL> CREATE PFILE FROM SPFILE;

----------------------------------------------------------------------------------------------------------------------------
Edit the pfile to add the standby parameters, here shown highlighted:
----------------------------------------------------------------------------------------------------------------------------

prim.__db_cache_size=100663296
prim.__java_pool_size=4194304
prim.__large_pool_size=4194304
prim.__shared_pool_size=54525952
prim.__streams_pool_size=0
*.audit_file_dest='/oracle/10gdg/admin/prim/adump'
*.background_dump_dest='/oracle/10gdg/admin/prim/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/oracle/10gdg/oradata/prim/control01.ctl','/oracle/10gdg/oradata/prim/control02.ctl','/oracle/10gdg/oradata/prim/control03.ctl'
*.core_dump_dest='/oracle/10gdg/admin/prim/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='prim'
*.db_recovery_file_dest='/oracle/10gdg/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.job_queue_processes=10
*.dispatchers='(PROTOCOL=TCP) (SERVICE=primXDB)'
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/oracle/10gdg/admin/prim/udump'

*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150

*.sga_target=167772160
*.DB_UNIQUE_NAME='prim'

*.INSTANCE_NAME='prim'

*.DB_FILE_NAME_CONVERT='stand','prim'*.INSTANCE_NAME='prim'
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(prim,stand)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/oracle/10gdg/admin/prim/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=prim'
*.LOG_ARCHIVE_DEST_2='SERVICE=stand VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=stand'
*.LOG_ARCHIVE_DEST_STATE_1='ENABLE'
*.LOG_ARCHIVE_DEST_STATE_2='ENABLE'
*.LOG_ARCHIVE_FORMAT='log%t_%s_%r.arc'
*.LOG_FILE_NAME_CONVERT='stand','prim'
*.REMOTE_LOGIN_PASSWORDFILE='EXCLUSIVE'
*.SERVICE_NAMES='prim'
*.STANDBY_FILE_MANAGEMENT='AUTO'
*.FAL_CLIENT='prim'
*.FAL_SERVER='stand'

*.FAL_CLIENT='prim'
 



----------------------------------------------------------------------------------------------------------------------------
Once the new parameter file is ready we create from it the spfile:
----------------------------------------------------------------------------------------------------------------------------

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount pfile='$ORACLE_HOME/dbs/initprim.ora'
ORACLE instance started.
Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              96470608 bytes
Database Buffers          184549376 bytes
Redo Buffers                2973696 bytes


SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.

SQL> create spfile from pfile;
File created.



----------------------------------------------------------------------------------------------------------------------------
Enable Archiving:  On 10g you can enable archive log mode by mounting the database and executing the archivelog command:
----------------------------------------------------------------------------------------------------------------------------

SQL> startup mount
ORACLE instance started.
Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              96470608 bytes
Database Buffers          184549376 bytes
Redo Buffers                2973696 bytes
Database mounted.


SQL> alter database archivelog;
Database altered.

SQL> alter database open;

Database altered.

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /oracle/10gdg/admin/prim/arch
Oldest online log sequence     14
Next log sequence to archive   16
Current log sequence           16


----------------------------------------------------------------------------------------------------------------------------
Standby Database Steps:
----------------------------------------------------------------------------------------------------------------------------

create standby database using backup of the primary database datafiles,redologs, controlfile by RMAN compare with user managed backup, rman is comfortable and flexible method.

[oracle@rac6 ~]$ . oraenv
ORACLE_SID = [oracle] ? prim
[oracle@rac6 ~]$ rman target/

Recovery Manager: Release 10.2.0.1.0 - Production on Mon Nov 22 19:41:18 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: PRIM (DBID=4027893585)

----------------------------------------------------------------------------------------------------------------------------
Take the backup of the primary database :
----------------------------------------------------------------------------------------------------------------------------

RMAN> backup full database plus archivelog

----------------------------------------------------------------------------------------------------------------------------
Take the backup of controlfile for standby :
----------------------------------------------------------------------------------------------------------------------------

RMAN> BACKUP CURRENT CONTROLFILE FOR STANDBY;
RMAN> BACKUP ARCHIVELOG ALL;

----------------------------------------------------------------------------------------------------------------------------
SCP the backup pieces to the same location as that of the primary :
----------------------------------------------------------------------------------------------------------------------------
[oracle@rac6 ~]$ cd /oracle/10gdg/flash_recovery_area/PRIM/backupset/2010_11_21/
[oracle@rac6 2010_11_21]$ ls -ltr
total 662848
-rw-r-----  1 oracle oinstall 123472896 Nov 21 14:23 o1_mf_annnn_TAG20101121T142316_6gkqhxj3_.bkp
-rw-r-----  1 oracle oinstall 540319744 Nov 21 14:24 o1_mf_nnndf_TAG20101121T142327_6gkqj7f8_.bkp
-rw-r-----  1 oracle oinstall   7143424 Nov 21 14:24 o1_mf_ncsnf_TAG20101121T142327_6gkqkoxx_.bkp
-rw-r-----  1 oracle oinstall     22528 Nov 21 14:24 o1_mf_annnn_TAG20101121T142416_6gkqksmc_.bkp
-rw-r-----  1 oracle oinstall   7110656 Nov 21 14:25 o1_mf_ncnnf_TAG20101121T142459_6gkqm403_.bkp


[oracle@rac6 2010_11_21] scp * oracle@rac1:/oracle/10gdg/flash_recovery_area/PRIM/backupset/2010_11_21/


File created.


NOTE:The primary and standby database location for backup folder must be same.
for eg: /u01/app/oracle/backup folder

----------------------------------------------------------------------------------------------------------------------------
On the standby node create the required directories to get the datafiles :
----------------------------------------------------------------------------------------------------------------------------

mkdir -p /oracle/10gdg/flash_recovery_area/PRIM/backupset/2010_11_21/
mkdir -p /oracle/10gdg/flash_recovery_area/PRIM/onlinelog
mkdir -p /oracle/10gdg/admin/prim/adump
mkdir -p /oracle/10gdg/admin/prim/arch
mkdir -p /oracle/10gdg/oradata/prim/
mkdir -p /oracle/10gdg/admin/prim/bdump
mkdir -p /oracle/10gdg/admin/prim/cdump

mkdir -p /oracle/10gdg/admin/prim/udump

----------------------------------------------------------------------------------------------------------------------------
Prepare an Initialization Parameter File for the Standby Database:
----------------------------------------------------------------------------------------------------------------------------

stand.__db_cache_size=100663296
stand.__java_pool_size=4194304
stand.__large_pool_size=4194304
stand.__shared_pool_size=54525952
stand.__streams_pool_size=0
*.audit_file_dest='/oracle/10gdg/admin/stand/adump'
*.background_dump_dest='/oracle/10gdg/admin/stand/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/oracle/10gdg/oradata/stand/control01.ctl','/oracle/10gdg/oradata/stand/control02.ctl','/oracle/10gdg/oradata/stand/control03.ctl'
*.core_dump_dest='/oracle/10gdg/admin/stand/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_recovery_file_dest='/oracle/10gdg/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=standXDB)'
*.job_queue_processes=10

*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150

*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/oracle/10gdg/admin/stand/udump'

*.sga_target=167772160
*.DB_FILE_NAME_CONVERT='prim','stand'
*.DB_NAME='prim'

*.DB_UNIQUE_NAME='stand'
*.INSTANCE_NAME='stand'
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(prim,stand)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/oracle/10gdg/admin/stand/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=stand'
*.LOG_ARCHIVE_DEST_2='SERVICE=prim VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=prim'
*.LOG_ARCHIVE_DEST_STATE_1='ENABLE'
*.LOG_ARCHIVE_DEST_STATE_2='ENABLE'
*.LOG_ARCHIVE_FORMAT='log%t_%s_%r.arc'
*.LOG_FILE_NAME_CONVERT='prim','stand'
*.REMOTE_LOGIN_PASSWORDFILE='EXCLUSIVE'
*.SERVICE_NAMES='stand'
*.STANDBY_FILE_MANAGEMENT='AUTO'
*.FAL_CLIENT='stand'
*.FAL_SERVER='prim'


----------------------------------------------------------------------------------------------------------------------------Configure the listener and tnsnames to support the database on both nodes
----------------------------------------------------------------------------------------------------------------------------

#on rac6 machine : primary database

# Listener in primary

PRIM =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac6)(PORT = 1521))
  )

SID_LIST_PRIM =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = prim_DGMGRL)
      (ORACLE_HOME = /oracle/10gdg)
      (SID_NAME = prim)
    )
  )


#tnsnames in primary

STAND =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = rac7)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = stand)
    )
  )

PRIM =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = rac6)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = prim)
    )
  )


#on rac7 machine : standby database

# Listener in Standby

STAND =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac7)(PORT = 1521))
  )

SID_LIST_STAND =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = stand_DGMGRL)
      (ORACLE_HOME = /oracle/10gdg)
      (SID_NAME = stand)
    )
  )


#tnsnames in primary

STAND =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = rac7)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = stand)
    )
  )

PRIM =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = rac6)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = prim)
    )
  )


----------------------------------------------------------------------------------------------------------------------------
Start the listener and check tnsping on both nodes to both services:
----------------------------------------------------------------------------------------------------------------------------

#on machine rac6 : primary database

[oracle@rac6 ~]$ lsnrctl stop prim
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 22-NOV-2010 20:17:12
Copyright (c) 1991, 2005, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=rac6)(PORT=1521)))
The command completed successfully

[oracle@rac6 ~]$ lsnrctl start prim
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 22-NOV-2010 20:17:22
Copyright (c) 1991, 2005, Oracle.  All rights reserved.
Starting /oracle/10gdg/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.1.0 - Production
System parameter file is /oracle/10gdg/network/admin/listener.ora
Log messages written to /oracle/10gdg/network/log/prim.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=rac6)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=rac6)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     prim
Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date                22-NOV-2010 20:17:22
Uptime                    0 days 0 hr. 0 min. 1 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /oracle/10gdg/network/admin/listener.ora
Listener Log File         /oracle/10gdg/network/log/prim.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=rac6)(PORT=1521)))
Services Summary...
Service "prim_DGMGRL" has 1 instance(s).
  Instance "prim", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully


#on machine rac7 : standby database
[oracle@rac7 ~]$ lsnrctl stop stand
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 22-NOV-2010 20:18:40
Copyright (c) 1991, 2005, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=rac7)(PORT=1521)))
The command completed successfully

[oracle@rac7 ~]$ lsnrctl start stand
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 22-NOV-2010 20:19:18
Copyright (c) 1991, 2005, Oracle.  All rights reserved.
Starting /oracle/10gdg/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.1.0 - Production
System parameter file is /oracle/10gdg/network/admin/listener.ora
Log messages written to /oracle/10gdg/network/log/stand.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=rac7)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=rac7)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     stand
Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date                22-NOV-2010 20:19:18
Uptime                    0 days 0 hr. 0 min. 1 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /oracle/10gdg/network/admin/listener.ora
Listener Log File         /oracle/10gdg/network/log/stand.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=rac7)(PORT=1521)))
Services Summary...
Service "stand_DGMGRL" has 1 instance(s).
  Instance "stand", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully


----------------------------------------------------------------------------------------------------------------------------
Create a passwordfile for the standby:
----------------------------------------------------------------------------------------------------------------------------

[oracle@rac1 ~]$ orapwd file=$ORACLE_HOME/dbs/orapwblack password=oracle

note: sys password must be identical for both primary and standby database

---------------------------------------------------------------------------------------------------------------------------- Startup nomount the Standby database : Nomount the standby instance in preparation for the duplicate operation: Startup nomount the Standby database and generate an spfile.
----------------------------------------------------------------------------------------------------------------------------

[oracle@rac7 ~]$ . oraenv
ORACLE_SID = [whiteowl] ? stand
[oracle@rac7 ~]$ sqlplus '/as sysdba'


SQL> startup nomount pfile='$ORACLE_HOME/dbs/initstand.ora'
ORACLE instance started.

SQL> create spfile from pfile;

SQL> shutdown immediate

ORA-01507: database not mounted

ORACLE instance shut down.


SQL> startup nomount
ORACLE instance started.
Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              92276304 bytes
Database Buffers          188743680 bytes
Redo Buffers                2973696 bytes


----------------------------------------------------------------------------------------------------------------------------
Create the standby database using rman:
----------------------------------------------------------------------------------------------------------------------------
[oracle@rac1 ~]$ . oraenv
ORACLE_SID = [oracle] ? black
[oracle@rac1 ~]$ rman target=sys/oracle@white auxiliary=/

Recovery Manager: Release 10.2.0.1.0 - Production on Thu Jan 21 00:43:11 2010

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

connected to target database: PRIM (DBID=3603807872)
connected to auxiliary database: PRIM (not mounted)


RMAN> DUPLICATE TARGET DATABASE FOR STANDBY NOFILENAMECHECK;

----------------------------------------------------------------------------------------------------------------------------
Start the redo apply:
----------------------------------------------------------------------------------------------------------------------------

SQL> alter database recover managed standby database disconnect from session;



----------------------------------------------------------------------------------------------------------------------------
Test the configuration by generating archive logs from the primary and then querying the standby to see if the logs are being successfully applied.
----------------------------------------------------------------------------------------------------------------------------
On the Primary: 
SQL> alter system switch logfile;
SQL> alter system archive log current;

#on machine rac6 : primary database

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /oracle/10gdg/admin/prim/arch
Oldest online log sequence     14
Next log sequence to archive   16
Current log sequence           16


#on machine rac7 : standby database

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /oracle/10gdg/admin/stand/arch
Oldest online log sequence     14
Next log sequence to archive   0
Current log sequence           16


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


--------------------------------------------------------------------------------------------------------------------------
Verify the sync between primary and standby:
----------------------------------------------------------------------------------------------------------------------------

From primary

sql > select thread#,max(sequence#) from v$archived_log where archived='YES' group by thread#;

From StandbySQL > select thread#,max(sequence#) from v$archived_log where applied ='YES' group by thread#;

----------------------------------------------------------------------------------------------------------------------------
Stop the managed recovery process on the standby:
----------------------------------------------------------------------------------------------------------------------------

SQL> alter database recover managed standby database cancel;