Sunday, April 6, 2014

Oracle database 11g new feature

http://www.oracleworlds.com/

Oracle database 11g new feature

ASM :

Support for rolling upgrades.
We can maintain version compatibilities at diskgroup level.

SQL> alter diskgroup dg-name set attribute 'compatible.rdbms'='11.1';
SQL> alter diskgroup dg-name set attribute 'compatible.asm'='11.1';

v  ASM drops disks and if they remain offline for more than 3.6 hours. The
diskgroups default time limit is altered by changing the DISK_REPAIR_TIME
parameter with a unit of minutes(M/m) or hours(H/h).
SQL> alter diskgroup dg-name set attribute 'disk_repair_time'='4.5h';
Automatic bad block detection and repair.Supports variable extent
(allocation unit) sizes. The total number of extents in shared pool will be
significantly reduced and improved performance.

SQL> create diskgroup ... attribute 'au_size' = 'number-of-bytes';

New SYSASM role (like SYSDBA, SYSOPER) & OSASM OS group (like OSDBA, OSOPER) to manage ASM instance only. This will separate storage administration from database administration.
$ sqlplus "/as sysasm" or $ asmcmd -a sysasm
v  ASM Preferred Mirror Read or Preferred Read Failure Groups -
ASM_PREFERRED_READ_FAILURE_GROUPS parameter is set to the preferred
failure groups for each node.
v  Faster Mirror Resync - Fast mirror resync after temporary connectivity lost.
v  We can drop a diskgroup forcefully.
SQL> drop diskgroup dg-name force including contents;
v    Can mount the disk in restricted mode, to rebalance faster.
SQL> alter diskgroup dg-name mount restricted;
New commands in ASMCMD
v  cp - to copy between ASM and local or remote destination.
v  md_backup - to backup metadata.
v  md_restore - to restore metadata.
v  lsdsk - to list(check) disks.
v  remap - to repair a range of physical blocks on disk.
v  New options in Data Pump export.
DATA_OPTIONS, ENCRYPTION, ENCRYPTION_ALGORITHM, ENCRYPTION_MODE, REMAP_DATA, REUSE_DUMPFILES, TRANSPORTABLE
v  New options in Data Pump import.
DATA_OPTIONS, PARTITION_OPTIONS, REMAP_DATA, REMAP_TABLE, TRANSPORTABLE
v  New option in Data Pump export interactive mode - REUSE_DUMPFILES.
v  In Data Pump import, we can specify how the partitions should transform by using PARTITION_OPTIONS.

Dumpfile can be compressed. In Oracle 10g, only metadata can be compressed. From 11g, both data & metadata can be compressed. Dumpfile will be uncompressed automatically before importing.
v  Encryption: The dumpfile can be encrypted while creating. This encryption occurs on the entire dumpfile, not just on the encrypted columns as it was in the Oracle Database 10g.
Masking: when we import data from production to test or development instances, we have to make sure sensitive data such as credit card details, etc. are obfuscated/remapped (altered in such a way that they are not identifiable). From 11g, Data Pump enables us do that by creating a masking function and then using that during import.

v  Multisection backups of same file - RMAN can backup or restore a single file in parallel by dividing the work among multiple channels. Each channel backs up one file section, which is a contiguous range of blocks. This speeds up overall backup and restore performance, and particularly for bigfile tablespaces, in which a datafile can be sized upwards of several hundred GB to TB's.
v  Recovery will make use of flashback logs in FRA (Flash/Fast Recovery Area).
v  Fast Backup Compression - in addition to the Oracle Database 10g backup compression algorithm (BZIP2), RMAN now supports the ZLIB algorithm, which offers 40% better performance, with a trade-off of no more than 20% lower compression ratio, versus BZIP2.
RMAN> configure compression algorithm 'ZLIB' ;
v  Will backup uncommitted undo only, not committed undo.
v  Data Recovery Advisor (DRA) - quickly identify the root cause of failures; auto fix or present recovery options to the DBA.
v  Archived Redo log failover - this feature enables RMAN to complete backups even when some archiving destinations having missing logs or contain logs with corrupted blocks where local archive log destination is configured along with FRA.
 Virtual Private Catalog - a recovery catalog administrator can grant visibility of a subset of registered databases in the catalog to specific RMAN users.
RMAN> grant catalog for database db-name to user-name;
·                     Catalogs can be merged/moved/imported from one database to another.
·                     New commands in RMAN
v  RMAN> list failure;
v  RMAN> list failure errnumber detail;
v  RMAN> advise failure;
v  RMAN> repair failure;
v  RMAN> repair failure preview;
v  RMAN> validate database; -- checks for corrupted blocks
v  RMAN> create virtual catalog;
Partitioning:

