Oracle - to create a single instance dg rac, and call the shots from the switch

I. Overview

This article describes how to build a single-node dg rac, and how to role reversal. Previously have the knowledge (RAC build single instance - to build single-instance dg)

 

Second, the experimental environment Introduction

Main library rac (already installed rac, and existing database orcl)
Rac1: 192.168.56.11, SID1: the ORCL1, Version: 11.2.0.4
rac2: 192.168.56.12, sid2: the ORCL2, Version: 11.2.0.4

From the library (single-instance database software has been installed, no database instance)
oradg: 192.168.56.102, sid: orcldg, Version: 11.2.0.4

1

 

Third, build dg

** All of the following main library operations are done on a node 1, node 2 if required to do in, I will be marked

 

1. Open the main library archive mode and the write log

First view archived state database and is turned to force to write the log, from the chart you can see the current database does not open the archive, nor turn force the write log
SQL> select log_mode, force_logging from v $ database;
3

The database is opened in the mount state of archiving
the SQL> ALTER System SET LOG_ARCHIVE_DEST_1 = 'LOCATION = + Data' SID = '*' scope = SPFILE;
the SQL> the shutdown immediate; # two nodes are closed
SQL> startup mount; # open only node. 1
the SQL > the ALTER Database ARCHIVELOG;
SQL> Open the ALTER Database;

Forced to write the log, the database will be able to modify the open state
SQL> alter database force logging;

SQL> startup; # 1open finished when the node, node 2 in the open database

Come to view archived state database and whether to force open the write log
SQL> select log_mode, force_logging from v $ database;
4

 

2. Open the primary library switches dataguard

SQL> alter system set log_archive_config = 'dg_config = (orcl, orcldg)' sid = '*'; # orcl is db_unique_name main library, orcldg from library db_unique_name

 

3. Main Library set up a remote archive

SQL> alter system set log_archive_dest_3='service=orcldg valid_for=(online_logfiles,primary_role) db_unique_name=orcldg' sid='*';

 

4. Transfer the master password file from the library to the library

[oracle@rac1 ~]$ scp $ORACLE_HOME/dbs/orapw$ORACLE_SID 192.168.56.102:$ORACLE_HOME/dbs/orapworcldg

 

5. From the library preparation parameter file

Here parameter files with built dg makes no difference to a single instance of a single instance, it is not specifically introduced
[root @ oradg ~] # vi $ ORACLE_HOME / dbs / initorcldg.ora

*.audit_file_dest='/u01/app/oracle/admin/orcldg/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/orcldg/controlfile/control01.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.diagnostic_dest='/u01/app/oracle'
*.log_archive_config='dg_config=(orcl,orcldg)'
*.log_archive_dest_2='location=/u01/app/oracle/oradata/orcldg/archstdlog/ valid_for=(standby_logfiles,standby_role) db_unique_name=orcldg'
*.memory_target=838860800
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='exclusive'
*.undo_tablespace='UNDOTBS1'
standby_file_management = auto # default value of the parameter is manual, which needs to be changed to auto, indicating the master data file is modified library (e.g., new, rename, etc.), but also correspondingly modified accordingly from the library
db_unique_name='orcldg'
db_file_name_convert='+DATA/orcl/datafile/','/u01/app/oracle/oradata/orcldg/datafile/','+DATA/orcl/tempfile/','/u01/app/oracle/oradata/orcldg/tempfile/'
log_file_name_convert='+DATA/orcl/onlinelog/','/u01/app/oracle/oradata/orcldg/onlinelog/'

 

6. Prepare the relevant catalog from the library 

[oracle@oradg ~]$ mkdir -p /u01/app/oracle/admin/orcldg/adump
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/controlfile
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/archstdlog
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/datafile
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/tempfile
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/onlinelog

 

7. Start from the library examples

[oracle@oradg ~]$ export ORACLE_SID=orcldg
[oracle@oradg ~]$ sqlplus / as sysdba
SQL> create spfile from pfile;
SQL> startup nomount

 

