Oracle 11g R2 Dataguard configuration step by step

前端之家收集整理的这篇文章主要介绍了Oracle 11g R2 Dataguard configuration step by step前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Oracle 11g R2 Dataguard configuration step by step

Date: March 17,2016Author:Shripal Singh (DBA)

Note:-Oracle Database RDBMS software installed with one database on thePRIMARYserver and onSTANDBYserver installed only RDBMS software without any Database. Following below details:

Primary:

IP Address: 192.168.1.10
DB_NAME=db11g
DB_UNIQUE_NAME=db11g

Standby:

IP Address: 192.168.1.20
DB_NAME=db11g
DB_UNIQUE_NAME=std

required parameters:

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_CONVERTrequired when directory structure is different datafile
LOG_FILE_NAME_CONVERTrequired when directory structure is different logfile
STANDBY_FILE_MANAGEMENT – Keep auto to create file automatically on standby

Perform following steps on primary database:

Note:- Make sure primary database is runing in archivelog mode

Check your database mode using following command

  1. sql> select log_mode from v$database;
  2. OR
  3. sql> archive log list

If your database is not runing in archivelog mode use following command to change to archive mode.

  1. sql> SHU IMMEDIATE;
  2. sql> STARTUP MOUNT;
  3. sql> ALTER DATABASE ARCHIVELOG;
  4. sql> ALTER DATABASE OPEN;

Now your Database is runing in archivelog mode.

Note: –Make sure database is in force logging mode.

  1. sql> SELECT FORCE_LOGGING FROM V$DATABASE;

If not then following below command

  1. sql> ALTER DATABASE FORCE LOGGING;

Now verify DB_NAME and DB_UNIQUE_NAME of primary database

  1. sql> show parameter db_name
  2. sql> show parameter db_unique_name

Now MakeDB_UNIQUE_NAMEto be part of dataguard. (std service we will create soon)

  1. sql> alter system set log_archive_config=’DG_CONFIG=(db11g,std)’;

(db11g primary service name & std standby service name)

Then create service using “netmgr” command.

  1. sql> host
  2. $netmgr –> service add for std (+) –> net service name std –> hostname standby machine ip –> service name std –> save

Now start listener

  1. $lsnrctl start

Set archivelog destinations

  1. sql> alter system set log_archive_dest_2=’service=std
  2. Valid_for=(online_logfiles,primary_role) db_unique_name=std’;
  3. sql>alter system set log_archive_dest_state_2=enable;

Set remote login password to exclusive

  1. sql> alter system set remote_login_passwordfile=exclusive scope=spfile;
  2. 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.

  1. sql> ALTER SYSTEM SET FAL_SERVER=std;
  2. sql> ALTER SYSTEM SET DB_FILE_NAME_CONVERT=’std’,’db11g scope=spfile;
  3. sql> ALTER SYSTEM SET LOG_FILES_NAME_CONVERT=’std’,’db11g scope=spfile;
  4. sql> ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;

Now tack the backup primary database using RMAN

  1. $rman target=/
  2. RMAN> BACKUP DATABASE PLUS ARCHIVELOG;

Now create standby controlfile and pfile

  1. sql> ALTER DATABASE CREATE STANDBY CONTROLFILE AS ‘/u01/stdcontrol.ctl’;
  2. sql> CREATE PFILE=’/u01/initstd.ora from spfile;


Now edit your pfile

  1. $vi /u01/initstd.ora

Note:- YOUR PFILE PARAMETER LOCK LIKE THIS.

  1. std.__db_cache_size=318767104
  2. std.__java_pool_size=4194304
  3. std.__large_pool_size=4194304
  4. std.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
  5. std.__pga_aggregate_target=335544320
  6. std.__sga_target=503316480
  7. std.__shared_io_pool_size=0
  8. std.__shared_pool_size=159383552
  9. std.__streams_pool_size=4194304
  10. *.audit_file_dest='/u01/app/oracle/admin/std/adump'
  11. *.audit_trail='db'
  12. *.compatible='11.2.0.0.0'
  13. *.control_files='/u01/app/oracle/oradata/std/control01.ctl','/u01/app/oracle/fast_recovery_area/std/control02.ctl'
  14. *.db_block_size=8192
  15. *.db_domain=''
  16. *.db_file_name_convert='db11g','std'
  17. *.db_name='db11g'
  18. *.db_unique_name='std'
  19. *.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
  20. *.db_recovery_file_dest_size=4322230272
  21. *.diagnostic_dest='/u01/app/oracle'
  22. *.dispatchers='(PROTOCOL=TCP) (SERVICE=db11gXDB)'
  23. *.fal_server='DB11G'
  24. *.log_archive_config='DG_CONFIG=(db11g,std)'
  25. *.log_archive_dest_2='SERVICE=db11g VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db11g'
  26. *.log_archive_dest_state_2='ENABLE'
  27. *.log_file_name_convert='db11g','std'
  28. *.memory_target=836763648
  29. *.open_cursors=300
  30. *.processes=150
  31. *.remote_login_passwordfile='EXCLUSIVE'
  32. *.standby_file_management='AUTO'
  33. *.undo_tablespace='UNDOTBS1'