v  Partition advisor - figure out what partitions to create.
v  Automated partitioning by interval (new partitions are added automatically).
v  Automated reference partitioning by Parent/Child reference (as partitions are created, partitions are created in tables that reference them).
v  Partitioning by virtual columns.
v  New composite partitioning types: Range-Range, List-Range, List-Hash, List-List, Interval-Range, Interval-List and Interval-Interval.
v  System partitioning is introduced.
v  Support for transportable partitions (tablespace transport of single partition) -
for moving partitions between different databases/operating systems.
v  Staleness checking in partitions - only outdated partitions will be refreshed
when we run dbms_mview.refresh().
Compression

Support compression on INSERT, UPDATE and DELETE operations. 10g only supported compression for bulk data-loading operations.
v  Advanced compression allows for a 2-3 X compression rate of structured and unstructured data.
v  From Oracle 11g, we can compress individual partitions also.

Performance improvements 

v  RAC - 70% faster (ADDM has a better global view of the RAC cluster).
v  Streams - 30-50% faster.
v  Optimizer stats collection - 10x faster.
v  OLAP (Online Analytic Processing) based materialized views for fast OLAP cube building. Cube-organized MView supports automatic query rewrite and automatic refresh of the cube.
v  SQL Result Cache - new memory area in SGA for storing SQL query results, PL/SQL function results and OCI call results. When we execute a query with the hint result_cache, the results are stored in the SQL Result Cache. Query results caching is 25% faster. The size of the cache is determined by result_cache_max_size, result_cache_max_result, result_cache_mode, result_cache_remote_expiration.
v  Invisible indexes - indexes will be ignored by the optimizer. Handy for testing without dropping. To make it visible, recreate it.
SQL> alter index index-name invisible;
v  Oracle secure files - 5x faster than normal file systems.
Availability improvements 

v  Ability to apply many patches on-line without downtime (RAC and single instance databases).
v  XA transactions spanning multiple servers.
v  Improved runtime connection load balancing.
v  Flashback Transaction/Oracle Total Recall.
Security improvements 

v  Support for case sensitive and multi-byte passwords (disabled by setting
SEC_CASE_SENSITIVE_LOGON parameter to FALSE).
v  Transparent Data Encryption - support for tablespace level encryption.
v  Hardware based master key protection.
v  Encrypt backups.
v  Kerberos authentication - strong passwords.
v  Add Multi-factor DBA controls with Data Vault.
v  New parameters have been added to enhance the default security of the database.
* SEC_RETURN_SERVER_RELEASE_BANNER
* SEC_PROTOCOL_ERROR_FURTHER_ACTION
* SEC_PROTOCOL_ERROR_TRACE_ACTION
* SEC_MAX_FAILED_FAILED_LOGIN_ATTEMPTS
* SEC_DISABLE_OLDER_ORACLE_RPCS
Manageability improvements 

