Oracle 11g ADG 部署(duplicate)快速参考

本文旨在指导客户完成Oracle 11g的ADG部署工作,主库环境已具备,备库环境已安装完成数据库软件。
环境:RHEL 6.8 + Oracle 11.2.0.4

1.确认主库运行在归档模式

这里设置归档存放路径为/u01/arch:

mkdir /u01/arch
chown oracle:oinstall /u01/arch
SQL> 
archive log list
alter system set log_archive_dest_1 = 'LOCATION=/u01/arch';
shutdown immediate
startup mount
alter database archivelog;
alter database open;
archive log list

2.确认主库开启Force Logging

SQL> 
select FORCE_LOGGING FROM V$DATABASE;
alter database force logging;
select FORCE_LOGGING FROM V$DATABASE;

3.主库参数文件修改

set linesize 500
col value for a70
col name for a50

select name, value
from v$parameter
where name in ('db_name','db_unique_name','log_archive_config', 'log_archive_dest_1','log_archive_dest_2',
               'log_archive_dest_state_1','log_archive_dest_state_2', 'remote_login_passwordfile',
               'log_archive_format','log_archive_max_processes','fal_server','db_file_name_convert',
                     'log_file_name_convert', 'standby_file_management');

alter system set log_archive_config='DG_CONFIG=(jingyu,jingyus)';
alter system set log_archive_dest_1='LOCATION=/u01/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=jingyu';
alter system set log_archive_dest_2='SERVICE=jingyus VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=jingyus';
alter system set log_archive_dest_state_1=enable;
alter system set log_archive_dest_state_2=enable;
alter system set FAL_SERVER='jingyus';
--数据文件路径主备库设计规范(主要依赖于db_unique_name,这里源端和目标端用于数据存储的磁盘组名字一致,用于归档的磁盘组名字不一致,需要转换):
alter system set db_file_name_convert='jingyus','jingyu' scope=spfile;
alter system set log_file_name_convert='jingyus','jingyu' scope=spfile;
alter system set standby_file_management=AUTO;

4.创建SRLs

ALTER DATABASE ADD STANDBY LOGFILE thread 1 group 101 ('/u01/oradata/jingyu/srl101.rdo') SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE thread 1 group 102 ('/u01/oradata/jingyu/srl102.rdo') SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE thread 1 group 103 ('/u01/oradata/jingyu/srl103.rdo') SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE thread 1 group 104 ('/u01/oradata/jingyu/srl104.rdo') SIZE 52428800;

5.备份数据库

使用传统比如RMAN备份的方式恢复备库,这里需要备份数据库。
而本次使用duplicate方式,无需备份,关于duplicate,后面章节会具体描述。

6.创建备库参数

create pfile='/tmp/pfile_for_standby.txt' from spfile;

7.更新tnsnames.ora文件

JINGYU =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = test04)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jingyu)
    )
  )

JINGYUS =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = test05)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jingyus)
    )
  )

8.拷贝主库RMAN备份和参数文件到备库

参数文件拷贝到备库:

scp /tmp/pfile_for_standby.txt 192.168.1.125:$ORACLE_HOME/dbs/

RMAN备份本次不需要,使用duplicate方式,后面章节会具体介绍。

注:使用scp拷贝时,如果两端$ORACLE_HOME变量值不一样,目标端需要修改为具体的绝对路径。

9.拷贝主库密码文件到备库

scp $ORACLE_HOME/dbs/orapwjingyu 192.168.1.125:$ORACLE_HOME/dbs/orapwjingyu

10.创建备库需要的目录

# audit_file_dest
mkdir -p /u01/app/oracle/admin/jingyus/adump
# db_recovery_file_dest
mkdir -p /u01/app/oracle/fast_recovery_area
# db_file
mkdir -p /u01/oradata/jingyus
mkdir -p /u01/app/oracle/fast_recovery_area/jingyus

11.修改备库参数文件

# vi pfile_for_standby.txt
:%s#jingyus#TTTTT#g
:%s#jingyu#jingyus#g
:%s#TTTTT#jingyu#g

# update:
*.db_name='jingyu'
*.db_unique_name='jingyus'

下面这段参数文件配置信息只是示例,实际需要根据主库的参数文件进行修改,要关注内存、进程数以及cursors等相关参数:

