Thursday 25 June 2015

How To Enable & Configure Dataguard And Create One Standby Database with Switching? 

Follow the steps as they are and you will be able to configure and enable dataguard.

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

Primary Database Name : PRMDB

On primary database :

- sqlplus sys/password@prmdb as sysdba

- select name, log_mode,database_role,force_logging from v$database;
Archive log and force logging should be enabled on primary database.

- shut immediate

- set oracle_sid=prmdb

- sqlplus / as sysdba

- startup mount

- alter database archivelog;

- alter database open;

- alter database force logging;.

- select name, log_mode,database_role,force_logging from v$database;

- exit

- Now create a new folder on same machine in D:\ drive or wherever feasible for first standby database 'STLDB'.

"D:\Oracle\ORADATA\STLDB\CONTROLFILE"

"D:\Oracle\FRA\STLDB"

- Now open cmd and create pfile and controlfile;

- set oracle_sid=prmdb

- sqlplus / as sysdba

- create pfile='D:\oracle\PFILESTLDB.ora' from spfile;

- alter database create standby controlfile as 'D:\oracle\ORADATA\STLDB\CONTROLFILE\CONTROL01.CTL';

- exit

- Open pfile created in notepad and replace 'prmdb' with 'stldb'

- Change the control file path as 'D:\oracle\ORADATA\STLDB\CONTROLFILE\CONTROL01.CTL'

- Add following parameters:

*.db_name='PRMDB'
*.db_unique_name='STLDB'

- Change path for *.db_recovery_file_dest as 'D:\oracle\FRA'

- Now create oracle instance and password file :

- oradim -new -sid STLDB

- Copy the password file of PRMDB And paste as same location 'D:\app\Admin\product\11.2.0\dbhome_1\database\'. Rename the copied file as PWDSTLDB.ora

- Add the entry of STLDB in TNSNAMES.ora and listener.ora and restart the listener.

- Now startup the STLDB database in nomount mode from the created pfile.

- set oracle_sid=stldb

- sqlplus / as sysdba

- create spfile from pfile='D:\oracle\PFILESTLDB.ora';

- startup nomount

- show parameter control_f

- Open the database in mount mode

- alter database mount

- select name from v$datafile;

- Now copy all the oradata files of PRMDB from primary to standby(D:\oracle\ORADATA\STLDB\) database except controlfile.

- set oracle_sid=prmdb

- sqlplus / as sysdba

- shut immediate

- Now copy all the oradata files except controlfile.

- Now startup the PRMDB database.

- startup

- exit

- set oracle_sid=stldb

- sqlplus / as sysdba

- select name from v$datafile;

- select name from v$tempfile;

- select member from v$logfile;

- Now we will rename datafile, logfile and tempfile for standby database

- show parameter STAND

- alter system set standby_file_management='MANUAL';

- alter database rename file 'D:\app\Admin\oradata\PRMDB\SYSAUX01.DBF' to 'D:\oracle\ORADATA\STLDB\SYSAUX01.DBF';

- alter database rename file 'D:\app\Admin\oradata\PRMDB\SYSTEM01.DBF' to 'D:\oracle\ORADATA\STLDB\SYSTEM01.DBF';

- alter database rename file 'D:\app\Admin\oradata\PRMDB\UNDOTBS01.DBF' to 'D:\oracle\ORADATA\STLDB\UNDOTBS01.DBF';

- alter database rename file 'D:\app\Admin\oradata\PRMDB\USERS01.DBF' to 'D:\oracle\ORADATA\STLDB\USERS01.DBF';

- alter database rename file 'D:\app\Admin\oradata\PRMDB\REDO01.LOG' to 'D:\oracle\ORADATA\STLDB\REDO01.LOG';

- alter database rename file 'D:\app\Admin\oradata\PRMDB\REDO02.LOG' to 'D:\oracle\ORADATA\STLDB\REDO02.LOG';

- alter database rename file 'D:\app\Admin\oradata\PRMDB\REDO03.LOG' to 'D:\oracle\ORADATA\STLDB\REDO03.LOG';

- alter database rename file 'D:\app\Admin\oradata\PRMDB\TEMP01.DBF' to 'D:\oracle\ORADATA\STLDB\TEMP01.DBF';

- select name from v$datafile;

- select name from v$tempfile;

- select member from v$logfile;

- exit

- Now we are creating a data guard configuration with dataguard command line interface.

- set oracle_sid=PRMDB

- DGMGRL /

- show configuration

- exit

- set oracle_sid=PRMDB

- sqlplus / as sysdba

- show parameter dg_

- alter system set dg_broker_start=TRUE scope=both;

- exit

- set oracle_sid=stldb

- sqlplus / as sysdba

- show parameter dg_

- alter system set dg_broker_start=TRUE scope=both;

- exit

- Now, add standby logs to primary and standby database.

- sqlplus sys/password@prmdb as sysdba

- alter database add standby logfile ('D:\app\Admin\oradata\PRMDB\SLOG01.LOG') size 500M;

- alter database add standby logfile ('D:\app\Admin\oradata\PRMDB\SLOG02.LOG') size 500M;

- alter database add standby logfile ('D:\app\Admin\oradata\PRMDB\SLOG03.LOG') size 500M;

- exit

- sqlplus sys/password@stldb as sysdba

- alter database add standby logfile ('D:\oracle\ORADATA\STLDB\SLOG01.LOG') size 500M;

- alter database add standby logfile ('D:\oracle\ORADATA\STLDB\SLOG02.LOG') size 500M;

- alter database add standby logfile ('D:\oracle\ORADATA\STLDB\SLOG03.LOG') size 500M;

- exit

-  CREATE CONFIGURATION DG AS
   PRIMARY DATABASE IS prmdb
   CONNECT IDENTIFIER IS prmdb;
  
- ADD DATABASE stldb
   AS CONNECT IDENTIFIER IS stldb
   MAINTAINED AS PHYSICAL;
  
- enable configuration;

- show configuration

- exit

- sqlplus sys/password@prmdb as sysdba

- show parameter log_arch

- Now check that the archive logs will be created in both databases on switching redo log files

- alter system switch logfile;

"D:\oracle\FRA\STLDB\ARCHIVELOG\2015_06_25"
"D:\app\Admin\flash_recovery_area\PRMDB\ARCHIVELOG\2015_06_25"

- Now we can check database roles

- select database_role from v$database;

- exit

- sqlplus sys/password@stldb as sysdba

- select database_role from v$database;

- exit

- Switching the primary and standby databases:

- set oracle_sid=prmdb

- sqlplus / as sysdba

- alter database commit to switchover to PHYSICAL STANDBY WITH SESSION SHUTDOWN;

====================

- Connect to standby database 'stldb' and run the following command :

- alter database commit to switchover to primary;

- select database_role from v$database;

- alter database open;

====================


Cheers!
























No comments:

Post a Comment