Tuesday, 25 February 2020

Configuring Data guard 12cR2 on Linux
Oracle Data Guard is basically a disaster recover solution for enterprises, but also term it as a maximum availability solution.
Oracle Data Guard ensures high availability, data protection, and disaster recovery for enterprise data. 
Data Guard provides a comprehensive set of services that create, maintain, manage, and monitor one or more standby databases to enable production Oracle databases to survive disasters and data corruptions. Data Guard maintains these standby databases as transactionally consistent copies of the production database. Then, if the production database becomes unavailable because of a planned or an unplanned outage, Data Guard can switch any standby database to the production role, minimizing the downtime associated with the outage. Data Guard can be used with traditional backup, restoration, and cluster techniques to provide a high level of data protection and data availability.
In my current blog, i will show how to configure oracle data guard on linux.
Let's start with machine preparation: 

Please follow my above blog link for the installation of 12c DB, while creating the DB, Go with coventional setup of single tenant architecture on primary node, while on standby db machine you need to install software only.
Once the installation is done, lets start preparing the DB for DG: 

su - oracle

sqlplus / as sysdba

SELECT LOG_MODE FROM V$DATABASE ;

Or simply

SQL> archive log list;
Convert the database to archive log mode:

SQL> shutdown immediate;

SQL> startup mount;

SQL> alter database archivelog;

SQL> alter database open;

Database altered.

               Enable the force logging:

SQL>ALTER DATABASE FORCE LOGGING;


         ALTER SYSTEM SWITCH LOGFILE;

Add standby by redo log files

ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 10 ('/u01/app/oracle/oradata/DB12C/standby_redo01.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 11 ('/u01/app/oracle/oradata/DB12C/standby_redo02.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 12 ('/u01/app/oracle/oradata/DB12C/standby_redo03.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 13 ('/u01/app/oracle/oradata/DB12C/standby_redo04.log') SIZE 50M;

If you want to use flashback database, enable it on the primary now, so it will be enabled on the standby also. i would recommend you to enable the flash back feature so that we can use advance features of DG broker like database reinstate.  It's very useful as you will see below.

ALTER DATABASE FLASHBACK ON;
Initialization Parameters
Check the setting for the DB_NAME and DB_UNIQUE_NAME parameters. In this case they are both set to "cdb1" on the primary database.

SQL> show parameter db_name

NAME      TYPE VALUE
------------------------------------ ----------- ------------------------------
db_name      string DB12C

SQL> show parameter db_unique_name

NAME      TYPE VALUE
------------------------------------ ----------- ------------------------------
db_unique_name      string DB12C

SQL>


Setting the standby file management

ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;
Now setting up listener file properties and tnsname.ora file
both files can be found @ /u01/app/oracle/product/12.2.0/db12c/network/admin

it is recommended to keep copy of old file before changing any value.
Listener.ora file should be like:

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = primary-db)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = DB12C_DGMGRL)
      (ORACLE_HOME = /u01/app/oracle/product/12.2.0/db12c)
      (SID_NAME = DB12C)
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

tnsname.ora file should have below enteries:

DB12C =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = primary-db)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = DB12C)
    )
  )

DB12C_STBY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = standby-db)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = DB12C)
    )
  )

Once these file are set, stop the listener and start the service again.


check the services set by using tnsping utility, they should be pingable:


So primary DB listener services are all set, now these 2 files should be copy to standby db with same location of primary

scp listener.ora oracle@19*.1**.1.**:/u01/app/oracle/product/12.2.0/db12c/network/admin/

scp tnsname.ora oracle@19*.1**.1.**:/u01/app/oracle/product/12.2.0/db12c/network/admin/



create spfile for standby and having proper changes

CREATE PFILE='/tmp/initDB12C_stby.ora' FROM SPFILE;
Make changes according to your environment:
vi /tmp/initDB12C.stby.ora

*.db_name='DB12C'
*.log_archive_dest_2='SERVICE=db12c ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=DB12c'
*.fal_server='DB12c'

add/ change these values in pfile created/
now move this pfile to standby DB;

scp initDB12C_stby.ora oracle@19*.1**.1.**:/tmp

Copying the paswordfile of Primary DB to standby DB 

scp orapwDB12C oracle@19*.1**.1.**:/u01/app/oracle/product/12.2.0/db12c/dbs/



Primary site is almost ready to go, now lets prepare the standby DB site:

Creating same directory structure on Standby DB

mkdir -p /u01/app/oracle/fast_recovery_area/DB12C
mkdir -p /u01/app/oracle/oradata/DB12C
mkdir -p /u01/app/oracle/admin/DB12C/adump

Actually i will demonstrate the, how to copy the same DB to standby location through RMAN duplicated command using auxiliary connection, for auxiliary connection i've already did the setting in listener and tnsname files.

let's start an auxiliary instance on standby DB:

$ export ORACLE_SID=DB12C
$ sqlplus / as sysdba

SQL> STARTUP NOMOUNT PFILE='/tmp/initDB12C_stby.ora';


once instance has been started now its time to copy the database to standby instance  by connecting to RMAN and establing auxiliary connection with standby DB

