本文主要是介绍创建ADG,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、主库单实例,备库单实例
主库(silentdg1):10.107.173.11
备库(silentdg2):10.107.173.12(只有oracle软件)
主备实例名:orcl
os:centos7.5minimal
oracle版本:11.2.0.4
1、pri
端和sty
端配置静态监听和tns
, 主备启动监听 并且都测试监听
主库编写listener.ora
,然后lsnrctl start
启动监听
LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=10.107.173.11)(PORT=1521))(ADDRESS=(PROTOCOL=ipc)(KEY=extproc))))
SID_LIST_LISTENER=(SID_LIST=(SID_DESC=(GLOBAL_DBNAME=orcl)(ORACLE_HOME=/u01/app/oracle/product/11.2.0/)(SID_NAME=orcl))(SID_DESC=(SID_NAME=plsextproc)(ORACLE_HOME=/u01/app/oracle/product/11.2.0/)(PROGRAM=extproc)))
主备库准备tnsnames.ora
内容是一样的
pritns =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 10.107.173.11)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)))stytns =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 10.107.173.12)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)))
主备库使用tnsping
互相测试监听(略)
2.修改primary
端初始化参数文件
mkdir /u01/app/archivelog
sqlplus / as sysdba
shu immediate
startup mount;
alter database archivelog;
alter database force logging;
alter database open;
alter system set db_unique_name = priuni scope=spfile;
alter system set log_archive_config = 'DG_CONFIG=(priuni,styuni)' scope=spfile;
alter system set log_archive_dest_1 = 'LOCATION=/u01/app/archivelog/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=priuni' scope=spfile;
alter system set log_archive_dest_2 = 'SERVICE=stytns LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=styuni' scope=spfile;
alter system set log_archive_dest_state_1=enable;
alter system set log_archive_dest_state_2=enable;
alter system set fal_server=stytns scope=spfile;
alter system set fal_client=pritns scope=spfile;
alter system set standby_file_management=AUTO scope=spfile;
shu immediate
startup(重启为了使上面的参数生效)
3、在primary
端生成pfile
参数文件和密码文件,并且拷贝到standby
段相应位置
主库:
orapwd file=orapworcl password=oracle force=y
create pfile from spfile;
cd $ORACLE_HOME/dbs
把主库的orapworcl
和initorcl.ora
传到备库
cd $ORACLE_BASE
scp -r diag/ 10.107.173.12:/u01/app/oracle
备库创建pfile
中涉及到的目录(略)
备库操作:
mkdir /u01/app/archivelog
sqlplus / as sysdba
create spfile from pfile;
startup nomount;
alter system set db_unique_name = styuni scope = spfile;
alter system set log_archive_config = 'DG_CONFIG=(priuni,styuni)' scope = spfile;
alter system set log_archive_dest_1 = 'LOCATION=/u01/app/archivelog/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=styuni' scope=spfile;
alter system set log_archive_dest_2 = 'SERVICE=pritns LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=priuni' scope=spfile;
alter system set fal_server=pritns scope=spfile;
alter system set fal_client=stytns scope=spfile;
shu abort
startup nomount
5.在primary
端通过Rman Duplicate
创建备库,在主库上执行如下命令
[oracle@silentdg1 ~]$ rman target sys/oracle@pritns auxiliary sys/oracle@stytns nocatalogRecovery Manager: Release 11.2.0.4.0 - Production on Mon May 17 14:45:38 2021Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.connected to target database: ORCL (DBID=1600326864)
using target database control file instead of recovery catalog
connected to auxiliary database: ORCL (not mounted)RMAN> duplicate target database for standby from active database nofilenamecheck;Starting Duplicate Db at 17-MAY-21
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=189 device type=DISKcontents of Memory Script:
{backup as copy reusetargetfile '/u01/app/oracle/product/11.2.0/dbs/orapworcl' auxiliary format '/u01/app/oracle/product/11.2.0/dbs/orapworcl' ;
}
executing Memory ScriptStarting backup at 17-MAY-21
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=34 device type=DISK
Finished backup at 17-MAY-21contents of Memory Script:
{backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/orcl/control01.ctl';restore clone controlfile to '/u01/app/oracle/fast_recovery_area/orcl/control02.ctl' from '/u01/app/oracle/oradata/orcl/control01.ctl';
}
executing Memory ScriptStarting backup at 17-MAY-21
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying standby control file
output file name=/u01/app/oracle/product/11.2.0/dbs/snapcf_orcl.f tag=TAG20210517T144636 RECID=1 STAMP=1072795596
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 17-MAY-21Starting restore at 17-MAY-21
using channel ORA_AUX_DISK_1channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 17-MAY-21contents of Memory Script:
{sql clone 'alter database mount standby database';
}
executing Memory Scriptsql statement: alter database mount standby databasecontents of Memory Script:
{set newname for tempfile 1 to "/u01/app/oracle/oradata/orcl/temp01.dbf";switch clone tempfile all;set newname for datafile 1 to "/u01/app/oracle/oradata/orcl/system01.dbf";set newname for datafile 2 to "/u01/app/oracle/oradata/orcl/sysaux01.dbf";set newname for datafile 3 to "/u01/app/oracle/oradata/orcl/undotbs01.dbf";set newname for datafile 4 to "/u01/app/oracle/oradata/orcl/users01.dbf";backup as copy reusedatafile 1 auxiliary format "/u01/app/oracle/oradata/orcl/system01.dbf" datafile 2 auxiliary format "/u01/app/oracle/oradata/orcl/sysaux01.dbf" datafile 3 auxiliary format "/u01/app/oracle/oradata/orcl/undotbs01.dbf" datafile 4 auxiliary format "/u01/app/oracle/oradata/orcl/users01.dbf" ;sql 'alter system archive log current';
}
executing Memory Scriptexecuting command: SET NEWNAMErenamed tempfile 1 to /u01/app/oracle/oradata/orcl/temp01.dbf in control fileexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEStarting backup at 17-MAY-21
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
output file name=/u01/app/oracle/oradata/orcl/system01.dbf tag=TAG20210517T144646
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
output file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf tag=TAG20210517T144646
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
output file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf tag=TAG20210517T144646
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
output file name=/u01/app/oracle/oradata/orcl/users01.dbf tag=TAG20210517T144646
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 17-MAY-21sql statement: alter system archive log currentcontents of Memory Script:
{switch clone datafile all;
}
executing Memory Scriptdatafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=1072795630 file name=/u01/app/oracle/oradata/orcl/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=1072795630 file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=1072795630 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=1072795630 file name=/u01/app/oracle/oradata/orcl/users01.dbf
Finished Duplicate Db at 17-MAY-21
6.在primary
和standby
端添加standby
日志
主库:
select status from v$instance;
STATUS
------------
OPENSELECT a.member,bytes/1024/1024FROM v$logfile a,v$log bWHERE a.group# = b.group#;MEMBER BYTES/1024/1024
--------------------------------------------- ---------------
/u01/app/oracle/oradata/orcl/redo03.log 50
/u01/app/oracle/oradata/orcl/redo02.log 50
/u01/app/oracle/oradata/orcl/redo01.log 50alter database add standby logfilegroup 4 ('/u01/app/oracle/oradata/orcl/styredo04.log') size 300m,group 5 ('/u01/app/oracle/oradata/orcl/styredo05.log') size 300m,group 6 ('/u01/app/oracle/oradata/orcl/styredo06.log') size 300m,group 7 ('/u01/app/oracle/oradata/orcl/styredo07.log') size 300m;SQL> SELECT GROUP#,THREAD#,SEQUENCE#,ARCHIVED,STATUS FROM V$STANDBY_LOG; GROUP# THREAD# SEQUENCE# ARC STATUS
---------- ---------- ---------- --- ----------4 0 0 YES UNASSIGNED5 0 0 YES UNASSIGNED6 0 0 YES UNASSIGNED7 0 0 YES UNASSIGNED
备库操作:
select status from v$instance;STATUS
------------
MOUNTEDalter database add standby logfilegroup 4 ('/u01/app/oracle/oradata/orcl/styredo04.log') size 300m,group 5 ('/u01/app/oracle/oradata/orcl/styredo05.log') size 300m,group 6 ('/u01/app/oracle/oradata/orcl/styredo06.log') size 300m,group 7 ('/u01/app/oracle/oradata/orcl/styredo07.log') size 300m;Database altered.SQL> select member from v$logfile;MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/flash_recovery_area/STYUNI/onlinelog/o1_mf_3_jb44cgs0_.log
/u01/app/oracle/flash_recovery_area/STYUNI/onlinelog/o1_mf_2_jb44cgno_.log
/u01/app/oracle/flash_recovery_area/STYUNI/onlinelog/o1_mf_1_jb44cgjg_.log
/u01/app/oracle/oradata/orcl/styredo04.log
/u01/app/oracle/oradata/orcl/styredo05.log
/u01/app/oracle/oradata/orcl/styredo06.log
/u01/app/oracle/oradata/orcl/styredo07.log
7.在standby
端开启实时日志应用
alter database recover managed standby database using current logfile disconnect from session;
开始测试ADG
8、执行日志切换测试(在pri
端切换归档,在节点二上检查是否也发生了切换)
–primary
执行日志切换
archive log list;
Current log sequence 21alter system switch logfile;archive log list;
Current log sequence 22
–standby
查看日志的sequence
号也跟着变了
archive log list;
Current log sequence 22
9、查看standby
启动的DG
进程
select process,client_process,sequence#,status from v$managed_standby;PROCESS CLIENT_P SEQUENCE# STATUS
--------- -------- ---------- ------------
ARCH ARCH 0 CONNECTED --归档进程
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
RFS ARCH 0 IDLE --归档传输进程
RFS UNKNOWN 0 IDLE
RFS LGWR 22 IDLE
RFS UNKNOWN 0 IDLE
MRP0 N/A 22 APPLYING_LOG --日志应用进程9 rows selected.
10、查看数据库的保护模式
#primary
端查看,我们可以看到数据库的保护模式为最大性能
select database_role,protection_mode,protection_level,open_mode from v$database;DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL OPEN_MODE
---------------- -------------------- -------------------- --------------------
PRIMARY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE READ WRITE
#standby
端查看
select database_role,protection_mode,protection_level,open_mode from v$database;DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL OPEN_MODE
---------------- -------------------- -------------------- --------------------
PHYSICAL STANDBY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE MOUNTED
11.查看DG
的日志信息
set line 200
col MESSAGE for a80
select * from v$dataguard_status;
--查看应用延迟情况
select * from v$dataguard_stats;
12.Open Read Only standby
数据库并且开启实时日志应用
备库
shutdown immediate
startup
select OPEN_MODE from v$database ;OPEN_MODE
--------------------
READ ONLYalter database recover managed standby database using current logfile disconnect from session;select open_mode from v$database;OPEN_MODE
--------------------
READ ONLY WITH APPLYselect process,client_process,sequence#,status from v$managed_standby;PROCESS CLIENT_P SEQUENCE# STATUS
--------- -------- ---------- ------------
ARCH ARCH 23 CLOSING
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
ARCH ARCH 22 CLOSING
RFS ARCH 0 IDLE
RFS UNKNOWN 0 IDLE
RFS LGWR 24 IDLE
MRP0 N/A 24 APPLYING_LOG
#至此Oracle 11g ADG
配置完成
这篇关于创建ADG的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!