Oracle 11g R2 Dataguard configuration step by step
Date: March 17,2016Author:Shripal Singh (DBA)@H_502_5@
Note:-Oracle Database RDBMS software installed with one database on thePRIMARYserver and onSTANDBYserver installed only RDBMS software without any Database. Following below details:@H_502_5@
Primary:@H_502_5@
IP Address: 192.168.1.10
DB_NAME=db11g
DB_UNIQUE_NAME=db11g@H_502_5@
Standby:@H_502_5@
IP Address: 192.168.1.20
DB_NAME=db11g
DB_UNIQUE_NAME=std@H_502_5@
DB_NAME – Must be same on primary and on all standby
DB_UNIQUE_NAME – Must be different on primary and all standby
LOG_ARCHIVE_CONFIG – This parameter includes db_unique_name which are the part of Dataguard configuration
LOG_ARCHIVE_DEST_n – Define local and remote archive log file location
LOG_ARCHIVE_DEST_STATE_n – Define state of archiving (ENABLE or DIFER)
REMOTE_LOGIN_PASSWORDFILE – Must be in EXCLUSIVE mode
FAL_SERVER – Use for archivelog gap resolution (required only in physical standby server)
DB_FILE_NAME_CONVERT – required when directory structure is different datafile
LOG_FILE_NAME_CONVERT – required when directory structure is different logfile
STANDBY_FILE_MANAGEMENT – Keep auto to create file automatically on standby@H_502_5@
Perform following steps on primary database:
Note:- Make sure primary database is runing in archivelog mode@H_502_5@
Check your database mode using following command@H_502_5@
sql> select log_mode from v$database; OR sql> archive log list
If your database is not runing in archivelog mode use following command to change to archive mode.@H_502_5@
sql> SHU IMMEDIATE; sql> STARTUP MOUNT; sql> ALTER DATABASE ARCHIVELOG; sql> ALTER DATABASE OPEN;
Now your Database is runing in archivelog mode.@H_502_5@
Note: –Make sure database is in force logging mode.@H_502_5@
sql> SELECT FORCE_LOGGING FROM V$DATABASE;
If not then following below command@H_502_5@
sql> ALTER DATABASE FORCE LOGGING;
Now verify DB_NAME and DB_UNIQUE_NAME of primary database@H_502_5@
sql> show parameter db_name sql> show parameter db_unique_name
Now MakeDB_UNIQUE_NAMEto be part of dataguard. (std service we will create soon)@H_502_5@
sql> alter system set log_archive_config=’DG_CONFIG=(db11g,std)’;
(db11g primary service name & std standby service name)@H_502_5@
Then create service using “netmgr” command.@H_502_5@
sql> host $netmgr –> service add for std (+) –> net service name std –> hostname standby machine ip –> service name std –> save
Now start listener@H_502_5@
$lsnrctl start
Set archivelog destinations@H_502_5@
sql> alter system set log_archive_dest_2=’service=std Valid_for=(online_logfiles,primary_role) db_unique_name=std’; sql>alter system set log_archive_dest_state_2=enable;
Set remote login password to exclusive@H_502_5@
sql> alter system set remote_login_passwordfile=exclusive scope=spfile; sql> show parameter remote_login
Set fail server and file name convert parameter in case if directory structure is different in primary and standby database.@H_502_5@
sql> ALTER SYSTEM SET FAL_SERVER=std; sql> ALTER SYSTEM SET DB_FILE_NAME_CONVERT=’std’,’db11g’ scope=spfile; sql> ALTER SYSTEM SET LOG_FILES_NAME_CONVERT=’std’,’db11g’ scope=spfile; sql> ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;
Now tack the backup primary database using RMAN@H_502_5@
$rman target=/ RMAN> BACKUP DATABASE PLUS ARCHIVELOG;
Now create standby controlfile and pfile@H_502_5@
sql> ALTER DATABASE CREATE STANDBY CONTROLFILE AS ‘/u01/stdcontrol.ctl’; sql> CREATE PFILE=’/u01/initstd.ora’ from spfile;
Now edit your pfile@H_502_5@
$vi /u01/initstd.ora
Note:- YOUR PFILE PARAMETER LOCK LIKE THIS.@H_502_5@
std.__db_cache_size=318767104 std.__java_pool_size=4194304 std.__large_pool_size=4194304 std.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment std.__pga_aggregate_target=335544320 std.__sga_target=503316480 std.__shared_io_pool_size=0 std.__shared_pool_size=159383552 std.__streams_pool_size=4194304 *.audit_file_dest='/u01/app/oracle/admin/std/adump' *.audit_trail='db' *.compatible='11.2.0.0.0' *.control_files='/u01/app/oracle/oradata/std/control01.ctl','/u01/app/oracle/fast_recovery_area/std/control02.ctl' *.db_block_size=8192 *.db_domain='' *.db_file_name_convert='db11g','std' *.db_name='db11g' *.db_unique_name='std' *.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area' *.db_recovery_file_dest_size=4322230272 *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=db11gXDB)' *.fal_server='DB11G' *.log_archive_config='DG_CONFIG=(db11g,std)' *.log_archive_dest_2='SERVICE=db11g VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db11g' *.log_archive_dest_state_2='ENABLE' *.log_file_name_convert='db11g','std' *.memory_target=836763648 *.open_cursors=300 *.processes=150 *.remote_login_passwordfile='EXCLUSIVE' *.standby_file_management='AUTO' *.undo_tablespace='UNDOTBS1'
Save this file then create some directories on standby machine@H_502_5@
$mkdir -p /u01/app/oracle/admin/std/adump $mkdir -p /u01/app/oracle/oradata/std $mkdir -p /u01/app/oracle/fast_recovery_area/std
After creating appropriate directory on physical standby and copy backupset,archivelog,pfile,standby controlfile and password file to physical standby database.@H_502_5@
#scp /u01/stdcontrol.ctl oracle@192.168.1.20:/u01/app/oracle/oradata/std/control01.ctl #scp /u01/stdcontrol.ctl oracle@192.168.1.20:/u01/app/oracle/fast_recovery_area/std /control02.ctl
Transfer archivelog and backups@H_502_5@
#scp –r /u01/app/oracle/fast_recovery_area/DB11G oracle@192.168.1.20:/u01/app/oracle/fast_recovery_area/
Copy Parameter file@H_502_5@
#scp /u01/initstd.ora oracle@192.168.1.20:/u01/initstd.ora
Transfer remote login password file@H_502_5@
#scp /u01/app/oracle/product/11.2.0.4/db_1/dbs/orapwdb11g oracle@192.168.1.20:/u01/app/oracle/product/11.2.0.4/db_1/dbs/orapwstd
On physical standby server@H_502_5@
$export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/db_1
make tns service using below command@H_502_5@
$netmgr =>service naming + add new Net service name (db11g) Host name (server ip) Service name (db11g) Test your connection then finish Add one more service for standby server + add new Net service name (std) Host name (standby ip) Service name (std) Then finish
Then save click on file => save network configuration@H_502_5@
start listner@H_502_5@
$lsnrctl start
Now update/etc/oratabfile on standby machine@H_502_5@
$vi /etc/oratab (add below line in end of file) Std:/u01/app/oracle/product/11.2.0.4/db_1:N
Restore backup on standby machine@H_502_5@
$export ORACLE_SID=std $sqlplus / as sysdba sql> create spfile from pfile=’/u01/initstd.ora’;
Now exit from sql prompt and login with RMAN then restore backup@H_502_5@
$rman target=/ RMAN>startup mount RMAN> restore database; RMAN> exit
Note:-After finishing restore database we need to create standby redo log file on standby server,and it should be one extra either then online redo log file.@H_502_5@
$sqlplus / as sysdab sql> alter database add standby logfile (‘/u01/app/oracle/oradata/std/standby_redo01.log’) size 50m; sql> alter database add standby logfile (‘/u01/app/oracle/oradata/std/standby_redo02.log’) size 50m; sql> alter database add standby logfile (‘/u01/app/oracle/oradata/std/standby_redo03.log’) size 50m; sql> alter database add standby logfile (‘/u01/app/oracle/oradata/std/standby_redo04.log’) size 50m;
Note:-we have needed to add four redo log files because we have three online redo log file.@H_502_5@
Now check your log members and you can confirm using this command@H_502_5@
sql> select member from v$logfile where type=’STANDBY’; sql> select member from v$logfile;
Note:-Now we need to create same online redolog files on PRIMARY machine also in case you planing switch the role so if your primary become STANDBY then you need to have STANDBY redolog files.@H_502_5@
So now going on PRIMARY server and add redolog files.@H_502_5@
sql> alter database add standby logfile (‘/u01/app/oracle/oradata/db11g/standby_redo01.log’) size 50m; sql> alter database add standby logfile (‘/u01/app/oracle/oradata/db11g/standby_redo02.log’) size 50m; sql> alter database add standby logfile (‘/u01/app/oracle/oradata/db11g/standby_redo03.log’) size 50m; sql> alter database add standby logfile (‘/u01/app/oracle/oradata/db11g/standby_redo04.log’) size 50m;
Now CHECK….@H_502_5@
sql> select member from v$logfile where type=’STANDBY’;
Now start redo apply process on standby@H_502_5@
Note: before applying redolog files,open alert logfile on different terminal@H_502_5@
On standby machine@H_502_5@
sql> alter database recover managed standby database disconnect from session;
Run below command and check current redo sequence number@H_502_5@
On primary server@H_502_5@
sql> select sequence#,first_time,next_time from v$archived_log order by sequence#;
Now switch the log file using following command and check it’s applying on standby server or not.@H_502_5@
sql> alter system switch logfile;
Then check what your current sequence number on PRIMARY machine is@H_502_5@
sql> select sequence#,next_time from v$archived_log order by sequence#;
Then going on STANDBYmachine and check redo are going on standby machine or not.
STANDBY:-@H_502_5@
sql> select sequence#,next_time,applied from v$archived_log order by sequence#;
Now going on PRIMARYmachine and run switch logfile command one more time.@H_502_5@
sql> alter system switch logfile;
Now check DB mode and protection mode run below command on both machines@H_502_5@
sql> desc v$database sql> select name,open_mode,database_role,db_unique_name,protection_mode from v$database;
Now your Dataguard configuration is completed:@H_502_5@
Steps to configure read only STANDBY@H_502_5@
On STANDBY machine@H_502_5@
Now I’m going to convert physical standby database into read only standby database.@H_502_5@
In this case what happen your database will be in read only mode.Let me show you how to convert physical standby server into read only mode.@H_502_5@
So what you do actually@H_502_5@
sql>Shu immediate sql>startup mount; sql>alter database open read only;
After running these all commands your database will be open in read only mode.@H_502_5@
Check…@H_502_5@
sql> select name,protection_mode from v$database; sql> select * from scott.emp; (now you able to read your database)
Now login onPRIMARYmachine and run switch log file command@H_502_5@
sql>alter system switch logfile;
OnSTANDBYcheck redo applying or not@H_502_5@
sql> select sequence#,applied from v$archived_log order by sequence#;
Note:-You can see redo files but it’s not applied@H_502_5@
So if you’re standby database in read only mode then redo are not applying.@H_502_5@
If you want to bring back to physical standby following below steps@H_502_5@
sql> shu immediate sql> startup mount sql> alter database recover managed standby database disconnect from session;
After that check redo applying or not@H_502_5@
So this is your physical standby database in read only mode,
But in oracle 11g have new featureACTIVE DATAGUARD.@H_502_5@
How to configureACTIVE DATAGUARD@H_502_5@
InACTIVE DATAGUARDfeature we can open standby database in read only mode and also can apply log files.@H_502_5@
Steps almost same like read only standby database@H_502_5@
sql>shu immediate sql>startup mount; sql>alter database open read only; sql>alter database recover managed standby database disconnect from session;
Now you can check open mode@H_502_5@
sql> select name,protection_mode from v$database;
And check redo apply@H_502_5@
sql> select sequence#,applied from v$archived_log order by sequence#;
Enjoy@H_502_5@ 原文链接:https://www.f2er.com/oracle/207208.html