$ rman TARGET sys/oracle@db12c AUXILIARY sys/oracle@db12c_stby

Now issue the following DUPLICATE command.

DUPLICATE TARGET DATABASE
  FOR STANDBY
  FROM ACTIVE DATABASE
  DORECOVER
  SPFILE
    SET db_unique_name='DB12C_stby' COMMENT 'Is standby'
  NOFILENAMECHECK;



Once the database copy is completed, now its time to start apply process, in case of manual handling of data guard.

now check the last archive log generated at primary site and confirm the archive log at standby database:
Primary site:

Standby Site:

By default the protection mode will be maximum performance:
Until and unless the DG broker is configured all the operation like protection mode change, Role transition, checking configuration status etc will be done manual.






















Wednesday, 30 October 2019

Patch Application (GI Home & DB Home) /Applying/Installing the Patch from an Oracle RAC Home Installation Manually

Oracle provides you a patches each quarter, either to fix the bugs reported or to improve performance of DB or security measure. In this blog, i will demonstrate how to apply patch to two nodes RAC of version 11.2.0.4
Download the patch from oracle support website using support id, place that patch on the oracle server and unzip that folder.

1- we have to create ocm file, it is basically a parameters file, which will be used during patch application.

Creation of OCM_FILE

/u01/app/11.2.0/grid/OPatch/ocm/bin/emocmrsp  -no_banner -output /u01/app/11.2.0/grid/ocm_file.rsp






2- Login through oracle user and stop the executable used, by issuing below command:

/u01/app/oracle/product/11.2.0/bin/srvctl stop home -o /u01/app/oracle/product/11.2.0 -s /tmp/state1.txt -n racnode1




3- Stop all the RAC services on that specific node, by issued below command:



4- Once all the service are down, its the time to patch up the Grid home:
 a- Apply first patch using command:
/u01/app/11.2.0/grid/OPatch/opatch napply -oh /u01/app/11.2.0/grid -local /u01/30070097/29938455 -ocmrf /u01/app/11.2.0/grid/ocm_file.rsp



b- Apply second patch:
/u01/app/11.2.0/grid/OPatch/opatch apply -oh /u01/app/11.2.0/grid -local /u01/30070097/29509309 -ocmrf /u01/app/11.2.0/grid/ocm_file.rsp


 c- Apply the third patch:
/u01/app/11.2.0/grid/OPatch/opatch apply -oh /u01/app/11.2.0/grid -local /u01/30070097/29913194 -ocmrf /u01/app/11.2.0/grid/ocm_file.rsp



All three patches are successfully applied to GRID_HOME, Now we need to switch to DB_HOME to apply patches given by oracle for DB_HOME
Before application of application we need to run some preopatch command:

/u01/30070097/29938455/custom/server/29938455/custom/scripts/prepatch.sh -dbhome /u01/app/oracle/product/11.2.0


Apply first patch to DB Home:

/u01/app/oracle/product/11.2.0/OPatch/opatch napply -oh /u01/app/oracle/product/11.2.0 -local /u01/30070097/29938455/custom/server/29938455/ -ocmrf /u01/app/11.2.0/grid/ocm_file.rsp



 Apply second patch to DB Home:

/u01/app/oracle/product/11.2.0/OPatch/opatch apply -oh /u01/app/oracle/product/11.2.0 -local /u01/30070097/29913194 -ocmrf /u01/app/11.2.0/grid/ocm_file.rsp



Once all patches provided are applied, we have to run postpatch command as below:

/u01/30070097/29938455/custom/server/29938455/custom/scripts/postpatch.sh -dbhome /u01/app/oracle/product/11.2.0

Exit from Oracle User and login to root user and execute below command:

/u01/app/11.2.0/grid/rdbms/install/rootadd_rdbms.sh


Now starting high availiblity services:

 /u01/app/11.2.0/grid/crs/install/rootcrs.pl -patch


All patches have successfully been applied to GI and Oracle home now we need to apply
Loading Modified SQL Files into the Database

cd $ORACLE_HOME/rdbms/admin
sqlplus /nolog
SQL> CONNECT / AS SYSDBA
SQL> STARTUP
SQL> @catbundle.sql psu apply
SQL> QUIT

When it is completed now you can check the status of patches applied using patch inventory command:

/u01/app/oracle/product/11.2.0/OPatch/opatch lsinventory












Tuesday, 29 October 2019

Patch Deinstallaion (GI Home & DB Home) /Rolling Back the Patch from an Oracle RAC Home Installation Manually

Oracle sends patches each quarter or against any bug reported by end user. In this blog we will demonstrate how to deinstall or rolling back oracle patch provided by oracle on 16 Oct 2019, Patch applied to GI Home and DB Home. Execute the following on each node of the cluster in non-shared CRS and DB home environment to rollback the patch.

First of all we have to check the patch number which are applied to GI home and DB home, by issuing command:

1- $ GI_HOME/OPatch/Opatch lsinventory

It will display all the main patches, subpatches and the bugs fixed by that patch:

similarly from oracle home we should issue the same commad to check the patches number:
$ ORACLE_HOME/OPatch/opatch lsinventory

