Tuesday, January 31, 2012



Oracle R12 MIDDLE TIER Concepts

OC4J Instances

 An OC4J instance is a logical instantiation of the OC4J implementation in Oracle Application Server. This implementation is Java 2 Enterprise Edition (J2EE) complete and written entirely in Java. It executes on the standard Java Development Kit (JDK) 1.4 Java Virtual Machine, which is installed with OracleAS (JDK 1.3 is supported). It has a lower disk and memory footprint than the previous Oracle Application Server Java environment and competitive Java application servers. Note that each OC4J instance can consist of more than one JVM process where each process can be executing multiple J2EE containers. The number of JVM processes can be specified for each OC4J instance using the Oracle Enterprise Manager Application Server Control GUI.
Oracle Application Server allows several OC4J instances to be clustered together for scalability and high availibility purposes. When OC4J instances are clustered together, they have the same configuration and applications deployed amongst them. A more in-depth discussion on clustering is found in the section "Oracle Application Server Support for High Availability and Load Balancing" below.

 Oracle Process Manager and Notification Server (OPMN) Server

 Each OracleAS instance has an OPMN server which performs monitoring and process management functions within that instance. This service communicates messages between the components in an OracleAS instance to enable startup, death-detection and recovery of components. This communication extends to other OPMN services in other OracleAS instances belonging to the same cluster as well, thereby allowing other instances in a cluster to be aware of active OC4J and Oracle HTTP Server processes in other OracleAS instances (in the same cluster).
The OPMN service also communicates and interfaces with Application Server Control to provide a consolidated interface for monitoring, configurating, and managing Oracle Application Server. Oracle Application Server components, Oracle HTTP Server, OC4J instances, and Distributed Configuration Manager (described below), use a subscribe-publish messaging mechanism to communicate with the OPMN service. For failover and availibility, the process that implements the OPMN service has a shadow process that restarts the OPMN process if it fails.

 Distributed Configuration Manager (DCM)

 In order to manage and track configuration changes in the various components in each OracleAS instance, a DCM process exists in each OracleAS instance to perform those tasks. Each configuration change made to any of the components in a OracleAS instance is communicated to the DCM. DCM in turn takes note of the change and records it in the Oracle Application Server Metadata Repository in the Infrastructure database. This repository contains the configuration information for all the OracleAS instances connected to it through their respective DCMs. All OracleAS instances connecting to the same infrastructure repository in this way belong to the same OracleAS Farm. If any of the OracleAS instances fail, the configuration information can be retrieved from the repository for purposes of restarting the instance.
Each DCM also communicates with the OPMN in their respective instances to send notification events on changes in repository data. This allows OPMN to make the corresponding adjustments to the Oracle Application Server components.


ADPATCH Options

You can execute adpatch by logging in as the applications OS user and sourcing the appropriate environment file.
#su – applmgr
$cd SAMAPPL
$. ./APPSORA.env
$adpatch
By default adpatch does not take any clause, but there are some clauses that you could use with adpatch
Running a patch in test mode
You can use the apply clause with adpatch to specify weather to run the patch in TEST mode or not, when you run the patch in  test mode it does not do any changes but runs generates a log fiule with all the actions it would have performed.
$adpatch apply=n|y
The default is apply=y
Pre-install Mode
You can also run a patch in pre install mode, this would be done normally during an upgrade or consolidated update. When a patch is applied in a preinstall mode the all the AD utilities are updated before the upgrade or update.
$adpatch preinstall=y
The default is preinstall=n
Other Options with adpatch
You can use the options clause to specify some of the other options available with adpatch.
Autoconfig
You can use the options=noautoconfig top specify autopatch that you do not wish to run autoconfig as a part of the patch  application. This can be useful when applying a large number of patches when they are not merged. By default autoconfig is run  as a part of adpatch.
$adpatch options=noautoconfig Checkfile
The chekfile option of adpatch tells adpathc to check for already executed exec, SQL, and exectier commands.You can use  options=nocheckfile skips this check, however this can cause performance overheds so should be used only when specified.
$adpatch options=nocheckfile
Compile Database
By defaulty autopatch compiles the invalid objects after the patch application, in case you wish not to do so you can specify  options=nocompiledb along with autopatch.
$adpatch options=nocompiledb
Compile JSP
By defaulty autopatch compiles the java server pages (jsp) after the patch application, in case you wish not to do so you can specify options=nocompilejsp along with autopatch.
$adpatch options=nocompilejsp
Copy Portion
If you wish adpatch not to execute the commands present in the copy driver portion of the patch you can use the  options=nocopyportion.
$adpatch options=nocopyportion
Database Portion
If you wish adpatch not to execute the commands present in the database driver portion of the patch you can use the options=nodatabaseportion.
$adpatch options=nodatabaseportion
Generate Portion
If you wish adpatch not to execute the commands present in the generate driver portion of the patch you can use the options=nogenerateportion

