这篇文章主要讲解了“怎么搭建Data Guard”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么搭建Data Gua...
这篇文章主要讲解了“怎么搭建Data Guard”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么搭建Data Guard”吧!
一、 规划
说明:在Data Guard中,
- db_name:主备库必须保持一致;
- db_unique_name:主备库必须不一致;
- service_names和instance_name可以保持一致或不一致。
二、 DG环境要求
1. 硬件和操作系统要求
Data Guard允许主备库有不同的CPU型号,不同的操作系统(例如windows & linux),不同的操作系统位数(32-bit/64-bit)或者不同的数据库位数(32-bit/64-bit)。
2. Oracle软件要求
Data Guard只支持Oracle database企业版,不支持标准版本。
在物理备库中,Oracle主备库的compatiable参数必须保持一致(通常情况下,我们说的Data Guard都是指物理备库)。在逻辑备库中,备库的compatiable必须大于或等于主库参数。
主库可以是单实例库或者RAC,备库也可以是单实例或是RAC。
如果主备库的操作系统一致,那么主备库的存储路径必须保持不同,否则,备库可能会覆盖主库文件。
如果主备库都是RAC,主库使用了ASM和OMF(Oracle managed files)命名管理,那么备库也应该使用ASM和OMF管理。
三、 思路清晰
step1:
主库开启force logging
step2:
备库配置listener.ora文件
step3:
主备库配置tnsnames.ora文件
step4:
主库添加standby logfile
step5:
主备库修改参数文件
step6: RMAN复制数据库
step7: DG检查,应用日志
step8:
开启备库,实时应用日志
四、 准备工作
1. 关闭防火墙(主备库)
# systemctl stop firewalld
# systemctl disable firewalld
2. 禁用selinux(主备库)
# vi /etc/selinux/config
selinux=disabled
3. 检查主库归档设置
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /archivelog/ORCL
Oldest online log sequence 26
Next log sequence to archive 28
Current log sequence 28
4. 配置/etc/hosts文件(主备库)
# vi /etc/hosts
#Primary IP
172.16.70.178 primary
#Standby IP
172.16.70.179 standby
五、 搭建DG
1. 开启强制日志模式(主库)
SQL> alter database force logging;
2. 配置listener.ora文件(备库)
(Oracle用户)
备库添加静态监听
$ vi $ORACLE_HOME/network/admin/listener.ora
(添加以下内容)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = SBDB)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = SBDB)
)
)
开启监听
$ lsnrctl start
3. 修改tnsnames.ora文件(主备库)
(主备库一致)
$ vi $ORACLE_HOME/network/admin/tnsnames.ora
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCL)
)
)
SBDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = SBDB)
)
)
tns连通性检测
$ tnsping ORCL
$ tnsping SBDB
4. 主库添加standby logfile;
SQL> select group#,thread#,bytes/1024/1024 M,status from v$log;
SQL> select member from v$logfile;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/ORCL/redo04.log' size 50m;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/ORCL/redo05.log' size 50m;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/ORCL/redo06.log' size 50m;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/ORCL/redo07.log' size 50m;
查看日志组状态
SQL> select group#,status,type,member from v$logfile;
5. 修改参数文件
(主库修改参数)
1) 生成参数文件
SQL> create pfile from spfile;
2) 修改参数文件
$ cd /u01/app/oracle/product/11.2.0/db_1/dbs
$ vi initORCL.ora
添加以下内容:
db_unique_name=ORCL
log_archive_config='dg_config=(ORCL,SBDB)'
log_archive_dest_1='location=/archivelog/ORCL valid_for=(all_logfiles,all_roles) db_unique_name=ORCL'
log_archive_dest_2='service=SBDB lgwr async valid_for=(online_logfiles,primary_roles) db_unique_name=SBDB'
log_archive_dest_state_1=enable
log_archive_dest_state_2=enable
db_file_name_convert='/u01/app/oracle/oradata/SBDB','/u01/app/oracle/oradata/ORCL'
log_file_name_convert='/u01/app/oracle/oradata/SBDB','/u01/app/oracle/oradata/ORCL'
fal_server=SBDB
fal_client=ORCL
standby_file_management=auto
3) 生成spfile,重启库使参数生效
SQL> shutdown immediate;
SQL> create spfile from pfile;
SQL> startup;
(备库修改)
1) 将主库pfile传到备库
$ scp initORCL.ora standby:$ORACLE_HOME/dbs/initSBDB.ora
2) 修改参数文件
$ cd /u01/app/oracle/product/11.2.0/db_1/dbs
$ vi initSBDB.ora
执行以下命令
:%s/ORCL/AAAA/g
:%s/SBDB/ORCL/g
:%s/AAAA/SBDB/g
最后将db_name修改回ORCL
最后结果如下:
*.audit_file_dest='/u01/app/oracle/admin/SBDB/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/SBDB/control01.ctl','/u01/app/oracle/oradata/SBDB/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='ORCL'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=SBDBXDB)'
*.log_archive_dest_1='LOCATION=/archivelog/SBDB'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=769654784
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
db_unique_name=SBDB
log_archive_config='dg_config=(SBDB,ORCL)'
log_archive_dest_1='location=/archivelog/SBDB valid_for=(all_logfiles,all_roles) db_unique_name=SBDB'
log_archive_dest_2='service=ORCL lgwr async valid_for=(online_logfiles,primary_roles) db_unique_name=ORCL'
log_archive_dest_state_1=enable
log_archive_dest_state_2=enable
db_file_name_convert='/u01/app/oracle/oradata/ORCL','/u01/app/oracle/oradata/SBDB'
log_file_name_convert='/u01/app/oracle/oradata/ORCL','/u01/app/oracle/oradata/SBDB'
fal_server=ORCL
fal_client=SBDB
standby_file_management=auto
3) 备库创建上述目录
$ mkdir -p /u01/app/oracle/admin/SBDB/adump
$ mkdir -p /u01/app/oracle/oradata/SBDB
$ mkdir -p /archivelog/SBDB
4) 备库创建密码文件
$ cd $ORACLE_HOME/dbs/
$ orapwd file=orapwSBDB password=oracle
6. 复制数据库
1) 备库开启到nomount状态
SQL> create spfile from pfile;
SQL> startup nomount;
2)RMAN复制数据库(主库执行)
$ rman target / auxiliary sys/oracle@SBDB
RMAN> duplicate target database for standby from active database;
此时,已经完成了Data Guard搭建部分!
六、 配置ADG
1) 查询主备库状态
(主库)
SQL> col db_unique_name for a15
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;
DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------------- ------------------ ---------------- --------------------
ORCL READ WRITE PRIMARY FAILED DESTINATION
(备库)
DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
-------------- ------------------ ---------------- --------------------
SBDB MOUNTED PHYSICAL STANDBY SESSIONS ACTIVE
2) 备库应用日志
SQL> alter database recover managed standby database using current logfile disconnect from session;
此时注意检查备库SWITCHOVER_STATUS状态,直到SWITCHOVER_STATUS为NOT ALLOWED为正常。
3) 备库取消应用日志
SQL> alter database recover managed standby database cancel;
4) 开启备库
SQL> alter database open;
5) 备库开启实时应用
SQL> alter database recover managed standby database using current logfile disconnect from session;
6) 再次检查备库状态
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;
DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------------- -------------------- ---------------- --------------------
SBDB READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED
7) 查看备库进程状态
SQL> select process, pid, status, client_process from v$managed_standby;
PROCESS PID STATUS CLIENT_P
--------- ---------- ------------ --------
ARCH 24183 CONNECTED ARCH
ARCH 24186 CONNECTED ARCH
ARCH 24188 CLOSING ARCH
ARCH 24190 CONNECTED ARCH
RFS 24533 IDLE LGWR
RFS 24527 IDLE UNKNOWN
RFS 24529 IDLE ARCH
RFS 24707 IDLE UNKNOWN
MRP0 24918 APPLYING_LOG N/A
此时,备库已经是实时应用状态(Active Data Guard)
感谢各位的阅读,以上就是“怎么搭建Data Guard”的内容了,经过本文的学习后,相信大家对怎么搭建Data Guard这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是捷杰建站,小编将为大家推送更多相关知识点的文章,欢迎关注!