本文包含以下两个知识点,欧博官网环境信息如下图所示:
部署Data Guard服务; Data Guard Broker的配置以及使用。
一、部署Physical Standby 1.1 主库准备工作 1.1.1启用force logging SQL> ALTER DATABASE FORCE LOGGING; 1. 1.1.2 创建standby数据库redo文件 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;
1.1.3 设置主库参数 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;
1.1.4 确保主库处于归档模式
1.1.5 编辑tnsnames.ora [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) ) )
1.1.6 配置静态监听地址 编辑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) ) )
切记,欧博必须重启监听方可生效。
1.2 备库准备工作 1.2.1 创建备库密码文件 直接复制主库的密码文件到备库相应目录。
[oracle@db03 dbs]$ scp orapwcdb db02:$ORACLE_HOME/dbs/ 1. 1.2.2 创建初始化文件 [oracle@db02 ~]$ cd $ORACLE_HOME/dbs [oracle@db02 dbs]$ echo DB_NAME=cdb>initcdb.ora 1. 2. 1.2.3 创建adump目录 [oracle@db02 ~]$ mkdir -p $ORACLE_BASE/admin/cdb/adump 1. 1.2.4 配置静态监听地址 编辑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) ) )
切记,欧博娱乐必须重启监听方可生效。
1.2.5 启动备库至nomount [oracle@db02 ~]$ sqlplus "/as sysdba" SQL> startup nomount
1.2.6 编辑tnsnames.ora [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) ) )
1.3 创建physical standby database与验证 1.3.1 创建备库 这里直接使用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'; }
脚本成功执行后,欧博allbet使用下面的SQL验证备库的状态:
SQL> select status,instance_name from v$instance;
1.3.2 启用redo日志应用 在主库节点先执行日志切换操作,然后在备库上启用redo日志应用。
SQL> alter database recover managed standby database using current logfile disconnect;
1.3.3 主备库角色验证 分别在主备库上,执行下面的SQL进行验证:
--主库 SQL> select database_role,switchover_status from v$database;
--备库 SQL> select database_role,switchover_status from v$database;
二、配置DG Broker服务 2.1 主备库启用broker 主备库上执行下面的SQL启用broker:
SQL> ALTER SYSTEM SET dg_broker_start=true scope=both; 1. 2.2 创建broker配置文件 执行下面的命令连接主库并创建配置文件:
[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 1. 在备库上,将LOG_ARCHIVE_DEST_2参数的值清空重新添加即可。
SQL> alter system set LOG_ARCHIVE_DEST_2=' ' scope=both; 1. 2.3 查看配置文件信息 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
2.4 使用dgmgrl执行主备切换 登录后复制 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) -----------------------------------
(责任编辑:)
|