$adpatch options=nogenerateportion
Maintenance Mode
If you wish to apply a patch regardless of the system being in maintenance mode you can use options=hotpatch.
$adpatch options=hotpatch
Integrity Check
If you wish to check the integrity of the patch you can use the options=integrity. Since metalink patches are pre checked for  their integrity it is generally not required to do an explicit check and the default value is nointegrity.
$adpatch options=integrity
Maintain MRC
You can use the maintainmrc option to specify weather you wish adpatch to execute the Maintain MRC schema as a part of the patch application or not. By default maintain MRC is done for standard patches and is disbaled for tarnslation and documentation patches.
$adpatch options=nomaintainmrc
Pre requisite Patch Check
If you wish adpatch not to check for pre requisite patches before application of the main patch you can use options=noprereq.By default pre requsite checking is enabled.
$adpatch options=noprereq

Validate Schemas
If you wish adpatch to explicitly validate all the registed schems by making a connection you can use options=validate. By  default this validation is not performed.
$adpatch options=validate
Java Classes
If you wish adpatch not to copy new java classes from the patch you can use options=nojcopy.By default java classes are copied.
$adpatch options=nojcopy
Force Copy
By default adpatch copies the files without check the version of the existing files already present on the system.If you do  not wish the newer version of the file to be replaced by the older version contained in the patch use options=noforcecopy.
$adpatch options=noforcecopy
Relinking
If you wish adpatch not do perform relinking you can use options=nolink.
$adpatch options=nolink
Generate Forms
If you wish adpatch not to generate the forms files you can specify options=nogenform.
$adpatch options=nogenform
Generate Reports
If you wish adpatch not to generate the report files you can specify options=nogenrep.
$adpatch options=nogenrep
You could specify multiple options at the command line using the , delimiter.
$adpatch options=hotpatch,nojcopy





IMPORTANT LOG FILES LOCATIONS

 Startup/Shutdown Log files for Application Tier in R12
Instance Top is new TOP added in R12 (to read more click here)
Startup/Shutdown error message text files like adapcctl.txt, adcmctl.txt…
$INST_TOP/apps/$CONTEXT_NAME/logs/appl/admin/log
Startup/Shutdown error message related to tech stack (10.1.2, 10.1.3 forms/reports/web)
$INST_TOP/apps/$CONTEXT_NAME/logs/ora/  (10.1.2 & 10.1.3)
$INST_TOP/apps/$CONTEXT_NAME/logs/ora/10.1.3/Apache/error_log[timestamp]
$INST_TOP/apps/$CONTEXT_NAME/logs/ora/10.1.3/opmn/ (OC4J~…, oa*, opmn.log)$INST_TOP/apps/$CONTEXT_NAME/logs/ora/10.1.2/network/ (listener log)
$INST_TOP/apps/$CONTEXT_NAME/logs/appl/conc/log  (CM log files)
$COMMON_TOP/admin/log/$CONTEXT_NAME (11i -cm log)
B. Log files related to cloning in R12
Preclone log files in source instance
i) Database Tier - /$ORACLE_HOME/appsutil/log/$CONTEXT_NAME/(StageDBTier_MMDDHHMM.log)
ii) Application Tier - $INST_TOP/apps/$CONTEXT_NAME/admin/log/ (StageAppsTier_MMDDHHMM.log)
Clone log files in target instance

Database Tier - $ORACLE_HOME/appsutil/log/$CONTEXT_NAME/ApplyDBTier_<time>.log
Apps Tier  - $INST_TOP/apps/$CONTEXT_NAME/admin/log/ApplyAppsTier_<time>.log
—–
If your clone on DB Tier fails while running txkConfigDBOcm.pl  (Check metalink note - 415020.1)
During clone step on DB Tier it prompts for “Target System base directory for source homes” and during this you have to give like /base_install_dir like ../../r12 and not oracle home like ../../r12/db/tech_st_10.2.0
—–
C. Patching related log files in R12
i) Application Tier adpatch log - $APPL_TOP/admin/$SID/log/
ii) Developer (Developer/Forms & Reports 10.1.2) Patch - $ORACLE_HOME/.patch_storage
iii) Web Server (Apache) patch - $IAS_ORACLE_HOME/.patch_storage
iv) Database Tier opatch
 log - $ORACLE_HOME/.patch_storage
