Oracle 11G R2利用RMAN搭建DataGuard环境

环境:

角色 机器名 操作系统 IP 备注
主库 db1 CentOS 5.11 x86_64 192.168.2.241 安装Oracle,创建数据库
备库 db2 CentOS 5.11 x86_64 192.168.2.242 只安装Oracle

准备工作:

在db1的/etc/hosts里增加

127.0.0.1       db1

192.168.2.242    db2

在db2的/etc/hosts里增加

127.0.0.1       db2

192.168.2.241    db1

目录

  1. 主库打开归档及强制归档
  2. 创建3组standby redolog
  3. 修改参数文件
  4. 修改监听文件
  5. RMAN备份主库
  6. 复制文件至备库

1.主库打开归档及强制归档(db1)

检查Oracle是否开启归档

SQL> archive log list;
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     6
Current log sequence           8

#可以看到Automatic archival             Disabled说明未打开归档

打开归档(打开归档需要先关闭Oracle,然后将数据库启动至mount状态才能修改)

SQL> shutdown immediate;

SQL> startup mount;

SQL> alter database archivelog;         #打开归档

SQL> alter database force logging;    #打开强制归档也可以在数据库open状态下打开

SQL> alter database open;                  #打开数据库

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     6
Next log sequence to archive   8
Current log sequence           8

2.创建多组standby redo log,最少需要多一组,standby redo log是使用Real Time Apply的必要条件

SQL> select group#,member from v$logfile;
    GROUP#        MEMBER
--------------------------------------------------------------------------------
         3                /opt/oracle/oradata/tpy100/redo03.log
         2                /opt/oracle/oradata/tpy100/redo02.log
         1                /opt/oracle/oradata/tpy100/redo01.log

SQL> alter database add standby logfile (‘/opt/oracle/oradata/tpy100/standby04.log‘) size 50m;
SQL> alter database add standby logfile (‘/opt/oracle/oradata/tpy100/standby05.log‘) size 50m;
SQL> alter database add standby logfile (‘/opt/oracle/oradata/tpy100/standby06.log‘) size 50m;
SQL> alter database add standby logfile (‘/opt/oracle/oradata/tpy100/standby07.log‘) size 50m;

SQL> select group#,member from v$logfile;
    GROUP#        MEMBER
--------------------------------------------------------------------------------
         3                /opt/oracle/oradata/tpy100/redo03.log
         2                /opt/oracle/oradata/tpy100/redo02.log
         1                /opt/oracle/oradata/tpy100/redo01.log

4                /opt/oracle/oradata/tpy100/standby04.log
         5                /opt/oracle/oradata/tpy100/standby05.log
         6                /opt/oracle/oradata/tpy100/standby06.log

7                /opt/oracle/oradata/tpy100/standby07.log

3.修改参数文件

修改参数文件前,我们先进行备份

SQL> create pfile=‘/tmp/tpy100.pfile‘ from spfile;

在修改前我们需要查看下备份的参数文件,根据具体环境更改下面语句

SQL> alter system set db_unique_name=db1 scope=spfile;
SQL> alter system set log_archive_config=‘dg_config=(db1,db2)‘ scope=both;
SQL> alter system set log_archive_dest_1= ‘location=/opt/oracle/flash_recovery_area/ valid_for=(all_logfiles,all_roles)  db_unique_name=db1‘ scope=both;
报错:
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-16053: DB_UNIQUE_NAME db1 is not in the Data Guard Configuration

可能会遇上如下报错信息,这个时候需要重启下数据库

SQL> shutdown immediate;
SQL> startup