Save this file then create some directories on standby machine

  1. $mkdir -p /u01/app/oracle/admin/std/adump
  2. $mkdir -p /u01/app/oracle/oradata/std
  3. $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.

  1. #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

  1. #scp –r /u01/app/oracle/fast_recovery_area/DB11G oracle@192.168.1.20:/u01/app/oracle/fast_recovery_area/

Copy Parameter file

  1. #scp /u01/initstd.ora oracle@192.168.1.20:/u01/initstd.ora

Transfer remote login password file

  1. #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

  1. $export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/db_1

make tns service using below command

  1. $netmgr
  2. =>service naming
  3. + add new
  4. Net service name (db11g)
  5. Host name (server ip)
  6. Service name (db11g)
  7. Test your connection then finish
  8. Add one more service for standby server
  9. + add new
  10. Net service name (std)
  11. Host name (standby ip)
  12. Service name (std)
  13. Then finish

Then save click on file => save network configuration

start listner

  1. $lsnrctl start

Now update/etc/oratabfile on standby machine

  1. $vi /etc/oratab (add below line in end of file)
  2. Std:/u01/app/oracle/product/11.2.0.4/db_1:N


Restore backup on standby machine

  1. $export ORACLE_SID=std
  2. $sqlplus / as sysdba
  3. sql> create spfile from pfile=’/u01/initstd.ora’;

Now exit from sql prompt and login with RMAN then restore backup

sql> exit

  1. $rman target=/
  2. RMAN>startup mount
  3. RMAN> restore database;
  4. 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.

  1. $sqlplus / as sysdab
  2. sql> alter database add standby logfile (‘/u01/app/oracle/oradata/std/standby_redo01.log’) size 50m;
  3. sql> alter database add standby logfile (‘/u01/app/oracle/oradata/std/standby_redo02.log’) size 50m;
  4. sql> alter database add standby logfile (‘/u01/app/oracle/oradata/std/standby_redo03.log’) size 50m;
  5. 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.

Now check your log members and you can confirm using this command

  1. sql> select member from v$logfile where type=’STANDBY’;
  2. 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.

So now going on PRIMARY server and add redolog files.

  1. sql> alter database add standby logfile (‘/u01/app/oracle/oradata/db11g/standby_redo01.log’) size 50m;
  2. sql> alter database add standby logfile (‘/u01/app/oracle/oradata/db11g/standby_redo02.log’) size 50m;
  3. sql> alter database add standby logfile (‘/u01/app/oracle/oradata/db11g/standby_redo03.log’) size 50m;
  4. sql> alter database add standby logfile (‘/u01/app/oracle/oradata/db11g/standby_redo04.log’) size 50m;

Now CHECK….

  1. sql> select member from v$logfile where type=’STANDBY’;

Now start redo apply process on standby

Note: before applying redolog files,open alert logfile on different terminal

On standby machine

  1. sql> alter database recover managed standby database disconnect from session;

Run below command and check current redo sequence number

On primary server

  1. 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.

  1. sql> alter system switch logfile;

Then check what your current sequence number on PRIMARY machine is

  1. 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:-

  1. 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.

  1. sql> alter system switch logfile;

Now check DB mode and protection mode run below command on both machines

  1. sql> desc v$database
  2. sql> select name,open_mode,database_role,db_unique_name,protection_mode from v$database;

Now your Dataguard configuration is completed:

Steps to configure read only STANDBY

On STANDBY machine

Now I’m going to convert physical standby database into read only standby database.

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.

So what you do actually

  1. sql>Shu immediate
  2. sql>startup mount;
  3. sql>alter database open read only;

After running these all commands your database will be open in read only mode.

Check…

  1. sql> select name,protection_mode from v$database;
  2. sql> select * from scott.emp; (now you able to read your database)

Now login onPRIMARYmachine and run switch log file command

  1. sql>alter system switch logfile;

OnSTANDBYcheck redo applying or not

  1. sql> select sequence#,applied from v$archived_log order by sequence#;

Note:-You can see redo files but it’s not applied

So if you’re standby database in read only mode then redo are not applying.

If you want to bring back to physical standby following below steps

  1. sql> shu immediate
  2. sql> startup mount
  3. sql> alter database recover managed standby database disconnect from session;

After that check redo applying or not

So this is your physical standby database in read only mode,

But in oracle 11g have new featureACTIVE DATAGUARD.

How to configureACTIVE DATAGUARD

InACTIVE DATAGUARDfeature we can open standby database in read only mode and also can apply log files.

Steps almost same like read only standby database

  1. sql>shu immediate
  2. sql>startup mount;
  3. sql>alter database open read only;
  4. sql>alter database recover managed standby database disconnect from session;

Now you can check open mode

  1. sql> select name,protection_mode from v$database;

And check redo apply

  1. sql> select sequence#,applied from v$archived_log order by sequence#;

Enjoy

猜你在找的Oracle相关文章