2- Stop the CRS managed resources running from DB homes.
$ <ORACLE_HOME>/bin/srvctl stop home -o <ORACLE_HOME> -s <status file location> -n <node name>

$ /u01/app/11.2.0/grid/bin/srvctl stop home -o /u01/app/11.2.0/grid -s /tmp/statedeinstall.txt -n racnode2

now check the status:

Now bring down all the services using command :
3- Run the pre root script.
 If this is a GI Home, as the root user execute:
 # <GI_HOME>/crs/install/rootcrs.pl -unlock

#
/u01/app/11.2.0/grid/crs/install/rootcrs.pl -unlock

4- Now rolling back the Patches :

As the GI home owner execute:
 $ <GI_HOME>/OPatch/opatch rollback -local -id <OCW Components_number> -oh <GI_HOME>


$ /u01/app/11.2.0/grid/OPatch/opatch rollback -local -id  29938455 -oh /u01/app/11.2.0/grid       

$ <GI_HOME>/OPatch/opatch rollback -local -id <ACFS Components_number> -oh <GI_HOME>

$/u01/app/11.2.0/grid/OPatch/opatch rollback -local -id  29509309 -oh /u01/app/11.2.0/grid

$ <GI_HOME>/OPatch/opatch rollback -local -id <DB_PSU_number> -oh <GI_HOME>

$ /u01/app/11.2.0/grid/OPatch/opatch rollback -local -id  29913194 -oh /u01/app/11.2.0/grid

 -------------------------------DB Home Patches Deinstallation------------------------------------------

 5- Run the pre script for DB component of the patch.

 As the database home owner execute:
 $ <UNZIPPED_PATCH_LOCATION>/<GI_PSU_number>/<OCW Components_number>/custom/server/<OCW Components_number>/custom/scripts/prepatch.sh -dbhome <ORACLE_HOME>

$ /u01/30070097/29938455/custom/server/29938455/custom/scripts/prepatch.sh -dbhome /u01/app/oracle/product/11.2.0


-- Roll back the DB patch from the database home.
 As the database home owner execute:
 $ <ORACLE_HOME>/OPatch/opatch rollback -local -id <OCW Components_number> -oh <ORACLE_HOME>

$ /u01/app/oracle/product/11.2.0/OPatch/opatch rollback -local -id /u01/30070097/29938455/ -oh /u01/app/oracle/product/11.2.0

$ <ORACLE_HOME>/OPatch/opatch rollback -local -id <DB_PSU_number> -oh <ORACLE_HOME>


$/u01/app/oracle/product/11.2.0/OPatch/opatch rollback -local -id 29913194 -oh /u01/app/oracle/product/11.2.0

6-  Run the post script for DB component of the patch.
 As the database home owner execute:
 $ <UNZIPPED_PATCH_LOCATION>/<GI_PSU_number>/<OCW Components_number>/custom/server/<OCW Components_number>/custom/scripts/postpatch.sh -dbhome <ORACLE_HOME>


 $/u01/30070097/29938455/custom/server/29938455/custom/scripts/postpatch.sh -dbhome /u01/app/oracle/product/11.2.0

/**************************DONE*********************************/

7. Run the post script.
 As the root user execute:
 # <GI_HOME>/rdbms/install/rootadd_rdbms.sh



 $ /u01/app/11.2.0/grid/rdbms/install/rootadd_rdbms.sh

If this is a GI Home, as the root user execute:
 # <GI_HOME>/crs/install/rootcrs.pl -patch


$ /u01/app/11.2.0/grid/crs/install/rootcrs.pl -patch

 Now checking the Database instance status after the patches are being successfully deinstalled.
Both nodes are up & running:


Checking the GI Home for patches, check patch inventory

$ /u01/app/11.2.0/grid/OPatch/opatch lsinventory

 There is no interim patch installed.

Now checking the DB home:

$ /u01/app/oracle/product/11.2.0/OPatch/opatch lsinventory


No interim patch have been installed , one done on all nodes, run Patch Post-Deinstallation Instructions for an Oracle RAC Environment, that are:


Loged in to DB:

cd $ORACLE_HOME/rdbms/admin
sqlplus /nolog
SQL> CONNECT / AS SYSDBA
SQL> @catbundle_PSU_<database SID PREFIX>_ROLLBACK.sql
SQL> QUIT


In an Oracle RAC environment, the name of the rollback script will have the format catbundle_PSU_<database SID PREFIX>_ROLLBACK.sql.



cd $ORACLE_HOME/rdbms/admin
sqlplus /nolog
SQL> CONNECT / AS SYSDBA
SQL> @utlrp.sql

Check the log file for any errors. The log file is found in $ORACLE_BASE/cfgtoollogs/catbundle and is named catbundle_PSU_<database SID>_ROLLBACK_<TIMESTAMP>.log where TIMESTAMP is of the form YYYYMMMDD_HH_MM_SS. If there are errors, see Known Issues.

Installing Oracle 11g on Linux

Unpack Files Unzip the files. # 11.2.0.1 unzip linux.x64_11gR2_database_1of2.zip unzip linux.x64_11gR2_database_2of2.zip #11.2.0.2 u...