*.audit_file_dest='/u01/app/oracle/admin/jingyus/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/oradata/jingyus/control01.ctl','/u01/app/oracle/fast_recovery_area/jingyus/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_file_name_convert='jingyu','jingyus'
*.db_name='jingyu'
*.db_unique_name='jingyus'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=jingyusXDB)'
*.fal_server='jingyu'
*.log_archive_config='DG_CONFIG=(jingyus,jingyu)'
*.log_archive_dest_1='LOCATION=/u01/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=jingyus'
*.log_archive_dest_2='SERVICE=jingyu VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=jingyu'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_file_name_convert='jingyu','jingyus'
*.open_cursors=300
*.pga_aggregate_target=294649856
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.service_names='demo'
*.sga_target=883949568
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'

12.拷贝主库tnsnames.ora文件到备库

scp $ORACLE_HOME/network/admin/tnsnames.ora 192.168.1.125:$ORACLE_HOME/network/admin/tnsnames.ora

13.备库启动实例到nomount状态

sqlplus / as sysdba
startup nomount pfile=$ORACLE_HOME/dbs/pfile_for_standby.txt

14.初始化standby数据库

本次选用使用duplicate命令创建standby数据库,因为duplicate时间较长,需在后台运行防止过程中断:

vi dup_dg.sh

rman target sys/oracle@jingyu auxiliary sys/oracle@jingyus <<EOF
duplicate target database for standby from active database dorecover nofilenamecheck;
EOF

nohup sh dup_dg.sh > dup_dg.log &

tail -200f dup_dg.log

注意:为保证duplicate连接正常,可以先这样测试连接可用:

sqlplus sys/oracle@jingyu as sysdba
sqlplus sys/oracle@jingyus as sysdba
--备库连接报错:
ORA-12528: TNS:listener: all appropriate instances are blocking new connections

因为备库目前是nomount状态,如果需要连接就配置静态监听:
在备库listener.ora配置文件中增加(注意这里的GLOBAL_DBNAME对应的service_name我这里选择为原始的):

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = jingyus)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
      (SID_NAME = jingyu)
    )
  )

再次查看监听状态,Service “jingyus”部分有UNKNOWN,即静态监听标识,再次尝试连接成功:

Service "jingyus" has 2 instance(s).
  Instance "jingyu", status UNKNOWN, has 1 handler(s) for this service...
  Instance "jingyu", status BLOCKED, has 1 handler(s) for this service...

[oracle@test05 admin]$ sqlplus sys/oracle@jingyus as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue Jul 14 11:46:33 2020

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select status from v$Instance;

STATUS
------------------------
STARTED

正常完成duplicate后,数据库处于mount状态,且可以open只读打开:

SQL> select status from v$instance;

STATUS
------------
MOUNTED

SQL> alter database open;

Database altered.

SQL> 
SQL> 
SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ ONLY

15.确认数据库各类文件路径

a)确认已创建ORLs和SRLs:
SQL> SELECT MEMBER FROM V$LOGFILE;
在对应存储目录中查询没有也会后续自动创建的,确定路径没问题就可以,路径如果有问题,很可能是之前的convert参数设置有问题,设置convert参数,重启生效。

b)确认数据文件路径
select name from v$datafile;
select checkpoint_change# from v$datafile_header;
如果这个查询结果都是0,需要catalog start with 正确的路径,然后switch database to copy进行更正。

我这里检查都没有问题。

16.创建spfile然后使用spfile启动数据库

create spfile from pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/pfile_for_standby.txt';

17.启动MRP,验证DG同步成功

--RECOVER:
recover managed standby database disconnect;

--CANCEL:
recover managed standby database cancel;

--RTA(最终要求这种方式):
recover managed standby database using current logfile disconnect;

--DG LAG:
set lines 1000
col value for a15
select * from v$dataguard_stats;
查询结果显示,在DATUM_TIME列是接近当前时间的情况下,transport lag和apply lag两列的值均为0或是接近0,一般认定是同步正常。
还可以查询备库的SCN,观察是否随着时间不断增长,以此来辅助判断DG实时同步:
select current_scn from v$database;

如果同步有问题,主库查询对应dest_id的error信息:

select error from v$archive_dest where dest_id = 2;

18.部署定时任务进行历史归档清理

因为备库没有备份任务,为防止后续备库端归档满,需要部署定时任务进行历史归档清理,下面给出一个示例:

mkdir /home/oracle/scripts
cd /home/oracle/scripts
vi del_arch.sh

rman target / <<EOF >> /home/oracle/scripts/del_arch.log
delete noprompt archivelog all completed before 'sysdate - 1/24';
EOF

crontab -e
0 * * * * /bin/sh /home/oracle/scripts/del_arch.sh

至此,Oracle 11g ADG 部署(duplicate)整个过程已完成。

This entry was posted in Oracle专项实施 and tagged , . Bookmark the permalink.