8. Configure from the library and start the listener

Because the use of duplicate data way to copy the main library, so it is necessary to form a static library from the configuration register

[oracle@oradg ~]$ vi $ORACLE_HOME/network/admin/listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = orcldg)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = orcldg)
    )
  )

LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.102)(PORT = 1521))
  )

 

[oracle@oradg ~]$ lsnrctl start

 

9. Main Library Configuration Naming Service 

# Two nodes should be set
[oracle @ rac1 ~] $ vi $ ORACLE_HOME / network / admin / tnsnames.ora

orcldg =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.102)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcldg)
    )
  )

 
[oracle @ rac2 ~] $ vi $ ORACLE_HOME / network / admin / tnsnames.ora
content consistent with rac1, slightly 

 

10. Main library from the library using a network connection (connectivity test)

# Sys password here my main library is 123456, consistent with the main library from the library
[oracle @ rac1 ~] $ sqlplus sys / 123456 @ orcldg as sysdba

 

11. copy from the library at the main library started rman

rman connection from the library and the master library
[oracle @ rac1 ~] $ rman target / auxiliary sys / 123456 @ orcldg

RMAN> duplicate target database for standby from active database;

 

12. Add standbylog from the library

Onlinelog add log size is consistent with the main library, the number more than two (onlinelog main library to view information log $ v)
Group numbers are not repeated and to the current onlinelog