D. Autoconfig related log files in R12
i) Database Tier Autoconfig log :
$ORACLE_HOME/appsutil/log/$CONTEXT_NAME/MMDDHHMM/adconfig.log
$ORACLE_HOME/appsutil/log/$CONTEXT_NAME/MMDDHHMM/NetServiceHandler.log
ii) Application Tier Autoconfig log -  $INST_TOP/apps/$CONTEXT_NAME/admin/log/$MMDDHHMM/adconfig.log
Autoconfig context file location in R12 - $INST_TOP/apps/$CONTEXT_NAME/appl/admin/$CONTEXT_NAME.xml
E. R12 Installation Logs
Database Tier Installation
RDBMS $ORACLE_HOME/appsutil/log/$CONTEXT_NAME/<MMDDHHMM>.logRDBMS $ORACLE_HOME/appsutil/log/$CONTEXT_NAME/ApplyDBTechStack_<MMDDHHMM>.logRDBMS
$ORACLE_HOME/appsutil/log/$CONTEXT_NAME/ohclone.logRDBMS $ORACLE_HOME/appsutil/log/$CONTEXT_NAME/make_<MMDDHHMM>.logRDBMS
$ORACLE_HOME/appsutil/log/$CONTEXT_NAME/installdbf.logRDBMS $ORACLE_HOME/appsutil/log/$CONTEXT_NAME/adcrdb_<SID>.log RDBMS
$ORACLE_HOME/appsutil/log/$CONTEXT_NAME/ApplyDatabase_<MMDDHHMM>.logRDBMS $ORACLE_HOME/appsutil/log/$CONTEXT_NAME/<MMDDHHMM>/adconfig.log    RDBMS
$ORACLE_HOME/appsutil/log/$CONTEXT_NAME/<MMDDHHMM>/NetServiceHandler.log
Application Tier Installation
$INST_TOP/logs/<MMDDHHMM>.log
$APPL_TOP/admin/$CONTEXT_NAME/log/ApplyAppsTechStack.log
$INST_TOP/logs/ora/10.1.2/install/make_<MMDDHHMM>.log
$INST_TOP/logs/ora/10.1.3/install/make_<MMDDHHMM>.log
$INST_TOP/admin/log/ApplyAppsTechStack.log
$INST_TOP/admin/log/ohclone.log
$APPL_TOP/admin/$CONTEXT_NAME/log/installAppl.log
$APPL_TOP/admin/$CONTEXT_NAME/log/ApplyAppltop_<MMDDHHMM>.log
$APPL_TOP/admin/$CONTEXT_NAME/log/<MMDDHHMM>/adconfig.log
$APPL_TOP/admin/$CONTEXT_NAME/log/<MMDDHHMM>/NetServiceHandler.log
Inventory Registration:
$Global Inventory/logs/cloneActions<timestamp>.log
$Global Inventory/logs/oraInstall<timestamp>.log
$Global Inventory/logs/silentInstall<timestamp>.log
F. Other log files in R12
1) Database Tier
1.1) Relink Log files :
$ORACLE_HOME/appsutil/log/$CONTEXT_NAME /MMDDHHMM/ make_$MMDDHHMM.log
1.2) Alert Log Files :
$ORACLE_HOME/admin/$CONTEXT_NAME/bdump/alert_$SID.log
1.3) Network Logs :
$ORACLE_HOME/network/admin/$SID.log
1.4) OUI Logs :
OUI Inventory Logs :
$ORACLE_HOME/admin/oui/$CONTEXT_NAME/oraInventory/logs
2) Application Tier 
$ORACLE_HOME/j2ee/DevSuite/log
$ORACLE_HOME/opmn/logs
$ORACLE_HOME/network/logs
Tech Stack Patch 10.1.3 (Web/HTTP Server)
$IAS_ORACLE_HOME/j2ee/forms/logs
$IAS_ORACLE_HOME/j2ee/oafm/logs
$IAS_ORACLE_HOME/j2ee/oacore/logs
$IAS_ORACLE_HOME/opmn/logs
$IAS_ORACLE_HOME/network/log
$INST_TOP/logs/ora/10.1.2
$INST_TOP/logs/ora/10.1.3
$INST_TOP/logs/appl/conc/log
$INST_TOP/logs/appl/admin/log
If I missed any important log file name/location, drop a line via comment
$LOG_HOME/ora/10.1.2/forms
$LOG_HOME/ora/10.1.2/reports











[oracle@chain j2ee]$ find /oracle -name '*.log' -mtime -1  \! -type d -exec  ls -l {} \;

 /oracle/CHAIN/db/tech_st/10.2.0/admin/CHAIN_chain/bdump/alert_CHAIN.log

 /oracle/CHAIN/db/tech_st/10.2.0/network/admin/chain.log

 /oracle/CHAIN/inst/apps/CHAIN_chain/logs/ora/10.1.3/opmn/default_group~o acore~default_group~1.log

/oracle/CHAIN/inst/apps/CHAIN_chain/logs/ora/10.1.3/opmn/default_group~forms~default_group~1.log

/oracle/CHAIN/inst/apps/CHAIN_chain/logs/ora/10.1.3/opmn/default_group~oa fm~default_group~1.log

/oracle/CHAIN/inst/apps/CHAIN_chain/logs/ora/10.1.3/j2ee/forms/forms_default_group_1/server.log

/oracle/CHAIN/inst/apps/CHAIN_chain/logs/ora/10.1.3/j2ee/oafm/oafm_default_group_1/server.log

/oracle/CHAIN/inst/apps/CHAIN_chain/logs/ora/10.1.3/j2ee/oacore/oacore_default_group_1/application.log

/oracle/CHAIN/inst/apps/CHAIN_chain/logs/ora/10.1.3/j2ee/oacore/oacore_default_group_1/server.log

 /oracle/CHAIN/inst/apps/CHAIN_chain/logs/ora/10.1.2/network/apps_chain.lo g

/oracle/CHAIN/inst/apps/CHAIN_chain/logs/appl/conc/log/javacache.log

/oracle/CHAIN/inst/apps/CHAIN_chain/logs/appl/conc/log/reports.log

 /oracle/CHAIN/inst/apps/CHAIN_chain/logs/appl/rgf/javacache.log