v  New MEMORY_TARGET, MEMORY_MAX_TARGET parameters. When we set MEMORY_TARGET, Oracle will dynamically assign memory to SGA & PGA as and when needed i.e.MEMORY_TARGET=SGA_TARGET+PGA_AGGREGATE_TARGET. New views related this are v$memory_dynamic_components, v$memory_resize_ops.
v  From Oracle 11g, SID clause in "alter system reset" command is optional.
SQL> alter system [SID=instance-name] reset parameter-name;
v  New DIAGNOSTIC_DEST parameter as replacement for BACKGROUND_DUMP_DEST, CORE_DUMP_DEST and USER_DUMP_DEST. It defaults to $ORACLE_BASE/diag/.
v  From 11g, we have two alert log files. One is the traditional alert_SID.log (in DIAGNOSTIC_DEST/trace) and the other one is a log.xml file (in DIAGNOSTIC_DEST/alert). The xml file gives a lot more information than the traditional alert log file. We can have logging information for DDL operations in the alert log files. If log.xml reaches 10MB size, it will be renamed and will create new alert log file. log.xml can be accessed from ADR command line.
ADRCIshow alert
v  Logging information for DDL operations will be written into alert log files, is not enabled by default and we must change the new parameter to TRUE.
SQL> ALTER SYSTEM SET enable_ddl_logging=TRUE SCOPE=BOTH;
v  Parameter(p) file & server parameter(sp) file can be created from memory.
SQL> create pfile[=location] from memory;
SQL> create spfile[=location] from memory;
v  From 11g, server parameter file (spfile) is in new format that is compliant with Oracle Hardware Assisted Resilient Data(HARD).
v  DDL wait option - Oracle will automatically wait for the specified time period during DDL operations and will try to run the DDL again.
SQL> ALTER SYSTEM/SESSION SET DDL_LOCK_TIMEOUT = n;
v  We can define the statistics to be pending, which means newly gather statistics will not be published or used by the optimizer — giving us an opportunity to test the new statistics before we publish them.
v  From Oracle Database 11g, we can create extended statistics on
(i) expressions of values, not only on columns
(ii) on multiple columns (column group), not only on single column.
v  Table level control of CBO statistics refresh threshold.
SQL> exec dbms_stats.set_table_prefs(’HR’, EMP’, ‘STALE_PERCENT’, ‘20');
Flashback Data Archive - flashback will make use of flashback logs, explicitly created for that table, in FRA (Flash/Fast Recovery Area), will not use undo. Flashback data archives can be defined on any table/tablespace. Flashback data archives are written by a dedicated background process called FBDA so there is less impact on performance. Can be purged at regular intervals automatically.

v  Analytic Workspace Manager (AWM) - a tool to manage OLAP objects in the database.
v  Users with default passwords can be found in DBA_USERS_WITH_DEFPWD.
v  Hash value of the passwords in DBA_USERS (in ALL_USERS and USER_USERS) will be blank. If you want to see the value, query USER$.
v  Default value for audit_trail is DB, not NULL. By default some system privileges will be audited.
v  LogMiner can be accessed from Oracle Enterprise Manager.
Data Guard improvements

v  Oracle Active Data Guard - Standby databases can now simultaneously be in read and recovery mode - so use it for running reports 24x7.
v  Online upgrades: Test on standby and roll to primary.
v  Snapshot standby database - physical standby database can be temporarily converted into an updateable one called snapshot standby database.
v  Creation of physical standby is become easier.
v  From Oracle 11g, we can control archive log deletion by setting the log_auto_delete initialization parameter to TRUE.  The log_auto_delete parameter must be coupled with the log_auto_del_retention_target parameter to specify the number of minutes an archivelog is maintained until it is purged. Default is 24 hours (1440 minutes).
v  Incremental backup on physical readable physical standby.
v  Offload: Complete database and fast incremental backups.
v  Logical standby databases now support XML and CLOB datatypes as well as transparent data encryption.
v  We can compress the redo data that goes to the standby server, by setting compression=enable.
v  From Oracle 11g, logical standby provides support for DBMS_SCHEDULER.
v  When transferring redo data to standby, if the standby does not respond in time, the log transferring service will wait for specified timeout value (set by net_timeout=n) and then give up.
v  In Oracle 11g, block change tracking is now supported in the standby database.
v  New package and procedure, DBMS_DG.INITIATE_FS_FAILOVER, introduced to programmatically initiate a failover.
SecureFiles 
SecureFiles provide faster access to unstructured data than normal file systems, provides the benefits of LOBs and external files. For example, write access to SecureFiles is faster than a standard Linux file system, while read access is about the same. SecureFiles can be encrypted for security, de-duplicated and compressed for more efficient storage, cached (or not) for faster access (or save the buffer cache space), and logged at several levels to reduce the mean time to recover (MTTR) after a crash.

create table table-name ( ... lob-column lob-type [deduplicate] [compress high/low] [encrypt using 'encryption-algorithm'] [cache/nocache] [logging/nologging] ...) lob (lob-column) store as securefile ...;


To create SecureFiles:

(i) The initialization parameter db_securefile should be set to PERMITTED (the default value).
(ii) The tablespace where we are creating the securefile should be Automatic Segment Space Management (ASSM) enabled (default mode in Oracle Database 11g).

Real Application Testing(RAT)
Real Application Testing (RAT) will make decision making easier in migration, upgradation, patching, initialization parameter changes, object changes, hardware replacements, and operating system changes and moving to RAC environment. RAT consists of two components:

Database Replay 
 capture production workload and replay on different (standby/test/development) environment. Capture the activities from source database in the form of capture files in capture directory. Transfer these files to target box. Replay the process on target database.
v    SQL Performance Analyzer (SPA) - identifies SQL execution plan changes and performance regressions. SPA allows us to get results of some specific SQL or entire SQL workload against various types of changes such as initialization parameter changes, optimizer statistics refresh, and database upgrades, and then produces a comparison report to help us assess their impact. Accessible through Oracle Enterprise Manager or dbms_sqlpa package.

Other features

v  Temporary tablespace or it's tempfile can be shrinked, up to specified size.
SQL> alter tablespace temp-tbs shrink space;
SQL> alter tablespace temp-tbs shrink space keep n{K|M|G|T|P|E};
SQL> alter tablespace temp-tbs shrink tempfile '.../temp03.dbf'
·                     keep n{K|M|G|T|P|E};
We can check free temp space in new view DBA_TEMP_FREE_SPACE.
·                     From 11g, while creating global temporary tables, we can specify TEMPORARY tablespaces.
·                     Online application upgrades and hot patching. Features based patching is also available.
·       Real-time SQL Monitoring, allows us to see the different metrics of the SQL being executed in real time. The stats are exposed through V$SQL_MONITOR, which is refreshed every second.
·        "duality" between SQL and XML - users can embed XML within PL/SQL and vice versa.
·      New binary XML datatype, a new XML index & better XQuery support.
·      Query rewriting will occur more frequently and for remote tables also.
·      Automatic Diagnostic Repository (ADR)- automated capture of fault diagnostics for faster fault resolution. The location of the files depends on DIAGNOSTIC_DEST parameter. This can be managed from Database control or command line. For command line, execute $ ./adrci
·                     Repair advisors to guide DBAs through the fault diagnosis and resolution process.
·                     SQL Developer is installed with the database server software (all editions). The Windows SQL*Plus GUI is deprecated.

 APEX (Oracle Application Express), formerly known as HTML DB, shipped with the DB.
·                     Checkers - DB Structure Integrity Checker, Data Block Integrity Checker, Redo Integrity Checker, Undo Segment Integrity Checker, Transaction Integrity Checker, Dictionary Integrity Checker.
·                     11g SQL Access Advisor provides recommendations with respect to the entire workload, including considering the cost of creation and maintaining access structure.
·                     hangman Utility – hangman(Hang Manager) utility to detect database bottlenecks.
·                     Health Monitor (HM) utility - Health Monitor utility is an automation of the dbms_repair corruption detection utility.
·                     The dbms_stats package has several new procedures to aid in supplementing histogram data, and the state of these extended histograms can be seen in the user_tab_col_statistics view:
dbms_stats.create_extended_stats
dbms_stats.show_extended_stats_name
dbms_stats.drop_extended_stats
·                     New package DBMS_ADDM introduced in 11g.
·                     Oracle 11g introduced server side connection pool called Database Resident Connection Pool (DRCP).

Desupported features 
The following features are desupported/deprecated in Oracle Database 11g Release 1 (11.1.0):

·                     Oracle export utility (exp)Imp is still supported for backwards compatibility.
·                     Windows SQL*Plus GUI & iSQLPlus will not be shipped anymore. Use SQL Developer instead.
·                     Oracle Enterprise Manager Java console.
·                     copy command is deprecated.


Thursday, October 10, 2013

Standby Database creation with RMAN Duplicate

Posted By Pankaj Yadav
Setup: Physical Standby Data Guard Creation with RMAN, step by step 

Primary Site
Standby Site
Hostname
pk.prod.com
pk.standby.com
Database Name
prod
prod
Database Unique Name
prod
standby
Net Service Name
prod
standby

In this article, I explained the step by step process to create a physical standby database using RMAN duplicate command without shutting down the primary Database.

1.      Enable Database Force Logging
2.      Create SRL (Standby Redo Logs)
3.      Modify Init.ora parameters
4.      Enable Archiving
5.      Create a init.ora file for Standby Database ( Optional )
6.      Configure listener.ora and tnsnames.ora
7.      Copy init.ora and password  files to Standby Server

Standby Site Preparation :
1.      Create a remote login password file ( if it is not copied from primary site )
2.      Create a directory structure
3.      Modify the init.ora parameter file (Optional) [oracle@pk ~]$ sqlplus / as sysdba

[oracle@pk ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Wed Aug 28 08:21:24 2013

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


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> select name from v$database;

NAME
---------
PROD

SQL>  select name,db_unique_name,database_role,switchover_status from v$database
;
NAME      DB_UNIQUE_NAME                 DATABASE_ROLE    SWITCHOVER_STATUS
--------- ------------------------------ ---------------- --------------------
PROD      prod                           PRIMARY          SESSIONS ACTIVE
 SQL> select FORCE_LOGGING from v$database;

FOR
---
NO

SQL>  ALTER DATABASE FORCE LOGGING;

Database altered.

SQL> select name,user from v$database;

NAME      USER
--------- ------------------------------
PROD      SYS

SQL> col group# for 9999
SQL> col member for a50
SQL> set linesize 120
SQL> select name,user from v$database;

NAME      USER
--------- ------------------------------
PROD      SYS

SQL> select GROUP#,THREAD#,MEMBERS,BYTES FROM V$LOG;

GROUP#    THREAD#    MEMBERS      BYTES
------ ---------- ---------- ----------
     1          1          1   52428800
     2          1          1   52428800
     3          1          1   52428800

SQL> select group#,member from v$logfile;

GROUP# MEMBER
------ --------------------------------------------------
     3 /home/oracle/oracle/product/10.2.0/oradata/prod/redo03.log

     2 /home/oracle/oracle/product/10.2.0/oradata/prod/redo02.log
     1 /home/oracle/oracle/product/10.2.0/oradata/prod/redo01.log

SQL> ALTER DATABASE ADD STANDBY LOGFILE ('/home/oracle/oracle/product/10.2.0/oradata/prod/s_redo1.log') size 52428800;

Database altered.

SQL>  ALTER DATABASE ADD STANDBY LOGFILE ('/home/oracle/oracle/product/10.2.0/oradata/prod/s_redo2.log')  size 52428800;                                               
Database altered.


SQL> ALTER DATABASE ADD STANDBY LOGFILE ('/home/oracle/oracle/product/10.2.0/oradata/prod/s_redo3.log') size 52428800;

Database altered.

SQL>  ALTER DATABASE ADD STANDBY LOGFILE ('/home/oracle/oracle/product/10.2.0/oradata/prod/s_redo4.log')  size 52428800;                                                
Database altered.


SQL> select GROUP#,THREAD#,MEMBERS,BYTES FROM V$LOG;

    GROUP#    THREAD#    MEMBERS      BYTES
---------- ---------- ---------- ----------
         1          1          1   52428800
         2          1          1   52428800
         3          1          1   52428800

SQL> SELECT GROUP#, BYTES FROM V$STANDBY_LOG;

    GROUP#      BYTES
---------- ----------
         4   52428800
         5   52428800
         6   52428800
         7   52428800


************ Modify the init.ora parameters: *******************

Modify the initprod.ora parameters on the primary database side to reflect the following values. If you are using spfile, you can add these parameter online without
down the primary database.


alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(prod,standby)';
alter system set LOG_ARCHIVE_DEST_1='LOCATION=/home/oracle/archive/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=prod';

alter system set LOG_ARCHIVE_DEST_2=’SERVICE=standby ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby’;

alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;
alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE;
alter system set REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=spfile;
ALTER SYSTEM SET log_archive_format='arch_%t_%s_%r.arc' SCOPE=spfile;
alter system set LOG_ARCHIVE_MAX_PROCESSES=30;
alter system set FAL_SERVER=standby;
alter system set DB_FILE_NAME_CONVERT='standby','prod' SCOPE=spfile;
alter system set LOG_FILE_NAME_CONVERT=
'/home/oracle/oracle/product/10.2.0/oradata/prod/','/home/oracle/oracle/product/10.2.0/oradata/standby/'SCOPE=spfile;    
alter system set STANDBY_FILE_MANAGEMENT=AUTO;
                                  
SQL> alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(prod,standby)';
`System altered.
  
SQL> alter system set LOG_ARCHIVE_DEST_1='LOCATION=/home/oracle/archive/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=prod';

System altered.
  
SQL> alter system set LOG_ARCHIVE_DEST_2='SERVICE=standby ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby' SCOPE=spfile;

System altered.

SQL> alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;
System altered.

 SQL> alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE;
 System altered.

 SQL>  alter system set REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=spfile;
System altered.

SQL> ALTER SYSTEM SET log_archive_format='arch_%t_%s_%r.arc' SCOPE=spfile;
 System altered.
 SQL> alter system set LOG_ARCHIVE_MAX_PROCESSES=30;
 System altered.
 SQL> alter system set FAL_SERVER=standby;
 System altered.
 SQL> alter system set DB_FILE_NAME_CONVERT='standby','prod' SCOPE=spfile;
 System altered.
SQL> alter system set STANDBY_FILE_MANAGEMENT=AUTO;
 System altered.

SQL> alter system set LOG_FILE_NAME_CONVERT='/home/oracle/oracle/product/10.2.0/oradata/standby/','/home/oracle/oracle/product/10.2.0/oradata/prod/'SCOPE=spfile;
 System altered.


*****CHECK & UPDATE initprod.ora( PFILE ) PRIMARY DB SIDE *************
 vi initprod.ora 
prod.__db_cache_size=197132288
prod.__java_pool_size=4194304
prod.__large_pool_size=4194304
prod.__large_pool_size=4194304
prod.__shared_pool_size=75497472
prod.__db_cache_size=197132288
prod.__java_pool_size=4194304
prod.__large_pool_size=4194304
prod.__shared_pool_size=75497472
prod.__streams_pool_size=0
*.audit_file_dest='/home/oracle/oracle/product/10.2.0/db_1/admin/prod/adump'
*.background_dump_dest='/home/oracle/oracle/product/10.2.0/db_1/admin/prod/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/home/oracle/oracle/product/10.2.0/oradata/prod/control01.ctl',
                        '/home/oracle/oracle/product/10.2.0/oradata/prod/control02.ctl',  
                        '/home/oracle/oracle/product/10.2.0/oradata/prod/control03.ctl'
*.core_dump_dest='/home/oracle/oracle/product/10.2.0/db_1/admin/prod/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_file_name_convert='standby','prod'
*.db_name='prod'
*.db_recovery_file_dest='/home/oracle/oracle/product/10.2.0/db_1/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=prodXDB)'
*.fal_server='STANDBY'
*.job_queue_processes=10
*.local_listener='LISTENER_PROD'
*.log_archive_config='DG_CONFIG=(prod,standby)'
*.log_archive_dest_1='LOCATION=/home/oracle/archive/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=prod'
*.log_archive_dest_2='SERVICE=standby ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_format='arch_%t_%s_%r.arc'
*.log_file_name_convert='/home/oracle/oracle/product/10.2.0/oradata/standby/','/home/oracle/oracle/product/10.2.0/oradata/prod/'
*.db_file_name_convert='/home/oracle/oracle/product/10.2.0/oradata/standby/','/home/oracle/oracle/product/10.2.0/oradata/prod/'
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=285212672
*.standby_file_management='AUTO'
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/home/oracle/oracle/product/10.2.0/db_1/admin/prod/udump'


sql> create spfile from pfile;
sql> shutdown immediate;
sql> startup;
Create pfile for standby database:
 SQL> create pfile='/home/oracle/oracle/product/10.2.0/db_1/dbs/initstandby.ora' from spfile;
 File created.

Configure listener.ora and tnsnames.ora:
 # tnsnames.ora Network Configuration File: /home/oracle/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools. 
PROD =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = pk.prod.com)(PORT = 1522))

# tnsnames.ora Network Configuration File: /home/oracle/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
PROD =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.226.129)(PORT = 1522))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = prod)
    )
  )
STANDBY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.226.131)(PORT = 1522))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = standby)
    )
  )
EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC2))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )
LISTENER_PROD =
  (ADDRESS = (PROTOCOL = TCP)(HOST = pk.prod.com)(PORT = 1522))

[oracle@pk dbs]$ orapwd file=$ORACLE_SID  password=sys force=y;
 [oracle@pk dbs]$ ls
hc_prod.dat  initdw.ora  init.ora  initprod.ora  initstandby.ora  lkPROD  orapwprod  prod  spfileprod.ora
Transfer init.ora and password files to Standby Server:
Create Password file  and copy initstandby.ora and password file from primary server to standby server.

[oracle@pk dbs]$ ls
hc_prod.dat  initdw.ora  init.ora  initprod.ora  initstandby.ora  lkPROD  orapwprod  prod  spfileprod.ora
[oracle@pk dbs]$ scp initstandby.ora orapwprod oracle@192.168.226.131:/home/oracle/oracle/product/10.2.0/db_1/dbs/
oracle@192.168.226.131's password:
initstandby.ora                                                                          100% 1806     1.8KB/s   00:00
orapwprod                                                                                100% 1536     1.5KB/s   00:00


*****************************************************************************            Standby Database Site Preparation :
*****************************************************************************
* Create a remote login password file ( if it is not copied from primary site )
* Create a directory structure
If you are using a different directory structure on the standby server, then you need to create all the directories on the standby site.
Copy initstandby.ora to $ORACLE_HOME/dbs location.
SQL>  conn sys/sys@prod as sysdba
SQL> select name from v$database;
NAME
---------
PROD


Configure listener.ora and tnsnames.ora:
# tnsnames.ora Network Configuration File: /home/oracle/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
PROD =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = pk.prod.com)(PORT = 1522))
# tnsnames.ora Network Configuration File: /home/oracle/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
PROD =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.226.129)(PORT = 1522))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = prod)
    )
  )
STANDBY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.226.131)(PORT = 1522))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = standby)
    )
  )
EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC2))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )
LISTENER_PROD =
  (ADDRESS = (PROTOCOL = TCP)(HOST = pk.prod.com)(PORT = 1522))

*****************************************************************************
            Standby Database Site Preparation :
*****************************************************************************
* Create a remote login password file ( if it is not copied from primary site )
* Create a directory structure
If you are using a different directory structure on the standby server, then you need to create all the directories on the standby site.
Copy initstandby.ora to $ORACLE_HOME/dbs location.

**************** Edit pfile and update parameter for Standby *******************
 DB_NAME=prod
DB_UNIQUE_NAME=standby
LOG_ARCHIVE_CONFIG=’DG_CONFIG=(prod,standby)’
CONTROL_FILES=’/home/oracle/app/oracle/oradata/sbyorcl/s_control01.ctl’, ‘/home/oracle/app/oracle/flash_recovery_area/sbyorcl/s_control02.ctl’
DB_FILE_NAME_CONVERT=’prod’,'standby’
LOG_FILE_NAME_CONVERT=’/home/oracle/app/oracle/flash_recovery_area/prod/’,'/home/oracle/app/oracle/flash_recovery_area/standby/’
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_DEST_1=’LOCATION=/home/oracle/app/oracle/flash_recovery_area/standby/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=standby’
LOG_ARCHIVE_DEST_2=’SERVICE=prod ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=prod’
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
STANDBY_FILE_MANAGEMENT=AUTO
FAL_SERVER=prod
Edit parameter file and update parameteres required for standby
 vi initstandby.ora
*.audit_file_dest='/home/oracle/oracle/product/10.2.0/db_1/admin/standby/adump'
*.background_dump_dest='/home/oracle/oracle/product/10.2.0/db_1/admin/standby/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/home/oracle/oracle/product/10.2.0/oradata/standby/control01.ctl','/home/oracle/oracle/product/10.2.0/oradata/standby/control02.ctl','/home/oracle/ora
cle/product/10.2.0/oradata/standby/control03.ctl'
*.core_dump_dest='/home/oracle/oracle/product/10.2.0/db_1/admin/standby/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_file_name_convert='prod','standby'
*.db_name='prod'
*.db_unique_name=standby
*.db_recovery_file_dest='/home/oracle/oracle/product/10.2.0/db_1/flash_recovery_area'
#*.db_recovery_file_dest='/home/oracle/backup'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=prodXDB)'
*.fal_server='PROD'
*.job_queue_processes=10
*.local_listener='LISTENER_STANDBY'
*.log_archive_config='DG_CONFIG=(prod,standby)'
*.log_archive_dest_1='LOCATION=/home/oracle/archive/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=standby'
*.log_archive_dest_2='SERVICE=prod ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=prod'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_format='arch_%t_%s_%r.arc'
*.log_file_name_convert='/home/oracle/oracle/product/10.2.0/oradata/prod/','/home/oracle/oracle/product/10.2.0/oradata/standby/'
*.db_file_name_convert='/home/oracle/oracle/product/10.2.0/oradata/prod/','/home/oracle/oracle/product/10.2.0/oradata/standby/'
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=285212672
*.standby_file_management='AUTO'
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/home/oracle/oracle/product/10.2.0/db_1/admin/standby/udump'
~

SYS@STANDBY > startup nomount pfile='/home/oracle/oracle/product/10.2.0/db_1/dbs/initstandby.ora';
ORACLE instance started.
Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              83887696 bytes
Database Buffers          197132288 bytes
Redo Buffers                2973696 bytes
SYS@STANDBY > create spfile from pfile='/home/oracle/oracle/product/10.2.0/db_1/dbs/initstandby.ora';
 File created.
 SYS@STANDBY > shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SYS@STANDBY > startup nomount
ORACLE instance started.
Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              83887696 bytes
Database Buffers          197132288 bytes
Redo Buffers                2973696 bytes
_________________________________________________
*********** Take the backup of Primary Database in Primary DB side ***********
_________________________________________________
Create one backup directory for the backup of database on both side ( primary database & Standby database)
same path and same directory name like here i create with the name of backup on '/home/oracle/' path
 RMAN> backup full database format'/home/oracle/backup/%d_%U.bckp' plus archivelog format '/home/oracle/backup/5D_%U.bkp';
RMAN> configure channel device type disk format '/home/oracle/backup/%U';
RMAN> BACKUP CURRENT CONTROLFILE FOR STANDBY;
RMAN> BACKUP ARCHIVELOG ALL;

****** Transfer ALL Backup to standby Database *********************
____________________________________________________
********** ON STANDBY DATABASE SIDE *****************************
Create the standby database using rman: 
_______________________________________________________________
[oracle@rac1 ~]$ . oraenv
ORACLE_SID = [standby] ? standby

STARTUP DATABASE IN MOUNT MODE
SYS@STANDBY > startup nomount
ORACLE instance started. 
Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              83887696 bytes
Database Buffers          197132288 bytes
Redo Buffers                2973696 bytes
_________________________________________
  *******CONNECT RMAN**********
_________________________________________
 [oracle@pk ~]$ rman target=sys/sys@prod auxiliary=/
 Recovery Manager: Release 10.2.0.1.0 - Production on Fri Aug 30 08:29:55 2013
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: PROD (DBID=236467520)
connected to auxiliary database: PROD (DBID=236467520, not open)
RMAN> DUPLICATE TARGET DATABASE FOR STANDBY NOFILENAMECHECK; 
Starting Duplicate Db at 30-AUG-13
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=155 devtype=DISK
contents of Memory Script:
{
   restore clone standby controlfile;
   sql clone 'alter database mount standby database';
}
executing Memory Script
Starting restore at 30-AUG-13
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/backup/0toig3u6_1_1
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/home/oracle/backup/0toig3u6_1_1 tag=TAG20130829T055102
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output filename=/home/oracle/oracle/product/10.2.0/oradata/standby/control01.ctl
output filename=/home/oracle/oracle/product/10.2.0/oradata/standby/control02.ctl
output filename=/home/oracle/oracle/product/10.2.0/oradata/standby/control03.ctl
Finished restore at 30-AUG-13
sql statement: alter database mount standby database
released channel: ORA_AUX_DISK_1
contents of Memory Script:
{
   set newname for tempfile  1 to
 "/home/oracle/oracle/product/10.2.0/oradata/standby/temp01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to
 "/home/oracle/oracle/product/10.2.0/oradata/standby/system01.dbf";
   set newname for datafile  2 to
 "/home/oracle/oracle/product/10.2.0/oradata/standby/undotbs01.dbf";
   set newname for datafile  3 to
 "/home/oracle/oracle/product/10.2.0/oradata/standby/sysaux01.dbf";
   set newname for datafile  4 to
 "/home/oracle/oracle/product/10.2.0/oradata/standby/users01.dbf";
   set newname for datafile  5 to
 "/home/oracle/oracle/product/10.2.0/oradata/standby/example01.dbf";
   restore
   check readonly
   clone database
   ;
}
executing Memory Script
executing command: SET NEWNAME
renamed temporary file 1 to /home/oracle/oracle/product/10.2.0/oradata/standby/temp01.dbf in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 30-AUG-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=155 devtype=DISK
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 /home/oracle/oracle/product/10.2.0/oradata/standby/system01.dbf
restoring datafile 00002 to /home/oracle/oracle/product/10.2.0/oradata/standby/undotbs01.dbf
restoring datafile 00003 to /home/oracle/oracle/product/10.2.0/oradata/standby/sysaux01.dbf
restoring datafile 00004 to /home/oracle/oracle/product/10.2.0/oradata/standby/users01.dbf
restoring datafile 00005 to /home/oracle/oracle/product/10.2.0/oradata/standby/example01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/backup/PROD_0qoig3k8_1_1.bckp
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/home/oracle/backup/PROD_0qoig3k8_1_1.bckp tag=TAG20130829T054544
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:11
Finished restore at 30-AUG-13
contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy recid=7 stamp=824821751 filename=/home/oracle/oracle/product/10.2.0/oradata/standby/system01.dbf
datafile 2 switched to datafile copy
input datafile copy recid=8 stamp=824821751 filename=/home/oracle/oracle/product/10.2.0/oradata/standby/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=9 stamp=824821751 filename=/home/oracle/oracle/product/10.2.0/oradata/standby/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=10 stamp=824821751 filename=/home/oracle/oracle/product/10.2.0/oradata/standby/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=11 stamp=824821751 filename=/home/oracle/oracle/product/10.2.0/oradata/standby/example01.dbf
Finished Duplicate Db at 30-AUG-13
RMAN> exit
Recovery Manager complete.
[oracle@pk dbs]$ sqlplus / as sysdba

 SYS@STANDBY > alter database recover managed standby database disconnect from session;
 Database altered.

 _________________________________________
      On the Primary:
_________________________________________

 SYS@PROD > alter system switch logfile;
 System altered.
SYS@PROD > alter system archive log current;
 System altered.
  
SYS@PROD > archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /home/oracle/archive/
Oldest online log sequence     16
Next log sequence to archive   18
Current log sequence           18
_______________________________________________
            ON STAND BY DATABASE
_______________________________________________
SYS@STANDBY > archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /home/oracle/archive/
Oldest online log sequence     16
Next log sequence to archive   0
Current log sequence           18
 SYS@STANDBY > SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
  SEQUENCE# APP
---------- ---
         8 NO
         9 NO
        10 NO
        11 NO
        12 NO
        13 YES
        14 YES
        15 YES
        16 YES
        17 YES
10 rows selected.
SYS@STANDBY > select recovery_mode  from v$archive_dest_status;
 RECOVERY_MODE
-----------------------
MANAGED
MANAGED
MANAGED
MANAGED
MANAGED
MANAGED
MANAGED
MANAGED
MANAGED
MANAGED
MANAGED
11 rows selected.
SYS@STANDBY > select max(sequence#) from v$log_history;
 MAX(SEQUENCE#)
--------------
            17
SYS@STANDBY > archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /home/oracle/archive/
Oldest online log sequence     18
Next log sequence to archive   0
Current log sequence           20
  
***********CHECK ON BOTH PRIMARY AND STAND BY SIDE*************
SYS@STANDBY >  select max(sequence#) from v$archived_log; 
MAX(SEQUENCE#)
--------------
            19