SQL> alter system set log_archive_dest_1= ‘location=/opt/oracle/flash_recovery_area/ valid_for=(all_logfiles,all_roles)  db_unique_name=db1‘ scope=both;
SQL> alter system set log_archive_dest_2= ‘service=db2 async  valid_for=(online_logfiles,primary_role)  db_unique_name=db2‘ scope=both;
SQL> alter system set log_archive_dest_state_1=enable scope=both;
SQL> alter system set log_archive_dest_state_2=enable scope=both;
SQL> alter system set standby_file_management=auto scope=both;
SQL> alter system set fal_server=db2 scope=both;
SQL> alter system set fal_client=db1 scope=both;
SQL> alter system set db_file_name_convert=‘/opt/oracle/flash_recovery_area‘,‘/opt/oracle/flash_recovery_area‘ scope=spfile;
SQL> alter system set log_file_name_convert=‘/opt/oracle/flash_recovery_area‘,‘/opt/oracle/flash_recovery_area‘ scope=spfile;

4.修改监听文件

[[email protected] ~]$ vim /opt/oracle/product/11.2.0/network/admin/tnsnames.ora
在后面增加

db1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = db1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = db1)
    )
  )

db2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = db2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = db2)
    )
  )

5.RMAN备份主库

创建备份存放目录

[[email protected] ~]$ mkdir -p /opt/oracle/dbackup

执行备份

rman>run{
allocate channel c1 type disk;
backup format ‘/opt/oracle/dbackup/tpy100_%T_%s_%p‘ database;
sql ‘alter system archive log current‘;
backup format ‘/opt/oracle/dbackup/archive_log_%T_%s_%p‘ archivelog all;
backup spfile format ‘/opt/oracle/dbackup/spfile_%u_%T.bak‘;
release channel c1;
}
rman>copy current controlfile for standby to ‘/opt/oracle/dbackup/standby.ctl‘;

6.复制文件至备库

[[email protected] ~]$ scp -r /opt/oracle/dbackup/ db2:/opt/oracle

[[email protected] ~]$ cd $ORACLE_HOME/dbs

[[email protected] dbs]$ scp -r orapwtpy100 db2:$ORACLE_HOME/dbs

[[email protected] dbs]$ cd $ORACLE_HOME/network/admin

[[email protected] admin]$ scp -r listener.ora tnsnames.ora db2:$ORACLE_HOME/network/admin

7.恢复参数文件(db2)

RMAN> set dbid 2926260986

RMAN> startup nomount;

#这里会报错不用理会即可

RMAN> restore spfile to pfile ‘/tmp/tpy100.pfile‘ from ‘/opt/oracle/dbackup/spfile_04quaekm_20160219.bak‘;

#我们将参数文件恢复至/tmp/tpy100.pfile,因为这个是主库的参数文件,备库略有不同

[[email protected] ~]$ vim /tmp/tpy100.pfile

#将里面的DB1 db1变成相应的DB2 db2,将DB1变成db1
tpy100.__db_cache_size=322961408
tpy100.__java_pool_size=4194304
tpy100.__large_pool_size=4194304
tpy100.__oracle_base=‘/opt/oracle‘#ORACLE_BASE set from environment
tpy100.__pga_aggregate_target=339738624
tpy100.__sga_target=503316480
tpy100.__shared_io_pool_size=0
tpy100.__shared_pool_size=159383552
tpy100.__streams_pool_size=0
*.audit_file_dest=‘/opt/oracle/admin/tpy100/adump‘
*.audit_trail=‘db‘
*.compatible=‘11.2.0.0.0‘
*.control_files=‘/opt/oracle/oradata/tpy100/control01.ctl‘,‘/opt/oracle/flash_recovery_area/tpy100/control02.ctl‘
*.db_block_size=8192
*.db_domain=‘‘
*.db_file_name_convert=‘/opt/oracle/flash_recovery_area‘,‘/opt/oracle/flash_recovery_area‘
*.db_name=‘tpy100‘
*.db_recovery_file_dest=‘/opt/oracle/flash_recovery_area‘
*.db_recovery_file_dest_size=4070572032
*.db_unique_name=‘DB2‘
*.diagnostic_dest=‘/opt/oracle‘
*.dispatchers=‘(PROTOCOL=TCP) (SERVICE=tpy100XDB)‘
*.fal_client=‘DB2‘
*.fal_server=‘DB1‘
*.log_archive_config=‘dg_config=(db2,db1)‘
*.log_archive_dest_1=‘location=/opt/oracle/flash_recovery_area/ valid_for=(all_logfiles,all_roles)  db_unique_name=db2‘
*.log_archive_dest_2=‘service=db1 async  valid_for=(online_logfiles,primary_role)  db_unique_name=db1‘
*.log_archive_dest_state_1=‘ENABLE‘
*.log_archive_dest_state_2=‘ENABLE‘
*.log_file_name_convert=‘/opt/oracle/flash_recovery_area‘,‘/opt/oracle/flash_recovery_area‘
*.memory_target=843055104
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile=‘EXCLUSIVE‘
*.standby_file_management=‘AUTO‘
*.undo_tablespace=‘UNDOTBS1‘

