处理日志组
select group#, thread#, bytes from v$log; select * from v$log; alter database add logfile thread 1 group 5 size 1024M, group 6 size 1024M; alter database add logfile thread 2 group 7 size 1024M, group 8 size 1024M, group 9 size 1024M, group 10 size 1024M, group 11 size 1024M, group 12 size 1024M; alter database drop logfile group 2; alter system checkpoint; alter system switch logfile; alter database add logfile thread 1 group 1 size 1024M, group 2 size 1024M, group 3 size 1024M, group 4 size 1024M; alter database add logfile thread 1 group 2 size 1024M;
添加standby logfile
alter database add standby logfile thread 1 group 13 size 1024M, group 14 size 1024M, group 15 size 1024M, group 16 size 1024M, group 17 size 1024M, group 18 size 1024M, group 19 size 1024M; alter database add standby logfile thread 2 group 20 size 1024M, group 21 size 1024M, group 22 size 1024M, group 23 size 1024M, group 24 size 1024M, group 25 size 1024M, group 26 size 1024M;
select * from v$standby_log;
打开主库 force logging
select force_logging from v$database;
打开主库 flashback
select flashback_on from v$database; alter database flashback on; alter system set DB_FLASHBACK_RETENTION_TARGET=120 scope=both sid='*';
打开主库 Enable Standby File Management
alter system set STANDBY_FILE_MANAGEMENT=AUTO scope=both sid='*';
设置远程登录验证方式 Enable Remote Privileged Login
show parameter remote_login_passwordfile alter system set remote_login_passwordfile='exclusive' scope=spfile sid='*';
注册备库静态监听
lsnrctl 查询监听文件位置
#create a static listener service on the standby
/u01/app/19.0.0.0/grid/network/admin/listener.ora SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (ORACLE_HOME=/u01/app/oracle/product/19.0.0.0/dbhome_1)(SID_NAME=zhsstb1(GLOBAL_DBNAME=zhsstb.abc.cn)))
重启监听 lsnrctl stop lsnrctl start
添加TNS 解析,(在首次建立同步时候,主库备库都指定1节点来做)
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/19.0.0.0/dbhome_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. ZHSGBK = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = dbpri-scan)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = zhsgbk.gansea.cn) ) ) ZHSSTB = (DESCRIPTION = (UT=A) #这个是必须的 (ADDRESS = (PROTOCOL = TCP)(HOST = dbstb-scan)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = zhsstb.gansea.cn) ) ) */
主库 增加DG配置
alter system set log_archive_config="DG_CONFIG=(ZHSGBK,ZHSSTB)";
主库增加日志参数
alter system set log_archive_dest_2='SERVICE=ZHSSTB LGWR ASYNC REGISTER VALID_FOR=(online_logfile,primary_role) REOPEN=60 DB_UNIQUE_NAME=ZHSSTB' scope=both sid='*';
Setup Fetch Archive Log Server
alter system set FAL_SERVER=ZHSSTB scope=both sid='*';
创建初始spfile Create Initial Standby Parameter File
grid $> echo 'DB_NAME=zhsstb' > /u01/app/oracle/product/19.0.0.0/dbhome_1/dbs/initzhsstb.ora
处理密码文件和文件夹
orapwd file=/u01/app/oracle/product/19.0.0.0/dbhome_1/dbs/orapwzhsstb1 password=PP--ssw00rd mkdir –p /u01/app/oracle/admin/zhsstb/adump
备库启动到nomunt模式
startup nomount
利用备份建立备库
# export NLS_DATE_FORMAT=”HH24:MI:SS”
rman connect target sys/PP--ssw00rd@zhsgbk connect auxiliary sys/PP--ssw00rd@zhsstb run { allocate channel p1 type disk; allocate auxiliary channel s1 type disk; duplicate target database for standby from active database using backupset dorecover spfile parameter_value_convert='zhsgbk','zhsstb','ZHSGBK','ZHSSTB' set db_unique_name = 'zhsstb' set db_name = 'zhsgbk' set instance_number = '1' set cluster_database = 'TRUE' set audit_file_dest = '/u01/app/oracle/admin/zhsstb/adump' set db_create_file_dest = '+DATA' set log_archive_config="DG_CONFIG=(ZHSGBK,ZHSSTB)" set diagnostic_dest="/u01/app/oracle" set db_recovery_file_dest="+RECO" set db_create_online_log_dest_1="+RECO" set log_archive_dest_2 = 'service=ZHSGBK lgwr async register valid_for=(online_logfiles, primary_role) db_unique_name=ZHSGBK' set remote_listener = 'dbstb-scan:1521' set fal_server='ZHSGBK' set fal_client='ZHSSTB' nofilenamecheck; }
开启主备日志同步
alter database recover managed standby database disconnect;
查询主备角色状态
select database_role, switchover_status from v$database;
查询日志同步进度
select thread#, sequence#, applied from v$archived_log order by sequence#;
处理RAC SPFile问题
create spfile='+DATA' from pfile; alter system set spfile='+DATA/ZHSSTB/PARAMETERFILE/spfile.289.1042116545' scop=both ;
Standby Database 注册到 OCR 里 在standby任一节点上执行:
oracle 用户执行
srvctl add database -d zhsstb -o $ORACLE_HOME -p +DATA/ZHSSTB/PARAMETERFILE/spfile.289.1042116545 -r physical_standby -a DATA srvctl add database -db zhsstb -dbname zhsgbk -o "$ORACLE_HOME" -p "+DATA/ZHSSTB/PARAMETERFILE/spfile.289.1042116545" -r physical_standby -s 'read only' -a RECO,DATA -domain abc.cn
查看数据库注册配置
srvctl config database -d zhsstb -a
命令详情
srvctl add database -db db_unique_name [-eval] -oraclehome oracle_home [-node node_name ] [-domain domain_name ] [-spfile spfile ] [-pwfile password_file_path ][-dbtype {RACONENODE | RAC | SINGLE} [-server“ server_list ”] [-instance instance_name ] [-timeout timeout ]] [-role {PRIMARY | PHYSICAL_STANDBY | LOGICAL_STANDBY | SNAPSHOT_STANDBY“] [-startoption start_options ] [-stopoption stop_options ] [-dbname db_name ] [-acfspath“ acfs_path_list ”] [-policy {AUTOMATIC | 手动| NORESTART}] [-serverpool“ server_pool_list ”[-pqpool“ pq_pool_list ”]] [-diskgroup “disk_group_list” ] [-verbose]
添加实例
srvctl add instance -d zhsstb -i zhsstb1 -n dbstb1 srvctl add instance -d zhsstb -i zhsstb2 -n dbstb2
# 启动active dataguard
取消日志应用
alter database recover managed standby database cancel;
重启standby数据库
srvctl stop instance -d zhsstb -i zhsstb1 srvctl start database -d zhsstb
查看standby状态:
select name, database_role, open_mode from gv$database;
配置备库自动删除归档
[oracle@dbstb1 scripts]$ cat rman_remove_archivelog.sh #!/bin/bash #creater:Neil #date:2020-06-03 #modfiy date: 2020-06-6 #desc:delete archive with rman #Oracle env export ORACLE_BASE=/u01/app/oracle export ORACLE_SID=zhsstb1 export ORACLE_HOME=/u01/app/oracle/product/19.0.0.0/dbhome_1 export PATH=$ORACLE_HOME/bin:$PATH # delete arhcive log rman target / <<EOF configure encryption for database off; set encryption off; run{ crosscheck archivelog all; CONFIGURE ARCHIVELOG DELETION POLICY TO applied on standby; delete noprompt archivelog all; } EOF
定时任务
oracle@dbstb1 scripts]$ crontab -l 00 22 * * * /home/oracle/scripts/rman_remove_archivelog.sh