1.rac 开启归档
1)修改cluster_database 修改为false
alter system set cluster_database=false scope=spfile sid='olracdb1';
2)关闭所有实例数据库
srvctl stop database -db racdb
3)启动olracdb1本地实例挂载数据库
startup mount;
4)启动归档
alter database archivelog;
5)修改归档日志文件参数和路径
注意:log_archive_dest_1和log_archive_dest冲突两者只能设置一个
alter system set log_archive_format='%t_%s_%r.arc' scope=spfile sid='*';
alter system set log_archive_dest_1='location=+data/olracdb/archivelog' scope=spfile sid='*';
6)修改cluster_databae 值为true
alter system set cluster_database=true scope=spfile sid='racdb1';
7)关闭实例启动数据库
shutdown immediate;
srvctl start database -db racdb
2.修改主库参数
1启用强制日志
select force_logging from v$database;
alter database force logging;
2.设置主库初始化参数
alter system set db_unique_name='olracdb' scope=spfile;
alter system set db_unique_name=olracdb scope=spfile; #不加单引号设置的db_unique_name为大写
alter system set log_archive_config='DG_CONFIG=(olracdb,olracdg)' scope=both sid='*';
alter system set log_archive_dest_1='LOCATION=+data/olracdb/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=olracdb' scope=both sid='*';
alter system set log_archive_dest_2='SERVICE=tnsolracdg LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=olracdg' scope=both sid='*';
3.设置转换文件路径
注意:如果不做主备切换这个值不用设置
alter system set db_file_name_convert='/u01/app/oracle/oradata/olracdg','+DATA/olracdb/datafile','/u01/app/oracle/oradata/olracdg','+DATA/olracdb/tempfile' scope=spfile sid='*';
alter system set log_file_name_convert='/u01/app/oracle/oradata/olracdg','+DATA/olracdb/onlinelog' scope=spfile sid='*';
4.设置主备数据文件添加自动同步
alter system set standby_file_management=auto scope=both sid='*';
5.设置切换client/server
注意:如果不做主备切换这个值不用设置
alter system set fal_client='tnsolracdb' scope=both sid='*';
alter system set fal_server='tnsolracdg' scope=both sid='*';
6.设置访问服务
修改tnsname.ora 文件
注意:两边都要设置
TNSOLRACDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.131)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = olracdb)
)
)
TNSOLRACDG =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.134)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = olracdg)
)
)
测试
tnsping 192.168.5.131 1522
tnsping 192.168.5.134 1522
3.备库设置
1.拷贝密码文件
变化:
11g及之前版本数据库中密码文件存储在$ORACLE_HOME/dbs下
orapwSID
12C开始,密码文件存放在ASM共享存储中。
查询密码文件位置:
srvctl config database -d olracdb
su - grid
asmcmd cp +DATA/OLRACDB/PASSWORD/pwdolracdb.287.1035686333 /home/grid/orapwolracdg
2.创建spfile
touch initolracdg.ora
db_name='olracdb'
db_unique_name='olracdg'
sga_target=3G
pga_aggregate_target=800M
audit_file_dest='/u01/app/oracle/admin/olracdg/adump'
compatible='19.0.0'
remote_login_passwordfile='EXCLUSIVE'
control_files='/u01/app/oracle/oradata/olracdg/control01.ctl','/u01/app/oracle/oradata/olracdg/control02.ctl'
log_archive_config='DG_CONFIG=(olracdb,olracdg)'
log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=olracdg'
log_archive_dest_2='SERVICE=tnsolracdb LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=olracdb'
log_archive_format='%t_%s_%r.arc'
db_file_name_convert='+DATA/OLRACDB/DATAFILE','/u01/app/oracle/oradata/olracdg','+DATA/OLRACDB/TEMPFILE','/u01/app/oracle/oradata/olracdg'
log_file_name_convert='+DATA/OLRACDB/ONLINELOG','/u01/app/oracle/oradata/olracdg'
fal_client='tnsolracdg'
fal_server='tnsolracdb'
standby_file_management='AUTO'
db_recovery_file_dest='/u01/app/oracle/fast_recovery_area/'
db_recovery_file_dest_size=20g
db_create_file_dest='/u01/app/oracle/oradata'
mkdir /u01/app/oracle/fast_recovery_area -p
mkdir /u01/app/oracle/admin/olracdg/adump -p
mkdir /u01/app/oracle/oradata/olracdg -p
3.配置备库监听
su - grid
netca 创建listener_dg
netmgr 配置listener_dg 端口,$ORACLE_HOME路径
lsnrctl start listener_dg
listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = olracdg)
(ORACLE_HOME = /u01/app/oracle/product/19.3.0.0/dbhome_1)
(SID_NAME = olracdg)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.134)(PORT = 1522))
)
ADR_BASE_LISTENER = /u01/app/oracle
测试
sqlplus sys/Oracle123@tnsolracdg as sysdba
sqlplus sys/Oracle123@tnsolracdb as sysdba
4.设置环境变量
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/19.3.0.0/dbhome_1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
alias sqlplus='rlwrap sqlplus'
export PATH
4.使用Duplicate创建物理standby
1.duplicate
1.1离线—rman备份集
1.2在线—duplicate,适合局域网
rman target sys/Oracle123@tnsfxdb 必须指定密码
rman target / 最好不要使用
rman target sys/Oracle123@tnsolracdb auxiliary sys/Oracle123@tnsolracdg
duplicate target database for standby from active database nofilenamecheck;
1.备库添加standby 日志组
注意:日志组大小要跟主库redolog文件的大小一样,文件组的数量是单节点文件组的数量再加1.<br />视图:v$log v$logfile v$standby_log
alter database add STANDBY LOGFILE THREAD 1 GROUP 11;
alter database add STANDBY LOGFILE THREAD 1 GROUP 12;
alter database add STANDBY LOGFILE THREAD 1 GROUP 13;
alter database add STANDBY LOGFILE THREAD 2 GROUP 14;
alter database add STANDBY LOGFILE THREAD 2 GROUP 15;
alter database add STANDBY LOGFILE THREAD 2 GROUP 16;
2.开启同步
startup mount
开启redo应用(实时同步)commit
自Oracle Database 12.1起,USING CURRENT LOGFILE子句已弃用
alter database recover managed standby database using current logfile disconnect from session;弃用
alter database recover managed standby database using current logfile disconnect;弃用
alter database recover managed standby database disconnect;
停止redo应用
alter database recover managed standby database cancel;
开启redo应用(日志切换才会同步)
alter database recover managed standby database using archived logfile disconnect;
alter system switch logfile;
查看状态:
select name,open_mode,database_role,protection_mode,protection_level from v$database;
更改保护模式:
alter database set standby database to maximize performance;最大性能
alter database set standby database to maximize availability;最大可用
alter database set standby database to maximize protection;最大保护
3.更改保护模式:
主库备库都需要执行 3 选 1
alter database set standby database to maximize performance;最大性能
alter database set standby database to maximize availability;最大可用
alter database set standby database to maximize protection;最大保护
4.【DG启停顺序】
启动:
先备库,后主库
关闭:
先主库,后备库
前提:干净的关闭
5.解决同步故障
1.查下主库2节点,备库的配置
2.检查tns配置
3.检查fal_client,fal_server
4.查下备库是否在实时应用模式
5.查询相关视图
v$managed_standby(备库查询)
RFS:传输进程
MRP0:日志应用进程
v$archive_dest(主库)
v$archive_dest_status(主库)
select dest_name,status,error from v$archive_dest_status where dest_id = 2;
select dest_name,status,error from v$archive_dest;
#备库执行查看同步延迟
select value from v$dataguard_stats where name='apply lag';