暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

Oracle ADG搭建指南

IT那活儿 2022-09-19
1984

点击上方“IT那活儿”公众号,关注后了解更多内容,不管IT什么活儿,干就完了!!!


  

作为oracle数据库提供的一种容灾方式,ADG在我们日常生产中还是比较常见的,如何更快更好的搭建一套ADG,也是一个DBA需要掌握的基本技能。

下面是一次在实际搭建过程中整理的操作步骤。可以供大家参考。


环境准备
Primary Database

IP: 172.25.18.251

DATABASE VERSION: 11.2.0.4.0

DB_NAME:ptgbss

DB_UNIQUE_NAME:ptgbss

Standby Database

IP: 172.25.18.252
DATABASE VERSION: 11.2.0.4.0
DB_NAME:ptgbss
DB_UNIQUE_NAME: ptgbssdg    

先搭建好备库的数据库软件,无需建库。保持主库和备库的DB_NAME参数一致,DB_UNIQUE_NAME参数不能一致。


主库配置


2.1 主库测试备库1521端口是否通
[oracle@localhost ~]$ telnet 172.25.18.252 1521
Trying 172.25.18.252...
Connected to 172.25.18.252.
Escape character is '^]'.
^C
^CConnection closed by foreign host.
[oracle@localhost ~]$

2.2 主库配置tnsname.ora
vi /u01/product/11.2.0/db_1/network/admin/tnsnames.ora

# tnsnames.ora Network Configuration File: u01/product/11.2.0/db_1/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

PTGBSS =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.18.251)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ptgbss)
    )
  )

PTGBSSDG =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.18.252)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ptgbssdg)
    (UR=A)
    )
  )

tnsping 测试一下是否通:

[oracle@localhost admin]$ tnsping ptgbssdg

2.3 主库开启force_logging

查看是否已经开始强制日志:

select force_logging from v$database;

开启强制日志:

ALTER DATABASE FORCE LOGGING;

2.4 主库配置DG相关参数

主库添加standby 日志,日志大小与online日志保持一致,数量比online日志数量多一组:

set line 200

col member for a50

SELECT * FROM V$LOGFILE;

alter database add standby logfile thread 1 group 10 '/u01/oradata/ptgbss/redo10.log' size 1024M;
alter database add standby logfile thread 1 group 11 '/u01/oradata/ptgbss/redo11.log' size 1024M;
alter database add standby logfile thread 1 group 12 '/u01/oradata/ptgbss/redo12.log' size 1024M;
alter database add standby logfile thread 1 group 13 '/u01/oradata/ptgbss/redo13.log' size 1024M;
alter database add standby logfile thread 1 group 14 '/u01/oradata/ptgbss/redo14.log' size 1024M;
alter database add standby logfile thread 1 group 15 '/u01/oradata/ptgbss/redo15.log' size 1024M;
alter database add standby logfile thread 1 group 16 '/u01/oradata/ptgbss/redo16.log' size 1024M;
alter database add standby logfile thread 1 group 17 '/u01/oradata/ptgbss/redo17.log' size 1024M;
alter database add standby logfile thread 1 group 18 '/u01/oradata/ptgbss/redo18.log' size 1024M;
alter database add standby logfile thread 1 group 19 '/u01/oradata/ptgbss/redo19.log' size 1024M;


修改DG相关参数:

alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(ptgbss,ptgbssdg)' scope=both ;

alter system set LOG_ARCHIVE_DEST_1='LOCATION=/data/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ptgbss' scope=both;

alter system set LOG_ARCHIVE_DEST_2='SERVICE=ptgbssdg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ptgbssdg' scope=both;

alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE scope=both;

alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=both;

alter system set FAL_SERVER=ptgbssdg scope=both;
alter system set FAL_CLIENT=ptgbss scope=both;
alter system set standby_file_management=auto;

alter system set db_file_name_convert='/data/ptgbssdg','/data/ptgbss' scope=spfile;
alter system set log_file_name_convert='/u01/oradata/ptgbssdg','/u01/oradata/ptgbss' scope=spfile;

2.5 生成PFILE参数文件

create pfile from spfile;

2.6 传输参数文件和密码文件到备库

[oracle@localhost dbs]$ scp u01/product/11.2.0/db_1/dbs/initptgbss.ora 172.25.18.252:/u01/product/11.2.0/db_1/dbs
[oracle@localhost dbs]$ scp u01/product/11.2.0/db_1/dbs/orapwptgbss 172.25.18.252:/u01/product/11.2.0/db_1/dbs



备库相关参数配置

3.1 创建相应的目录

1)数据文件目录

2)日志文件目录

3)归档目录

3.2 备库配置listener.ora

[oracle@ptgbssdg ~]$ vi /u01/product/11.2.0/db_1/network/admin/listener.ora

#
 listener.ora Network Configuration File: /u01/product/11.2.0/db_1/network/admin/listener.ora

#
 Generated by Oracle configuration tools.


LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = ptgbssdg)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = /u01
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = ptgbss)
      (ORACLE_HOME = /u01/product/11.2.0/db_1)
      (SID_NAME = ptgbssdg)
    )
  )