创建相应的目录,以便启动oracle

[[email protected] ~]$ mkdir -p /opt/oracle/admin/tpy100/adump
[[email protected] ~]$ mkdir -p /opt/oracle/oradata/tpy100
[[email protected] ~]$ mkdir -p /opt/oracle/flash_recovery_area/tpy100

[[email protected] ~]$ cp /opt/oracle/dbackup/standby.ctl /opt/oracle/oradata/tpy100/control01.ctl
[[email protected] ~]$ cp /opt/oracle/dbackup/standby.ctl /opt/oracle/flash_recovery_area/tpy100/control02.ctl

SQL> shutdown immediate;

SQL> startup nomount pfile=‘/tmp/tpy100.pfile‘

SQL> create spfile from pfile=‘/tmp/tpy100.pfile‘;

SQL> alter database mount;

RMAN> restore database;

SQL > alter database open read only;

SQL > alter database recover managed standby database using current logfile disconnect from session;

如果需要重启备库,则需要按如下命令进行重启

SQL> startup mount;
SQL> alter database open read only;

#在这里启动的时候如果出现

ERROR at line 1:
ORA-10458: standby database requires recovery
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: ‘/opt/oracle/oradata/tpy100/system01.dbf‘

则是备库的监听未开启,使用lsnrctl start,启动监听,再打开数据库就不会报错了.

SQL> alter database recover managed standby database using current logfile disconnect from session;

测试有如下语句:
SQL> select sequence#,applied from v$archived_log;
SQL> select process,status from v$managed_standby;
SQL> select sequence# from v$log_history;

时间: 2024-10-24 14:30:08

Oracle 11G R2利用RMAN搭建DataGuard环境的相关文章

Oracle 11g R2 RAC RMAN备份脚本示例

一.将RAC切换成归档模式 1. 修改数据库的归档模式,通常在安装RAC的时候都会配置归档并且使用闪回区,已经配置过归档下面的方式可以略过. SQL> alter system set cluster_database=false scope=spfile sid='*'; 2. 关闭所有实例(两边都要shutdown) SQL> shutdown immediate 或直接关闭所有实例   $ srvctl stop database -d orcl 3. 在任意一个实例上将数据库启动到mo

oracle 11g R2但示例安装前环境准备(针对用户,权限,内存 存储和系统参数的相关调整)

本文主要是讲oracle11gR2对系统和物理配置的相关要求以及适当的参数调整 系统: [[email protected] ~]# cat /etc/system-release CentOS release 6.7 (Final) 内核版本: [[email protected] ~]# uname -r 2.6.32-573.el6.x86_64 内核相关参数: [[email protected] ~]# vi /etc/sysctl.conf kernel.shmall = 42949

oracle 11g r2 使用rman进行迁移rac到rac

