例如源主库db_name为aaa
db_unique_name为aaa,实例名为aaa1,aaa2
ORACLE_SID为aaa1,aaa2
tnsnames.ora的服务名配置:aaa/dgaaa
则备库设置参考:db_name相同为aaa,db_unique_name不同为dgaaa,实例名为dgaaa1,dgaaa2
ORACLE_SID为dgaaa1,dgaaa2
tnsnames.ora的服务名配置:aaa/dgaaa
创建dg时,
准备密码文件:从主库拷贝出密码文件传到备库,注意格式orapw+实例名
拷贝密码文件到asm 中管理:
[root@dgrac1 ~]# su - grid
[grid@dgrac1 ~]$ asmcmd
ASMCMD> cd datac1
ASMCMD> pwcopy /u01/app/oracle/product/19c/dbhome_1/dbs/orapwdgaaa1 +DATA/DGDGAAA/orapwdgaaa
copying /u01/app/oracle/product/19c/dbhome_1/dbs/orapwdgaaa1 -> +DATA/DGDGAAA/orapwdgaaa
ASMCMD> ls -l +DATA/DGDGAAA/orapwdgaaa
准备参数文件,从主库创建出参数文件,去掉所有集群相关的参数,保留单节点的参数值,并用dgaaa替换所有aaa(除了db_name的名称不能修改)。根据物理内存等情况适当调整sga,pga等值。
然后启动到nomount状态。
配置备库单个节点的监听和tnsnames.ora连接,主备库都连接这个单节点的tnsnames.ora服务,
listener.ora
备库配置grid监听:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dgaaa)
(ORACLE_HOME = /u01/app/oracle/product/19c/dbhome_1)
(SID_NAME = dgaaa1)
)
)
tnsnames.ora
#连备库
dgaaa =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dgrac1-vip)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID= dgaaa1)
)
)
#连主库
aaa =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = exa-scan1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = aaa)
)
)
主备测试联通性sqlplus sys/xxx@dgaaa as sysdba
sqlplus sys/xxx@aaa as sysdba
等duplicate恢复备库完成后
[oracle@dgrac1 ~]$ cat dg.sh
rman target sys/xxx@aaa auxiliary sys/xxx@dgaaa log /home/oracle/rman-`date +%Y%m%d-%H%M`.log <<EOF
run
{
allocate channel cl1 type disk;
allocate auxiliary channel c1 type disk;
duplicate target database for standby from active database nofilenamecheck;
release channel c1;
release channel cl1;
}
EOF
nohup ./dg.sh &
修改参数文件,加回所有集群参数,并用dgaaa替换所有aaa(除了db_name的名称不能修改)
创建参数到共享存储位置:例如
create spfile='+DATAC1' from pfile='/home/oracle/dgaaa.txt';
检查asm中生成的spfile文件,记录路径
节点1的$ORACLE_HOME/dbs下创建initdgaaa1.ora
vi inithiscdb1.ora
spfile='+DATAC1/DGAAA/PARAMETERFILE/spfile.376.1148230649'
并拷贝到节点2为initdgaaa2.ora
备库rac添加资源:
[oracle@dgrac1 ~]$ srvctl add database -db dgaaa -dbname aaa -oraclehome /u01/app/oracle/product/19c/dbhome_1 -dbtype RAC -role PHYSICAL_STANDBY
[oracle@dgrac1 ~]$ srvctl add instance -db dgaaa -instance dgaaa1 -node dgrac1
[oracle@dgrac1 ~]$ srvctl add instance -db dgaaa -instance dgaaa2 -node dgrac2
[oracle@dgrac1 ~]$ srvctl modify database -db dgaaa -spfile '+DATAC1/dgaaa/PARAMETERFILE/spfile.376.1148230649' -pwfile '+DATAC1/dgaaa/orapwhiscdb' -diskgroup DATAC1,RECOC1
检查配置
[oracle@dgrac1 dbs]$ srvctl config database -db dgaaa
恢复监听,去掉单节点的静态注册(备库操作)
备库操作:
srvctl stop listener -n dgrac1
srvctl stop listener -n dgrac2
srvctl stop scan_listener
srvctl start listener -n dgrac1
srvctl start listener -n dgrac2
srvctl start scan_listener
srvctl status listener -n dgrac1
srvctl status listener -n dgrac2
srvctl status scan_listener
恢复tnsnames.ora:去掉只连接单实例SID的信息,改为scanip和service_name(主备操作)
#连备库
dgaaa =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dgrac-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dgaaa)
)
)
#连主库
aaa =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = exa-scan1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = aaa)
)
)
备库可启动:
[oracle@dgrac1 ~]$ srvctl stop database -d dgorcl -o immediate
[oracle@dgrac1 ~]$ srvctl start database -d dgorcl
[oracle@dgrac1 ~]$ sqlplus /nolog
SQL>show pdbs;
SQL>alter pluggable database open all instances=all;
--recover managed stanssdby database cancel;#停止redo apply
SQL> recover managed standby database disconnect using current logfile;#重启 redo apply
检查备库alert日志输出是否正常,在主库创建记录测试备库是否正常应用。
启停测试:
[oracle@dgrac1 ~]$ srvctl stop database -d dgorcl -o immediate