[oracle@chain j2ee]$ tail -500f /oracle/CHAIN/inst/apps/CHAIN_chain/logs/appl/rgf/javacache.log

Monday, January 30, 2012


STEP BY STEP CONFIGURATION FOR ASM CREATION IN LINUX:

create ASM disk in command:
step1:
[root@dev140 oracle]# mkdir asm
[root@dev140 asm]# pwd
/oracle/asm
[root@dev140 asm]#
[root@dev140 ~]# dd if=/dev/sda2 of=/oracle/asm/disk-4 bs=1k count=5000000
output:

5000000+0 records in
5000000+0 records out

created 5gb disk
[root@dev140 ~]#

create 4 disk with same type

[root@dev140 ~]# cd /oracle/
[root@dev140 oracle]# chown -R oracle:dba asm/
[root@dev140 oracle]# chmod -R 777 asm/
[root@dev140 oracle]# cd asm/
[root@dev140 asm]# ll
total 20019600
-rwxrwxrwx  1 oracle dba 5120000000 Jan 23 16:53 disk-1
-rwxrwxrwx  1 oracle dba 5120000000 Jan 23 17:04 disk-2
-rwxrwxrwx  1 oracle dba 5120000000 Jan 23 17:06 disk-3
-rwxrwxrwx  1 oracle dba 5120000000 Jan 23 17:06 disk-4
[root@dev140 asm]#
step2:
[root@dev140 bin]$ pwd
/oracle/PROD/db/tech_st/10.2.0/bin
[root@dev140 bin]$
[root@dev140 bin]# localconfig all
output:
Usage:/oracle/PROD/db/tech_st/10.2.0/bin/localconfig [add] [delete] [ reset <destination Oracle home> ]   [-silent]   [-paramfile <Complete path of file specifying parameter values>]
[root@dev140 bin]# localconfig reset
output:
/etc/oracle does not exist. Creating it now.
/oracle/PROD/db/tech_st/10.2.0/bin/localconfig: line 549: /etc/oracle/ocr.loc: No such file or directory
/oracle/PROD/db/tech_st/10.2.0/bin/localconfig: line 571: [: too many arguments
Successfully accumulated necessary OCR keys.
Creating OCR keys for user 'root', privgrp 'root'..
Operation successful.
Configuration for local CSS has been initialized

Adding to inittab
Startup will be queued to init within 30 seconds.
Checking the status of new Oracle init process...
Expecting the CRS daemons to be up within 600 seconds.
CSS is active on these nodes.
        dev140
CSS is active on all nodes.
Oracle CSS service is installed and running under init(1M)
[root@dev140 bin]#

step3:  create ASM pwdfile & pfile
pwdfile:
[oracle@dev140 10.2.0]$ orapwd file=/oracle/PROD/db/tech_st/10.2.0/dbs/orapw+ASM password=sys

pfile: Parameter
_asm_allow_only_raw_disks=false
#asm_diskgroups='PROD_DATA1'
asm_diskstring='/oracle/asm/disk-*'
background_dump_dest=/oracle/PROD/db/tech_st/10.2.0/admin/PROD_dev140/bdump
core_dump_dest=/oracle/PROD/db/tech_st/10.2.0/admin/PROD_dev140/cdump
user_dump_dest=/oracle/PROD/db/tech_st/10.2.0/admin/PROD_dev140/udump
instance_type=asm
remote_login_passwordfile=exclusive
large_pool_size=12M
compatible=10.2.0.4.0
asm_power_limit=6
db_unique_name=+ASM

step 3: Startup steps

[oracle@dev140 dbs]$ export ORACLE_SID=+ASM
[oracle@dev140 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on Mon Jan 23 17:31:13 2012

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup
ASM instance started

Total System Global Area   83886080 bytes
Fixed Size                  1265912 bytes
Variable Size              57454344 bytes
ASM Cache                  25165824 bytes
ORA-15110: no diskgroups mounted
SQL> create spfile from pfile;

File created.

SQL> shu immediate
ORA-15100: invalid or missing diskgroup name


ASM instance shutdown
SQL> startup nomount
ASM instance started

Total System Global Area   83886080 bytes
Fixed Size                  1265912 bytes
Variable Size              57454344 bytes
ASM Cache                  25165824 bytes
SQL>

SQL> CREATE DISKGROUP testdb_data1 NORMAL REDUNDANCY
  2   FAILGROUP f1 DISK '/oracle/asm/disk-1','/oracle/asm/disk-2'
  3  FAILGROUP f2 DISK '/oracle/asm/disk-3','/oracle/asm/disk-4';

Diskgroup created.

SQL> shu immediate
ASM diskgroups dismounted
ASM instance shutdown
SQL> startup
ASM instance started

Total System Global Area   83886080 bytes
Fixed Size                  1265912 bytes
Variable Size              57454344 bytes
ASM Cache                  25165824 bytes
ASM diskgroups mounted

SQL>  shu immediate
ASM diskgroups dismounted
ASM instance shutdown
SQL> startup mount
ASM instance started

Total System Global Area   83886080 bytes
Fixed Size                  1265912 bytes
Variable Size              57454344 bytes
ASM Cache                  25165824 bytes
ASM diskgroups mounted
SQL> select group_number, name, total_mb, free_mb, state, type from v$asm_diskgroup;

GROUP_NUMBER NAME                             TOTAL_MB    FREE_MB STATE
------------ ------------------------------ ---------- ---------- -----------
TYPE
------
           1 TESTDB_DATA1                        19528      19422 MOUNTED
NORMAL


SQL>



EX:

1.Create Diskgroup:

SQL> CREATE DISKGROUP PRODDG NORMAL REDUNDANCY
  2  FAILGROUP f1 DISK '/oracle/asm/disk-1'
  3  FAILGROUP f2 DISK '/oracle/asm/disk-2';

Diskgroup created.

SQL>

2.    ADD Disk

SQL> ALTER DISKGROUP PRODDG add
  2  FAILGROUP f1 DISK '/oracle/asm/disk-3'
  3  FAILGROUP f2 DISK '/oracle/asm/disk-4';

Diskgroup altered.

SQL>


Migration:

step:1 Backup the controlfile

RMAN> backup current controlfile format '/oracle/aa.ctl';
Starting backup at 27-JAN-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
channel ORA_DISK_1: starting piece 1 at 27-JAN-12
channel ORA_DISK_1: finished piece 1 at 27-JAN-12
piece handle=/oracle/aa.ctl tag=TAG20120127T161724 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 27-JAN-12

RMAN> shutdown immediate;

database closed
database dismounted
Oracle instance shut down

RMAN> exit


Recovery Manager complete.
[oracle@dev140 dbs]$

STEP2: Add the pfile parameter

[oracle@dev140 dbs]# vi initPROD.ora

DB_CREATE_FILE_DEST = '+PRODDG'
DB_CREATE_ONLINE_LOG_DEST_1='+PRODDG'
control_files='+PRODDG'

step2:

SQL> startup nomount pfile='/oracle/PROD/db/tech_st/10.2.0/dbs/initPROD.ora';
ORACLE instance started.

Total System Global Area 1073741824 bytes
Fixed Size                  1271540 bytes
Variable Size             427821324 bytes
Database Buffers          633339904 bytes
Redo Buffers               11309056 bytes
SQL> create spfile from pfile;

File created.

SQL> shu immediate
ORA-01507: database not mounted


ORACLE instance shut down.

SQL>

STEP3: Restore Controfile
[oracle@dev140 dbs]$ rman target /

Recovery Manager: Release 10.2.0.4.0 - Production on Fri Jan 27 16:21:34 2012

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

connected to target database (not started)

RMAN> startup nomount

Oracle instance started

Total System Global Area    1073741824 bytes

Fixed Size                     1271540 bytes
Variable Size                427821324 bytes
Database Buffers             633339904 bytes
Redo Buffers                  11309056 bytes

RMAN>

RMAN> restore controlfile from '/oracle/aa.ctl';

RMAN>  backup as copy database format ='+PRODDG';

RMAN> switch database to copy;

RMAN> alter database open;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 01/27/2012 17:24:57
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

RMAN> backup archivelog all;
RMAN> recover database;

Exit

SQL> alter database open resetlogs;

Database altered.

SQL> alter database add logfile group 4;

Database altered.

SQL> alter database add logfile group 5;

Database altered.

SQL> alter database add logfile group 6;


Database altered.

SQL>

STEP4: Create New Redologs

SQL> alter database add logfile group 4;

Database altered.

SQL> alter database add logfile group 5;

Database altered.

SQL> alter database add logfile group 6;

Database altered.

STEP5: Removing Old redologs
We can drop only inactive status loggroups

SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS
---------- ---------- ---------- ---------- ---------- --- ----------------
FIRST_CHANGE# FIRST_TIM
------------- ---------
         1          1          6 1048576000          2 YES ACTIVE
   5.9651E+12 27-JAN-12

         2          1          7 1048576000          2 YES ACTIVE
   5.9651E+12 27-JAN-12

         4          1          8  104857600          1 YES ACTIVE
   5.9651E+12 27-JAN-12


    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS
---------- ---------- ---------- ---------- ---------- --- ----------------
FIRST_CHANGE# FIRST_TIM
------------- ---------
         5          1          9  104857600          1 YES ACTIVE
   5.9651E+12 27-JAN-12

         6          1         10  104857600          1 NO  CURRENT
   5.9651E+12 27-JAN-12


SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> /

System altered.

SQL> alter database drop logfile group 1;

Database altered.
SQL> alter database drop logfile group 2;

Database altered.

SQL>

SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS
---------- ---------- ---------- ---------- ---------- --- ----------------
FIRST_CHANGE# FIRST_TIM
------------- ---------
         4          1         12  104857600          1 YES INACTIVE
   5.9651E+12 27-JAN-12

         5          1         13  104857600          1 YES INACTIVE
   5.9651E+12 27-JAN-12

         6          1         14  104857600          1 NO  CURRENT
   5.9651E+12 27-JAN-12


SQL>

STEP 6: Create new TEMP tablespace & drop old TEMP tablespace.

SQL> create temporary tablespace TEMP_ASM tempfile size 2048m;

Tablespace created.

SQL> alter database default temporary tablespace TEMP_ASM;

Database altered.

SQL> select name from v$tablespace;

SQL>  drop tablespace TEMP1 including contents;

Tablespace dropped.

SQL> drop tablespace TEMP2 including contents;

Tablespace dropped.

SQL>





STEP BY STEP CONFIGURATION FOR DATA GUARD

Manually Create a Physical Standby Database

Primary Database name:TEST3
Standby Database name:TEST4
Primary Database Side:
1. Create a password file if it doesn’t exist.
To check if a password file already exists, run the following command:
SQL> select * from v$pwfile_users;
USERNAME SYSDB SYSOP SYSAS
----------------- ----- ----- -----
SYS TRUE TRUE FALSE
2) If it doesn’t exist, use the following command to create one:
Linux:$orapwd file=$ORACLE_HOME/dbs/orapw<db name> password=sys
3.    Configure a Standby Redo log.
The size of the standby redo log files should match the size of the current Primary database online redo log files. To find out the size of your online redo log files:
SQL> select bytes from v$log;
BYTES
----------
52428800
52428800
52428800
4.    Use the following command to determine your current log file groups:
SQL> select group#, member from v$logfile;
GROUP# MEMBER
--------------------------------------------------------------------------------
3 /oracle/11gdb/oradata/TEST3/redo03.log
2 /oracle/11gdb/oradata/TEST3/redo02.log
1 /oracle/11gdb/oradata/TEST3/redo01.log
5. Create standby Redo log groups.
My primary database had 3 log file groups originally and I created 3 standby redo log groups using the following commands:

SQL>ALTER DATABASE ADD STANDBY LOGFILE GROUP 4 'location' SIZE 50M;
SQL>ALTER DATABASE ADD STANDBY LOGFILE GROUP 5 'location'SIZE 50M;
SQL>ALTER DATABASE ADD STANDBY LOGFILE GROUP 6 'location'SIZE 50M;

6.    To verify the results of the standby redo log groups creation, run the following query:
SQL>select * from v$standby_log;
7.    Enable Archiving on Primary.
If your primary database is not already in Archive Log mode, enable the archive log mode:
SQL>shutdown immediate;
SQL>startup mount;
SQL>alter database archivelog;
SQL>alter database open;
SQL>archive log list;
5. Set Primary Database Initialization Parameters
Create a text initialization parameter file (PFILE) from the server parameter file (SPFILE), to add the new primary role parameters.
1) Create pfile from spfile for the primary database:

