本文包含以下两个知识点,环境信息如下图所示:
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@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文件,加入下面的内容:
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@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中运行下面的脚本:
[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验证备库的状态:
SQL> select status,instance_name from v$instance;
在主库节点先执行日志切换操作,然后在备库上启用redo日志应用。
SQL> alter database recover managed standby database using current logfile disconnect;
分别在主备库上,执行下面的SQL进行验证:
--主库
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)
转载于:https://blog.51cto.com/candon123/2390513