ORACLE 数据库DG搭建练习

1. 基本环境

参数 主库 备库
IPv4 172.15.1.65 172.15.0.55
HOSTNAME it-epc-db it-dms67
SID orcl orcl
UDBNAME orcl orcldg

2. 先决条件检查

2.1 先确认主库是运行在归档模式:

1
select name,log_mode from v$database;

2.2 是否安装了DG模块:

1
select * from v$option where parameter = 'Oracle Data Guard';

2.3 DNS解析

在主库及备库配置HOST文件,确认都可以使用主机名PING通对方

2.4 配置主库强制记录日志:

1
alter database force logging;

2.5 配置在主库添加或者删除数据文件时,这些文件也会在备份添加或删除:

1
alter system set standby_file_management='AUTO'

2.6 查看主库当前REDO文件数及大小:(standby log 大小需与当前一致)

1
select group#,bytes/1024/1024 as M from v$log;

2.7 计算所需STANDBY日志数:

(每线程的日志组数+1)最大线程数
所以本次需要创建standby logfile数目=(3+1)
1=4

1
2
3
4
alter database add standby logfile group  11 'F:\app\Administrator\oradata\orcl\DG\standby11.log' size 50M;
alter database add standby logfile group 12 'F:\app\Administrator\oradata\orcl\DG\standby12.log' size 50M;
alter database add standby logfile group 13 'F:\app\Administrator\oradata\orcl\DG\standby13.log' size 50M;
alter database add standby logfile group 14 'F:\app\Administrator\oradata\orcl\DG\standby14.log' size 50M;

2.8 生成主库密码文件:

1
orapwd file=F:\app\Administrator\product\11.2.0\dbhome_1\DATABASE\PWDORCL.ora password=oracle  --(实际环境使用了复杂密码,这里是举例)

2.9 检查REMOTE_LOGIN_PASSWORDFILE值是否为 EXCLUSIVE

1
show parameter REMOTE_LOGIN_PASSWORDFILE;

如果值不是EXCLUSIVE,则:

1
alter system set remote_login_passwordfile=exclusive scope=spfile;

2.10 把密码文件拷贝到从库相应的位置;

2.11生成 standby 控制文件:(在MOUNT状态下进行)

1
2
3
4
shutdown immediate
startup mount
alter database create standby controlfile as 'F:\app\Administrator\oradata\standby_control01.ctl';
startup open;

2.12 在备库建立对应的目录

2.13 设置主库的 db_unique_name 为 orcl,从库为 orcldg

1
2
show parameter db_unique_name
alter system set db_unique_name=orcl scope=spfile;

2.14 配置主库的监听

1
2
3
4
5
6
7
8
9
10
11
12
13
14
SID_LIST_LISTENER=
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = F:\app\Administrator\product\11.2.0\dbhome_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = it-epc-db)(PORT = 1521))
)
)

2.15 配置 tnsnames

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = it-epc-db)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)

ORCLDG =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = it-dms67)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcldg)
)
)

2.16 将监听配置文件及TNS文件拷贝到备库对应的位置,并修改监听配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
SID_LIST_LISTENER
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcldg)
(ORACLE_HOME = F:\app\Administrator\product\11.2.0\dbhome_1)
(SID_NAME = orcl)
)
)


LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = it-dms67)(PORT = 1521))
)
)

2.17 配置主库归档文件位置及参数

1
2
3
alter system set log_archive_dest_1='LOCATION=F:\arch\orcl  valid_for=(all_logfiles,primary_role) db_unique_name=orcl' scope=spfile; 
alter system set log_archive_dest_2='SERVICE=orcldg lgwr sync valid_for=(online_logfile,primary_role)
db_unique_name=orcldg';

2.18 配置 FAL_SERVER

1
alter system set FAL_SERVER='orcldg';

2.19 Data Guard 配置里的另外一个库的名字

1
alter system set log_archive_config = 'dg_config=(orcl,orcldg)';

2.20 生成PFILE文件:

1
create pfile from spfile;

2.21 检查生成的参数文件

将参数文件拷贝到备库,并修改下面的各项:

1
2
3
4
5
6
*.db_name='orcl'
*.db_unique_name='orcldg'
*.fal_server='orcl'
*.log_archive_config='dg_config=(orcldg,orcl)'
*.log_archive_dest_1='LOCATION=F:\arch\orcl valid_for=(all_logfiles,primary_role) db_unique_name=orcldg'
*.log_archive_dest_2='SERVICE=orcl lgwr sync valid_for=(online_logfile,primary_role) db_unique_name=orcl'

2.22 创建备库SPFIEL

1
create spfile from pfile;

2.23 传输主库数据文件到备库指定位置

2.24 创建备库实例

1
oradim -new -sid orcl -startmode m

2.25 启用物理备用数据库

1
2
startup nomount
alter database mount standby database;

2.26 启动 redo 应用

1
2
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;

2.27 启动主库:

1
startup

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×