SQL>create pfile from spfile;
8.    Edit pfileTEST3.ora to add the new primary and standby role parameters:
Ex:initTEST3.ora
[oracle@track dbs]$ cat initTEST3.ora
TEST3.__db_cache_size=687865856
TEST3.__java_pool_size=16777216
TEST3.__large_pool_size=16777216
TEST3.__oracle_base='/oracle/11gdb'#ORACLE_BASE set from environment
TEST3.__pga_aggregate_target=687865856
TEST3.__sga_target=1006632960
TEST3.__shared_io_pool_size=0
TEST3.__shared_pool_size=268435456
TEST3.__streams_pool_size=0
*.audit_file_dest='/oracle/11gdb/admin/TEST3/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/oracle/11gdb/oradata/TEST3/control01.ctl','/oracle/11gdb/oradata/TEST3/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.DB_FILE_NAME_CONVERT='/oracle/11gdb/oradata/TEST4/','/oracle/11gdb/oradata/TEST3/'
*.db_name='TEST3'
*.db_recovery_file_dest_size=10737418240
*.db_recovery_file_dest='/oracle/11gdb/product/11.2.0/dbhome_1/flash_back'
*.db_unique_name='TEST3'
*.diagnostic_dest='/oracle/11gdb'
#*.dispatchers='(PROTOCOL=TCP) (SERVICE=TEST3XDB)'
*.FAL_CLIENT='TEST3'
*.FAL_SERVER='TEST4'
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(TEST3,TEST4)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/oracle/11gdb/product/11.2.0/dbhome_1/flash_back/TEST3/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=TEST3'
*.LOG_ARCHIVE_DEST_2='SERVICE=TEST4 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=TEST4'
*.LOG_ARCHIVE_DEST_STATE_1='ENABLE'
*.LOG_ARCHIVE_DEST_STATE_2='ENABLE'
*.LOG_ARCHIVE_FORMAT='%t_%s_%r.arc'
*.LOG_ARCHIVE_MAX_PROCESSES=30
*.LOG_FILE_NAME_CONVERT='/oracle/11gdb/oradata/TEST4/','/oracle/11gdb/oradata/TEST3/','/oracle/11gdb/product/11.2.0/dbhome_1/flash_back/TEST4/onlinelog','/oracle/11gdb/product/11.2.0/dbhome_1/flash_back/TEST3/onlinelog'
*.memory_target=1680867328
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.STANDBY_FILE_MANAGEMENT='AUTO'
*.undo_tablespace='UNDOTBS1'
*.local_listener=TEST3
[oracle@track dbs]$
9.    Create spfile from pfile, and restart primary database using the new spfile.
Data Guard must use SPFILE. Create the SPFILE and restart database.
SQL> shutdown immediate;
SQL> startup nomount pfile='<Path>'
SQL> create spfile from pfile='<Path>';
SQL>shutdown immediate;
SQL>startup
10.                        Standby Database Site:
1. Create a copy of Primary database data files on the Standby Server:
On Primary DB:
SQL>shutdown immediate;
On Standby Server (While the Primary database is shut down):
1) Create directory for data files.
2) Copy the data files and temp files over.
3) Create directory (multiplexing) for online logs,
4) Copy the online logs over.
5. Create a Control File for the standby database:
On Primary DB, create a control file for the standby to use:
SQL>startup mount;
SQL>alter database create standby controlfile as ‘TEST4.ctl;
SQL>ALTER DATABASE OPEN;
6. Copy the Primary DB pfile to Standby server and rename/edit the file.
Ex:
[oracle@track dbs]$ cat initTEST4.ora
TEST4.__db_cache_size=687865856
TEST4.__java_pool_size=16777216
TEST4.__large_pool_size=16777216
TEST4.__oracle_base='/oracle/11gdb'#ORACLE_BASE set from environment
TEST4.__pga_aggregate_target=687865856
TEST4.__sga_target=1006632960
TEST4.__shared_io_pool_size=0
TEST4.__shared_pool_size=268435456
TEST4.__streams_pool_size=0
*.audit_file_dest='/oracle/11gdb/admin/TEST4/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/oracle/11gdb/oradata/TEST4/TEST4.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='TEST3'
*.db_recovery_file_dest_size=10737418240
*.db_recovery_file_dest='/oracle/11gdb/product/11.2.0/dbhome_1/flash_back'
*.diagnostic_dest='/oracle/11gdb'
#*.dispatchers='(PROTOCOL=TCP) (SERVICE=TEST4XDB)'
#*.memory_target=1680867328
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*.db_unique_name=TEST4
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(TEST3,TEST4)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/oracle/11gdb/product/11.2.0/dbhome_1/flash_back/TEST4/archivelog/
VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=TEST4'