3.3 备库配置tnsname

# tnsnames.ora Network Configuration File: /u01/product/11.2.0/db_1/network/admin/tnsnames.ora

#
 Generated by Oracle configuration tools.


PTGBSS =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.18.251)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ptgbss)
    )
  )

PTGBSSDG =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.18.252)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ptgbssdg)
    )
  )

3.4 备库修改参数文件

ptgbss.__db_cache_size=17448304640
ptgbssdg.__db_cache_size=16642998272
ptgbss.__java_pool_size=134217728
ptgbssdg.__java_pool_size=134217728
ptgbss.__large_pool_size=134217728
ptgbssdg.__large_pool_size=134217728
ptgbss.__oracle_base='/u01'#ORACLE_BASE set from environment
ptgbssdg.__oracle_base='/u01'#ORACLE_BASE set from environment
ptgbss.__pga_aggregate_target=3422552064
ptgbssdg.__pga_aggregate_target=3422552064
ptgbss.__sga_target=19327352832
ptgbssdg.__sga_target=19327352832
ptgbss.__shared_io_pool_size=0
ptgbssdg.__shared_io_pool_size=0
ptgbss.__shared_pool_size=1476395008
ptgbssdg.__shared_pool_size=2281701376
ptgbss.__streams_pool_size=0
ptgbssdg.__streams_pool_size=0
*.audit_file_dest='/u01/admin/ptgbss/adump' --此处修改
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/oradata/ptgbssdg/control01.ctl','/u01/fast_recovery_area/ptgbssdg/control02.ctl' --此处修改存放控制文件路径
*.db_block_size=8192
*.db_domain=''
*.db_file_name_convert='/data/ptgbss','/data/ptgbssdg' --此处修改
*.db_name='ptgbss' --此处修改
*.db_recovery_file_dest='/u01/fast_recovery_area' --此处修改对应的路径
*.db_recovery_file_dest_size=4385144832
*.db_unique_name='ptgbssdg' --此处修改
*.diagnostic_dest='/u01'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=ptgbssXDB)'
*.fal_client='PTGBSSDG' --此处修改
*.fal_server='PTGBSS'  --此处修改
*.log_archive_config='DG_CONFIG=(ptgbssdg,ptgbss)' --此处修改
*.log_archive_dest_1='location=/data/arch' --此处修改
*.log_archive_dest_2='SERVICE=ptgbssdg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ptgbssdg' --此处修改
*.log_archive_dest_state_1='ENABLE'  --修改此处参数
*.log_archive_dest_state_2='ENABLE'  --修改此处参数
*.log_file_name_convert='/u01/oradata/ptgbss','/u01/oradata/ptgbssdg'  --此处修改对应路径
*.open_cursors=300
*.pga_aggregate_target=3365928960
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_max_size=19327352832
*.sga_target=19327352832
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'

3.5 启动备库到nomount状态,启动监听

启动监听lsnrctl start:

---主库和备库都需要验证连通性:

sqlplus sys/oracle@ptgbss AS SYSDBA

sqlplus sys/oracle@ptgbssdg AS SYSDBA

3.6 使用RMAN DUPLICATE 主库到备库

rman target sys/oracle@ptgbss auxiliary sys/oracle@ptgbssdg
run
{
allocate channel cl1 type disk;
allocate channel cl2 type disk;
allocate channel cl3 type disk;
allocate auxiliary channel c1 type disk;
allocate auxiliary channel c2 type disk;
allocate auxiliary channel c3 type disk;
duplicate target database for standby from active database nofilenamecheck;
release channel c1;
release channel c2;
release channel c3;

}


备库开启日志应用并查看

4.1 duplicate成功后在备库开启日志应用

alter database open;
alter database recover managed standby database using current logfile disconnect from session;
select sequence#,thread#,applied from v$archived_log;

4.2 查看日志应用情况

col name for a50
select name,SEQUENCE#,APPLIED from v$archived_log order by sequence#;


select max(sequence#) from v$archived_log where applied='YES';
select thread#,max(sequence#) from v$archived_log where applied='YES' group by threa

查看错误:

select dest_id,error from v$archive_dest;

查看gap:

select * from v$archive_gap;

查看standby日志状态:

查看备库状态:

select MESSAGE from v$dataguard_status;

总 结:

在修改参数文件过程中,我这里已经把备库的参数文件反向配置也写好了,方便后期切换备库作为主库,主库作为备库。

备库参数文件修改完成后,需要把所有的文件目录在备库创建号,同时注意权限问题。

在搭建完成后,主备库根据需求设置归档清理策略。

使用rman duplicate的时候报错密码错误,使用如下命令orapwd file=/u01/app/oracle/product/18/db_1/dbs/orapworaclesid passwd=xxx 手动生成密码文件,然后重新执行rman duplicate命令。


本文作者:李 赛(上海新炬王翦团队)

本文来源:“IT那活儿”公众号

最后修改时间:2022-09-19 09:34:22
文章转载自IT那活儿,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论