[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/standbylog/
       
SQL> alter database add standby logfile group 21 '/u01/app/oracle/oradata/orcldg/standbylog/std01.log' size 50M;
SQL> alter database add standby logfile group 22 '/u01/app/oracle/oradata/orcldg/standbylog/std02.log' size 50M;
SQL> alter database add standby logfile group 23 '/u01/app/oracle/oradata/orcldg/standbylog/std03.log' size 50M;
SQL> alter database add standby logfile group 24 '/u01/app/oracle/oradata/orcldg/standbylog/std04.log' size 50M;
SQL> alter database add standby logfile group 25 '/u01/app/oracle/oradata/orcldg/standbylog/std05.log' size 50M;
SQL> alter database add standby logfile group 26 '/u01/app/oracle/oradata/orcldg/standbylog/std06.log' size 50M;

 

13. Open the application log from the library

SQL> alter database recover managed standby database disconnect from session;

 

14. A switching master archive library

SQL> alter system switch logfile;

 

15. Open from Library

After a period of time from the library archive application, you close the application archive log, open from the library.
SQL> Database Recover the ALTER Managed Database STANDBY the Cancel;
SQL> Open the ALTER Database;
SQL> the ALTER Database Recover a using Database Managed STANDBY Current logfile disconnect from the session;

 

16. Verify synchronous

Main library to make changes
SQL> Update scott.emp the SET SAL = 2000;
SQL> the commit;

From the database query
SQL> select * from scott.emp;

At this point, give rac dg build a single instance of it has been done, with the single instance dg build a single instance of no difference. Then we explain how to switch.

 

Fourth, prepared from the switching master

17. Add the primary database archive path standby logfile

Use grid account, create an archive path
[grid @ Rac1 ~] $ ASMCMD
ASMCMD> lsdg # view the disk group name
ASMCMD> cd the Data
ASMCMD> cd orcl
ASMCMD> mkdir ARCHSTDLOG

Use sys account database, to modify the parameters database
SQL> alter system set log_archive_dest_2 = ' location = + DATA / ORCL / ARCHSTDLOG / valid_for = (standby_logfiles, standby_role) db_unique_name = orcl' sid = '*';

 

18. The main library adds standby logfile

Onlinelog added with the size of the log of the primary database is consistent, the number of multiple groups (onlinelog main information repository view $ log V)
the SQL> ALTER STANDBY logfile the Add Database 21 is Thread Group. 1 ( '+ Data') size 50M;
the SQL> ALTER Database the Add STANDBY logfile Thread. 1 Group 22 is ( '+ Data') size 50M;
the SQL> ALTER Database the Add STANDBY logfile Thread. 1 Group 23 is ( '+ Data') size 50M;
the SQL> ALTER Database the Add STANDBY logfile Thread 2 Group 24 ( '+ Data') size 50M;
the SQL> ALTER STANDBY logfile the Add Database 25 Thread Group 2 ( '+ Data') size 50M;
the SQL> ALTER STANDBY logfile the Add Database 26 is Thread Group 2 ( '+ Data') size 50M;

 

19. The main library modify parameter files

SQL> alter system set standby_file_management=auto sid='*';
SQL> alter system set db_file_name_convert='/u01/app/oracle/oradata/orcldg/datafile/','+DATA/orcl/datafile/','/u01/app/oracle/oradata/orcldg/tempfile/','+DATA/orcl/tempfile/' sid='*' scope=spfile;
SQL> alter system set log_file_name_convert='/u01/app/oracle/oradata/orcldg/onlinelog/','+DATA/orcl/onlinelog/' sid='*' scope=spfile;

Here, the main library converted into a library equipment preparatory work has been completed!

 

20. From the configuration repository tnsnames.ora

The purpose here is to configure tnsnams.ora, when the transition from the library main library, the library becomes the original owner needs to send archive log from the library to the library of origin, so here tnsnames point of origin to the library, and because dg library application archive only can be in one node, only points to node 1 toorcl.

[oracle@oradg ~]$ vi $ORACLE_HOME/network/admin/tnsnames.ora

toorcl =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

 

21. From archive library path disposed onlinelog

[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/archivelog

SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/oradata/orcldg/archivelog/ valid_for=(online_logfiles,primary_role) db_unique_name=orcldg';

 

22. Set parameters from the remote archive library

SQL> alter system set log_archive_dest_3='service=toorcl valid_for=(online_logfiles,primary_role) db_unique_name=orcl';

Here, turn the main library from the library of the preparatory work has been completed!

 

Fourth, the master-slave switching

2

 

23. Check the state of role reversal main library

SQL> select database_role,switchover_status from v$database;
5 
  

24. transferred from the master node 1

Cluster role in doing the conversion, only one instance is open, the rest should be closed, so the node instance 2 is closed.
SQL> shutdown immediate; # only do on the node 2

On the node a command, from the library into the host library, and shut down the instance
SQL> alter database commit to switchover to  physical standby with session shutdown;

 

25. In the primary transfer from the node 3

SQL> select database_role,switchover_status from v$database;
6

如果是"NOT ALLOWED"表示归档还没有应用完成,可以等待一段时间

如果日志全部应用了再查看角色转换状态
SQL> select database_role,switchover_status from v$database;
7

如果角色转换状态是TO PRIMARY,那么表示可以进行角色转换

执行从转主的命令,命令执行成功后,数据库的状态会变为mount
SQL> alter database commit to switchover to primary;
SQL> alter database open;

 

26. 打开新从库

在节点1和节点2上
SQL> startup

节点1上应用归档
SQL> alter database recover managed standby database using current logfile disconnect from session;

节点3上切换归档
SQL> alter system switch logfile;

 

27. 验证同步

主库做修改
SQL> update scott.emp set sal=3000;
SQL> commit;

从库查询
SQL> select * from scott.emp;

 

28. 错误处理

如果发现日志传不到备库的话可以在主库通过以下命令查看错误原因

SQL> select dest_id,dest_name,log_sequence,status,error from v$archive_dest;
8

If the message above error, then restart the switch can be archived to
the SQL> SET ALTER System log_archive_dest_state_3 = 'the defer' SID = '*';
the SQL> SET ALTER System log_archive_dest_state_3 = 'enable' SID = '*';

 

V. Summary

1. dg handover needs to halt all applications, and to kill off all connected to a database of all, the whole lock the account, after the completion of the unlock switch
Example 2. rac when switching, leaving only a live, all other closing
3. each execution of a command, pay attention to the returned results, and real-time view alert.log

Guess you like

Origin www.cnblogs.com/ddzj01/p/12044310.html