*.LOG_ARCHIVE_DEST_2='SERVICE=TEST3 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=TEST3'

*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
*.LOG_ARCHIVE_MAX_PROCESSES=30
*.remote_login_passwordfile='EXCLUSIVE'
*.FAL_SERVER=TEST3
*.FAL_CLIENT=TEST4
*.STANDBY_FILE_MANAGEMENT=AUTO

*.DB_FILE_NAME_CONVERT='/oracle/11gdb/oradata/TEST3/','/oracle/11gdb/oradata/TEST4/'
*.LOG_FILE_NAME_CONVERT='/oracle/11gdb/oradata/TEST3/','/oracle/11gdb/oradata/TEST4/','/oracle/11gdb/product/11.2.0/dbhome_1/flash_back/TEST3/onlinelog','/oracle/11gdb/product/11.2.0/dbhome_1/flash_back/TEST4/onlinelog'
*.local_listener=TEST4
[oracle@track dbs]$
7. On Standby server, create all required directories for dump and archived log destination:
Create directories adump, bdump, cdump, udump, and archived log destinations for the standby database.
8. Copy the standby control file ‘TEST4.ctl’ from primary to standby destinations ;
9. Copy the Primary password file to standby and rename it to pwdTEST4.ora.
Ex:
$oradim –NEW –SID STAN –STARTMODE manual
or
create a password file
Ex:
Linux:$orapwd file=$ORACLE_HOME/dbs/orapw<db name> password=sys