源端服务器主机名 rac05 rac06公共IP地址(eth0) 10.15.8.15 10.15.8.16 虚拟IP地址(eth0) 10.15.8.17 10.15.8.18私有IP地址(eth1) 1.1.1.9 1.1.1.10ORACLE RAC SID bol1 bol2集群实例名称 bolSCAN IP 10.15.8.19 操作系统 CentOS 6.5(vm)存储 ASM(vm)ORACLE 11.2.0.4 目标端(实例已安装运行)服务器主机名 rac01 rac02公共IP

CentOS 5.11下Oracle 11G R2 Dataguard搭建

Datagard算是Oracle企业版的一种容灾方案,在企业中广泛应用,我就将搭建过程记录下来以作备用. 主机名    数据库版本    实例名    IP db1    Oracle 11G R2    member    172.16.1.250 db2    Oracle 11G R2    member    172.16.1.251 默认情况下以上都已经安装好了Oracle数据库,但是只在db1上建立了数据库和监听,db2只安装Oracle软件不建库,不建监听. 目录: 打开强制归档日

RedHat 6.4 Enterprise x64环境下使用RHCS部署Oracle 11g R2双机HA

环境 软硬件环境 硬件环境: 浪潮英信服务器NF570M3两台,华为OceanStor 18500存储一台,以太网交换机两台,光纤交换机两台. 软件环境: 操作系统:Redhat Enterprise Linux 6.7 x64 集群环境:RHCS 数据库:Oracle 11g R2 多路径软件:UltraPath for Linux 存储划分 类型 卷 大小 挂载点 用途 备注 内置硬盘 标准 500MB /boot 启动分区 两块内置硬盘作RAID1 LVM 20GB /home 用户分区

ORACLE 11g R2数据库安装硬件环境要求

物理内存要求:最小1G,在windows7,windows8,windows8.1上最小2G. 虚拟内存(或分页空间)容量要求: Available RAM Swap Space Required Between 2GB and 16GB Equal to the size of RAM More than 16 GB 16GB 数据库软件硬盘空间要求: Installation Type Requirement for software files TEMP Space 500MB C:\Pr

Oracle 11g R2 Rman、数据泵、闪回备份与恢复

Oracle 11g R2 Rman备份备份与恢复的定义及分类 备份的定义及分类: 备份就是把数据库复制到转储设备的过程.其中,转储设备是指用于放置数据库副本的磁带或磁盘.通常也将存放于转储设备中的数据库的副本称为原数据库的备份或转储.备份是一份数据副本,从不同的角度分类如下: 从物理与逻辑的角度来分类: 从物理与逻辑的,备份可以分为物理备份和逻辑备份. 物理备份:对数据库操作系统的物理文件(数据文件,控制文件和日志文件)的备份.物理备份又可以分为脱机备份(冷备份)和联机备份(热备份),前者是在

Oracle 11g R2 备份与恢复

Oracle 11g R2 Rman备份 1. 备份与恢复的定义及分类 备份的定义及分类: 备份就是把数据库复制到转储设备的过程.其中,转储设备是指用于放置数据库副本的磁带或磁盘.通常也将存放于转储设备中的数据库的副本称为原数据库的备份或转储.备份是一份数据副本,从不同的角度分类如下: 从物理与逻辑的角度来分类: 从物理与逻辑的,备份可以分为物理备份和逻辑备份. 物理备份:对数据库操作系统的物理文件(数据文件,控制文件和日志文件)的备份.物理备份又可以分为脱机备份(冷备份)和联机备份(热备份),

Oracle 10g R2升级到Oracle 11g R2

Oracle 10g R2升级到Oracle 11g R2 系统环境: 操作系统:RedHat EL55 Oracle 软件: Oracle 10g R2.Oracle 11g R2 Oracle 升级线路 本案例是从Oracle 10.2.0.4.0升级到Oracle 11.2.0.1.0 参考文档: Oracle patch CPU Update: http://tiany.blog.51cto.com/513694/846066 Oracle 10g 升级(10.2.0.1.0升级到10.