本文包含如下兩個知識點,環境信息以下圖所示:sql
SQL> ALTER DATABASE FORCE LOGGING;
SQL> ALTER DATABASE ADD STANDBY LOGFILE SIZE 200M; SQL> ALTER DATABASE ADD STANDBY LOGFILE SIZE 200M; SQL> ALTER DATABASE ADD STANDBY LOGFILE SIZE 200M; SQL> ALTER DATABASE ADD STANDBY LOGFILE SIZE 200M;
SQL> alter system set log_archive_config='dg_config=(cdb,cdb_stby)' scope=both; SQL> alter system set log_archive_dest_2='service=cdb_stby async valid_for=(online_logfile,primary_role) db_unique_name=cdb_stby'; SQL> alter system set standby_file_management=auto;
[oracle@db03 admin]$ vi tnsnames.ora CDB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.120.83)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = cdb) ) ) CDB_STBY = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.120.82)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = cdb) (UR=A) ) )
編輯listener.ora文件,加入下面的內容:數據庫
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = cdb) (ORACLE_HOME = /u01/app/oracle/product/19.0.0/db_1) (SID_NAME = cdb) ) (SID_DESC = (GLOBAL_DBNAME = cdb_stby) (ORACLE_HOME = /u01/app/oracle/product/19.0.0/db_1) (SID_NAME = cdb) ) )
切記,必須重啓監聽方可生效。oracle
直接複製主庫的密碼文件到備庫相應目錄。app
[oracle@db03 dbs]$ scp orapwcdb db02:$ORACLE_HOME/dbs/
[oracle@db02 ~]$ cd $ORACLE_HOME/dbs [oracle@db02 dbs]$ echo DB_NAME=cdb>initcdb.ora
[oracle@db02 ~]$ mkdir -p $ORACLE_BASE/admin/cdb/adump
編輯listener.ora文件,加入下面的內容:async
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = cdb) (ORACLE_HOME = /u01/app/oracle/product/19.0.0/db_1) (SID_NAME = cdb) ) (SID_DESC = (GLOBAL_DBNAME = cdb_stby) (ORACLE_HOME = /u01/app/oracle/product/19.0.0/db_1) (SID_NAME = cdb) ) )
切記,必須重啓監聽方可生效。ide
[oracle@db02 ~]$ sqlplus "/as sysdba" SQL> startup nomount
[oracle@db02 admin]$ vi tnsnames.ora CDB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.120.83)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = cdb) ) ) CDB_STBY = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.120.82)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = cdb) (UR=A) ) )
這裏直接使用duplicate方式在線建立備庫,在rman中運行下面的腳本:ui
[oracle@db03 ~]$ rman target / auxiliary sys/abcABC12@cdb_stby run { allocate channel prmy1 type disk; allocate channel prmy2 type disk; allocate channel prmy3 type disk; allocate channel prmy4 type disk; allocate auxiliary channel stby type disk; duplicate target database for standby from active database spfile set db_unique_name='cdb_stby' set fal_client='cdb_stby' set fal_server='cdb' set standby_file_management='AUTO' set log_file_name_convert='/cdb/','/cdb_stby/' set db_file_name_convert='/cdb/','/cdb_stby/' set log_archive_config='dg_config=(cdb,cdb_stby)' set log_archive_dest_2='service=cdb ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=cdb'; }
腳本成功執行後,使用下面的SQL驗證備庫的狀態:rest
SQL> select status,instance_name from v$instance;
在主庫節點先執行日誌切換操做,而後在備庫上啓用redo日誌應用。日誌
SQL> alter database recover managed standby database using current logfile disconnect;
分別在主備庫上,執行下面的SQL進行驗證:code
--主庫 SQL> select database_role,switchover_status from v$database;
--備庫 SQL> select database_role,switchover_status from v$database;
主備庫上執行下面的SQL啓用broker:
SQL> ALTER SYSTEM SET dg_broker_start=true scope=both;
執行下面的命令鏈接主庫並建立配置文件:
[oracle@db03 ~]$ dgmgrl sys@cdb as sysdba DGMGRL for Linux: Release 19.0.0.0.0 - Production on Tue May 7 16:22:12 2019 Version 19.3.0.0.0 Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved. Welcome to DGMGRL, type "help" for information. Password: Connected to "cdb" Connected as SYSDBA. DGMGRL> create configuration dg_cfg as primary database is cdb connect identifier is cdb; Configuration "dg_cfg" created with primary database "cdb" DGMGRL> add database cdb_stby as connect identifier is cdb_stby maintained as physical; Database "cdb_stby" added DGMGRL> enable configuration; enabled. DGMGRL>
若是添加standby數據庫的時候,報以下錯誤:
ORA-16698: LOG_ARCHIVE_DEST_n parameter set for object to be added
在備庫上,將LOG_ARCHIVE_DEST_2參數的值清空從新添加便可。
SQL> alter system set LOG_ARCHIVE_DEST_2=' ' scope=both;
DGMGRL> show configuration; Configuration - dg_cfg Protection Mode: MaxPerformance Members: cdb - Primary database cdb_stby - Physical standby database Fast-Start Failover: Disabled Configuration Status: SUCCESS (status updated 17 seconds ago) DGMGRL> show database cdb; Database - cdb Role: PRIMARY Intended State: TRANSPORT-ON Instance(s): cdb Database Status: SUCCESS DGMGRL> show database cdb_stby; Database - cdb_stby Role: PHYSICAL STANDBY Intended State: APPLY-ON Transport Lag: 0 seconds (computed 0 seconds ago) Apply Lag: 0 seconds (computed 0 seconds ago) Average Apply Rate: 2.00 KByte/s Real Time Query: ON Instance(s): cdb Database Status: SUCCESS
DGMGRL> show configuration; Configuration - dg_cfg Protection Mode: MaxPerformance Members: cdb - Primary database cdb_stby - Physical standby database Fast-Start Failover: Disabled Configuration Status: SUCCESS (status updated 26 seconds ago) DGMGRL> switchover to cdb_stby; Performing switchover NOW, please wait... Operation requires a connection to database "cdb_stby" Connecting ... Connected to "cdb_stby" Connected as SYSDBA. New primary database "cdb_stby" is opening... Oracle Clusterware is restarting database "cdb" ... Connected to an idle instance. Connected to an idle instance. Connected to an idle instance. Connected to an idle instance. Connected to an idle instance. Connected to "cdb" Connected to "cdb" Switchover succeeded, new primary is "cdb_stby" DGMGRL> show configuration; Configuration - dg_cfg Protection Mode: MaxPerformance Members: cdb_stby - Primary database cdb - Physical standby database Fast-Start Failover: Disabled Configuration Status: SUCCESS (status updated 15 second ago)