10. Configure listeners for the primary and standby databases.
On Primary system: use Oracle Net Manager to configure a listener for TEST3 and TEST4. Then restart the listener.
Ex:listener.ora
[oracle@track admin]$ cat listener.ora
# listener.ora Network Configuration File: /oracle/11gdb/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

TEST3 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.108)(PORT = 1523))
)
)
SID_LIST_TEST3 =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME=/oracle/11gdb/product/11.2.0/dbhome_1)
(SID_NAME = TEST3)
)
)

TEST4 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.108)(PORT = 1524))
)
)

SID_LIST_TEST4 =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME=/oracle/11gdb/product/11.2.0/dbhome_1/)
(SID_NAME = TEST4)
)
)

ADR_BASE_TEST3 = /oracle/11gdb

[oracle@track admin]$

$lsnrctl stop TEST3
$lsnrctl start TEST3
11. On Standby server: use Net Manager to configure a listener for TEST3 and TEST4. Then restart the listener.
$lsnrctl stop TEST4
$lsnrctl start TEST4
12.Create Oracle Net service names.
Ex:tnsnames.ora
[oracle@track admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /oracle/11gdb/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

TEST3 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.108)(PORT = 1523))
)
(CONNECT_DATA =
(SERVICE_NAME = TEST3)
(INSTANCE_NAME=TEST3)
)
)

TEST4 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.108)(PORT = 1524))
)
(CONNECT_DATA =
(SERVICE_NAME = TEST4)
(INSTANCE_NAME=TEST4)
)
)

[oracle@track admin]$
13. On Primary system: use Oracle Net Manager to create network service names for TEST3 and TEST4. Check tnsping to both services:
$tnsping TEST3
$tnsping TEST4
14.On Standby system: use Oracle Net Manager to create network service names for TEST3 and TEST4. Check tnsping to both services:
$tnsping TEST3
$tnsping TEST4
15. On Standby server, setup the environment variables to point to the Standby database.
Set up ORACLE_HOME and ORACLE_SID.
16. Start up nomount the standby database and generate a spfile.

SQL>startup nomount pfile=<path>


17.                        Start Redo apply
On the standby database, to start redo apply:
SQL>alter database recover managed standby database disconnect from session;
If you ever need to stop log apply services:
SQL> alter database recover managed standby database cancel;
18. Verify the standby database is performing properly:
On Standby perform a query:
SQL>select sequence#, first_time, next_time from v$archived_log;
On Primary, force a logfile switch:
SQL>alter system switch logfile;
19. On Standby, verify the archived redo log files were applied:
SQL>select sequence#, applied from v$archived_log order by sequence#;
20. If you want the redo data to be applied as it is received without waiting for the current standby redo log file to be archived, enable the real-time apply.
To start real-time apply:
SQL> alter database recover managed standby database using current logfile disconnect;





Switchover to Physical Standby Database




Primary Database Side:
Step 1 : Verify whether it is possible to perform a switchover
SQL> select switchover_status from v$database ;
SWITCHOVER_STATUS
--------------------
TO STANDBY
Step 2: Check the status of primary database.
SQL> select name,open_mode,db_unique_name from v$database;
NAME OPEN_MODE DB_UNIQUE_NAME
--------- -------------------- ------------------------------
TEST3 READ WRITE TEST3
Step 3: perform a log switch on the primary database
SQL> alter system switch logfile ;
System altered.
SQL> /
System altered.
SQL> /
System altered.
Step 4:Switch the Primary to Standby
SQL> alter database commit to switchover to physical standby;
Database altered.
SQL> select name,open_mode,db_unique_name from v$database;
select name,open_mode,db_unique_name from v$database
*
ERROR at line 1:
ORA-01507: database not mounted
SQL> shu immediate;
ORA-01507: database not mounted
ORACLE instance shut down.

Step 5: Startup the database (mount)
SQL> startup mount
ORACLE instance started.

Total System Global Area 1690705920 bytes
Fixed Size 1336960 bytes
Variable Size 1426065792 bytes
Database Buffers 251658240 bytes
Redo Buffers 11644928 bytes
Database mounted.
Step 6: Check the databases status
SQL> select name,open_mode,db_unique_name from v$database;

NAME OPEN_MODE DB_UNIQUE_NAME
--------- -------------------- ------------------------------
TEST3 MOUNTED TEST3
SQL> select name,open_mode,db_unique_name,switchover_status from v$database;
NAME OPEN_MODE DB_UNIQUE_NAME SWITCHOVER_STATUS
--------- -------------------- ------------------------ --------------------
TEST3 MOUNTED TEST3 TO PRIMARY

SQL> alter database open;
Database altered.
SQL> select name,open_mode ,db_unique_name,switchover_status from v$database;
NAME OPEN_MODE DB_UNIQUE_NAME SWITCHOVER_STATUS
--------- -------------------- ------------------------------ --------------------
TEST3 READ ONLY TEST3 RECOVERY NEEDED


Standby Database Side:

Step 1: Check the databases status
SQL> select name,open_mode,db_unique_name from v$database;
NAME OPEN_MODE DB_UNIQUE_NAME
--------- -------------------- ------------------------------
TEST3 READ ONLY TEST4
Step 2:Switch the target physical standby database role to the primary role
SQL> alter database commit to switchover to primary ;
alter database commit to switchover to primary
*
ERROR at line 1:
ORA-16139: media recovery required
Step 3: Try to recover
SQL> alter database recover managed standby database disconnect from session;



Database altered.



SQL> alter database commit to switchover to primary ;
alter database commit to switchover to primary
*
ERROR at line 1:
ORA-16139: media recovery required



Step 4: Down the database
SQL> shu immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.



Total System Global Area 150667264 bytes
Fixed Size 1335080 bytes
Variable Size 92274904 bytes
Database Buffers 50331648 bytes
Redo Buffers 6725632 bytes
Database mounted.
Database opened.
Step 5: Try to recover
SQL> alter database recover managed standby database disconnect from session;
Database altered.
Step 6:Switch the target physical standby database role to the primary role
SQL> alter database commit to switchover to primary ;
Database altered.
SQL> shu immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 150667264 bytes
Fixed Size 1335080 bytes
Variable Size 92274904 bytes
Database Buffers 50331648 bytes
Redo Buffers 6725632 bytes
Database mounted.
Database opened.
Step 7: Check the databases status
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ WRITE



SQL> select name,open_mode ,db_unique_name,switchover_status from v$database;
NAME OPEN_MODE DB_UNIQUE_NAME SWITCHOVER_STATUS
--------- -------------------- - ----------------------------- --------------------
TEST3         READ WRITE         TEST4                         TO STANDBY


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