oracle 11g DG 搭建

groupadd oinstall

groupadd dba

groupadd oper

groupadd asmadmin

groupadd asmdba

groupadd asmoper

useradd -g oinstall -G dba,asmdba,asmadmin,asmoper grid

useradd -g oinstall -G dba,oper,asmdba oracle

passwd  grid

passwd  oracle

mkdir -p /u01/app/11.2.0/grid

mkdir -p /u01/app/grid

mkdir -p /u01/app/oracle

chown grid:oinstall /u01/app/11.2.0/grid

chown grid:oinstall /u01/app/grid

chown -R oracle:oinstall /u01/app/oracle

chmod -R 775 /u01/

chown -R grid:oinstall /u01

sed -i ‘s/kernel.shmmax/#kernel.shmmax/g‘ /etc/sysctl.conf

sed -i ‘s/kernel.shmall/#kernel.shmall/g‘ /etc/sysctl.conf

vi /etc/sysctl.conf

添加以下内容:

fs.aio-max-nr = 1048576

fs.file-max = 6815744

kernel.shmall = 2097152

kernel.shmmax = 1073741824

kernel.shmmni = 4096

kernel.sem = 250 32000 100 128

net.ipv4.ip_local_port_range = 9000 65500

net.core.rmem_default = 262144

net.core.rmem_max = 4194304

net.core.wmem_default = 262144

net.core.wmem_max = 1048586

sysctl -p

vi /etc/security/limits.conf

添加如下内容:

oracle soft nproc 2047

oracle hard nproc 16384

oracle soft nofile 1024

oracle hard nofile 65536

oracle soft stack 10240

grid soft nproc 2047

grid hard nproc 16384

grid soft nofile 1024

grid hard nofile 65536

grid soft stack 10240

vi /etc/profile 写入如下内容:

if [ $USER = "oracle" ] || [ $USER = "grid" ]; then

if [ $SHELL = "/bin/ksh" ]; then

ulimit -p 16384

ulimit -n 65536

else

ulimit -u 16384 -n 65536

fi

umask 022

fi

export PATH=$PATH:/u01/app/11.2.0/grid/bin

配置节点rac1

grid 用户:

vi .bash_profile

export TMP=/tmp

export TMPDIR=$TMP

export ORACLE_HOSTNAME=

export ORACLE_SID=

export ORACLE_BASE=/u01/app/grid

export ORACLE_HOME=/u01/app/11.2.0/grid

export PATH=$ORACLE_HOME/bin:$PATH

oracle用户:

vi .bash_profile

export TMP=/tmp

export TMPDIR=$TMP

export ORACLE_HOSTNAME=

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1

export ORACLE_UNQNAME=

export ORACLE_SID=

export ORACLE_TERM=xterm

export PATH=/usr/sbin:$PATH

export PATH=$ORACLE_HOME/bin:$PATH

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib

export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

1.分别安装完数据库软件

2.主库dbca建库

3.主备分别netca

4.主库执行:

select * from v$option where parameter = ‘Managed Standby‘;

archive log list

alter database force logging;

alter database add standby logfile group 4 (‘/u01/app/oracle/oradata/redo04.log‘) size 50m;

alter database add standby logfile group 5 (‘/u01/app/oracle/oradata/redo05.log‘) size 50m;

alter database add standby logfile group 6 (‘/u01/app/oracle/oradata/redo06.log‘) size 50m;

alter database add standby logfile group 7 (‘/u01/app/oracle/oradata/redo07.log‘) size 50m;

create pfile from spfile;

show parameter name;

alter system set db_unique_name=‘ora11g_primary‘ scope=spfile;

alter system set log_archive_config=‘dg_config=(ora11g_primary,ora11g_standby)‘;

create pfile from spfile;

shutdown immediate;

cd /u01/app/oracle/product/11.2.0/db_1/dbs

查看initora11g.org   db_unique_name=‘ora11g_primary‘是否有

startup;

alter system set log_archive_dest_1=‘location=/u01/app/oracle/archivelog valid_for=(ALL_LOGFILES,ALL_ROLES) db_unique_name=ora11g_primary‘;

alter system set log_archive_dest_2=‘service=ora11g_standby LGWR SYNC valid_for=(ONLINE_LOGFILES,primary_role) db_unique_name=ora11g_standby‘;

alter system set log_archive_dest_state_1=‘enable‘;

alter system set log_archive_dest_state_2=‘enable‘;

alter system set REMOTE_LOGIN_PASSWORDFILE=‘EXCLUSIVE‘ scope=spfile;

alter system set FAL_SERVER=‘ora11g_standby‘ scope=spfile;

alter system set FAL_client=‘ora11g_primary‘ scope=spfile;

alter system set STANDBY_FILE_MANAGEMENT=‘AUTO‘ scope=spfile;

mkdir -p $ORACLE_BASE/archivelog

create pfile from spfile;

shutdown immediate;

验证参数是否都在

startup mount;

alter database create standby controlfile as ‘/u01/standby_ctl02.ctl‘;

cd /u01/app/oracle/product/11.2.0/db_1/network/admin

vim listener.ora

添加

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(SID_NAME = ora11g)

(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)

)

)

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = cbfdb1)(PORT = 1521))

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

)

)

ADR_BASE_LISTENER = /u01/app/oracle

vim tnsnames.ora

ORA11G_PRIMARY =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.1)(PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = ora11g)

)

)

ORA11G_STANDBY =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = ora11g)

)

)

关闭主数据库

SQL>shutdown immediate

生成spfile

SQL> create spfile from pfile;

5.在备库段执行:

mkdir -p $ORACLE_BASE/oradata/ora11g

mkdir -p $ORACLE_BASE/admin/ora11g

mkdir -p $ORACLE_BASE/admin/ora11g/adump

mkdir -p $ORACLE_BASE/admin/ora11g/bdump

mkdir -p $ORACLE_BASE/admin/ora11g/cdump

mkdir -p $ORACLE_BASE/admin/ora11g/dpdump

mkdir -p $ORACLE_BASE/admin/ora11g/pfile

mkdir -p $ORACLE_BASE/admin/ora11g/udump

mkdir -p $ORACLE_BASE/diag/rdbms

mkdir -p $ORACLE_BASE/diag/tnslsnr

mkdir -p $ORACLE_BASE/fast_recovery_area/ORA11G

mkdir -p $ORACLE_BASE/archivelog

下面的几个scp 在主库执行

scp -r $ORACLE_BASE/oradata/ora11g/*.dbf 192.168.0.2:/$ORACLE_BASE/oradata/ora11g

scp -r $ORACLE_BASE/oradata/*.log 192.168.0.2:/$ORACLE_BASE/oradata

scp -r /u01/standby_ctl01.ctl 192.168.0.2:/$ORACLE_BASE/oradata

scp -r $ORACLE_HOME/dbs/initora11g.ora 192.168.0.2: $ORACLE_HOME/dbs/

scp -r /u01/app/oracle/product/11.2.0/db_1/dbs/orapwora11g  192.168.0.2:/u01/app/oracle/product/11.2.0/db_1/dbs/

$ cd $ORACLE_BASE/oradata/ora11g

$ mv standby_ctl01.ctl  control01.ctl

$ cp control01.ctl control02.ctl

cd /u01/app/oracle/product/11.2.0/db_1/dbs

修改initora11g.ora

DB_UNIQUE_NAME=ora11g_standby

LOG_ARCHIVE_DEST_1=‘LOCATION=/u01/app/oracle/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ora11g_standby‘

LOG_ARCHIVE_DEST_2=‘SERVICE=ora11g_primary LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ora11g_primary‘

FAL_SERVER=ora11g_primary

FAL_CLIENT=ora11g_standby

cd /u01/app/oracle/product/11.2.0/db_1/network/admin

vim listener.ora

添加

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(SID_NAME = ora11g)

(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)

)

)

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = cbfdb2)(PORT = 1521))

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

)

)

ADR_BASE_LISTENER = /u01/app/oracle

vim tnsnames.ora

ORA11G_PRIMARY =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.1)(PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = ora11g)

)

)

ORA11G_STANDBY =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = ora11g)

)

)

startup nomount

alter database mount standby database;

主库执行:

startup mount

alter database set standby database to maximize  availability;     (设置为最高可用性模式)

alter database open;

SQL>alter database recover managed standby database disconnect from session;

#执行此命令后,备库会切换到自动恢复模式

一、功能切换

Switchover状态切换

首先在primary上操作:

(1).验证主库是否能执行角色转换到备库(原主库执行)

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS

-----------------

TO STANDBY

1 row selected

(2)开始把物理主库改变为物理备库(原主库执行)

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY with session shutdown;

注:如果有活动的session可以使用此选项,否则转换会遇到ORA-01093错误,也可以杀掉活动会话或等活动会话后进行转换

(3).关闭并重启主库(原主库执行)

SQL> shutdown immediate

SQL> startup nomount

SQL> alter database mount standby database; #让备库处于standby

SQL> alter database recover managed standby database using current logfile disconnect from session; #开始实时同步

然后在standby上操作:

(1).验证备库是否能执行角色转换到主库(原备库执行)

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS

-----------------

TO_PRIMARY

1 row selected

(2).开始把物理备库转换成物理主库(原备库执行)

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;

--如果报ORA-16139: media recovery required,可能是由于未应用日志引起,可先执行

ALTER  DATABASE RECOVER MANAGED STANDBY  DATABASE DISCONNECT FROM SESSION;

(3)打开备库,然后关闭重启.(原备库执行)

SQL> SHUTDOWN IMMEDIATE;

SQL> STARTUP;

(4)验证是否转换成功(原备库执行)

SQL> ALTER SYSTEM SWITCH LOGFILE;

启动日志应用

(5)  应用归档日志(原主库上执行)

SQL> ALTER  DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;

小窍门:要想顺利的实现switchover,最好在每台server上都同时设置好primary和standby的一些初始化参数,虽然其中一些参数只有在primary或者standby其中之一上起作用。

4、启动和关闭顺序

启动顺序

(1).启从、主库的监听Listener

从库DG-Standby:

$lsnrctl start

主库DG-Primary:

$lsnrctl start

(2).启动备库数据库,执行如下:

$sqlplus /nolog

SQL>conn /as sysdba

SQL> startup nomount

SQL> alter database mount standby database;               #让备库处于standby

SQL> alter database recover managed standby database using current logfile disconnect from session; #开始实时同步

(3).启动主库

$sqlplus /nolog

SQL>conn /as sysdba

SQL> startup

切换standby database到read only模式

SQL> alter database recover managed standby database cancel;    #首先取消备库的自动恢复模式

SQL>alter database open read only;

如果要切换回recover manage模式(启动日志应用或者启动日志实时应用)

SQL> alter database recover managed standby database disconnect from session; 启动日志应用

SQL>alter database recover managed standby database using current logfile disconnect from session; 启动日志实时应用

(3).启动主库数据库(上述第二步执行完毕后,方可执行如下命令):

SQL>startup

关闭顺序

关闭的时候正好相反,先关闭主库,然后关闭从库。

(1).  关闭主库

$su – oracle

SQL>sqlplus /nolog

SQL>conn /as sysdba

SQL>shutdown immediate;

(2). 关闭从库

su – oracle

SQL>sqlplus /nolog

SQL>conn /as sysdba

SQL>alter database recover managed standby database cancel;     #停止同步

SQL>shutdown immediate

应急切换

(注:模拟主库由于故障无法正常switchover,需要执行failover,强制备库->pridb并接管业务)

(1).备库:

由于是failover,所以理解主库这时候已经无法正常使用,只需备库切换至pridb

停止应用恢复模式

alter database recover managed standby database finish;

转换standbydb为primary db

alter database commit to switchover to primary;

重启数据库,恢复正常业务

SQL>shutdown immediate

SQL>startup

select open_mode,database_role from v$database;

OPEN_MODE       DATABASE_ROLE

----------             ----------------

OPEN                 PRIMARY

注:failover将破坏dataguard模式,需要重新配置dataguard,网上也说不需要配置,但是还没有测试成功

select dbid,name,protection_mode,protection_level from v$database;

时间: 2024-10-29 19:09:46

oracle 11g DG 搭建的相关文章

Oracle 11g RAC搭建(VMware环境)

Oracle 11g RAC搭建(VMware环境) Oracle 11g RAC搭建VMware环境 安装环境与网络规划 安装环境 网络规划 环境配置 通过SecureCRT建立命令行连接 关闭防火墙 创建必要的用户组和目录并授权 节点配置检查 系统文件设置 配置IP和hostshostname 配置grid和oracle用户环境变量 配置oracle用户ssh互信 配置裸盘 配置grid用户ssh互信 挂载安装软件文件夹 安装用于Linux的cvuqdisk 手动运行cvu使用验证程序验证O

Linux平台 Oracle 11g DG测试环境快速搭建参考

环境现状: 两台虚拟主机A和B: 1. A机器已安装ASM存储的Oracle 11g 实例 参考:http://www.cnblogs.com/jyzhao/p/4332410.html 2. B机器已安装系统,配置以及目录结构均和A机器保持一致 /u01 + 3块ASM盘 DG部署规划:   primary standby 主机 JY-DB JY-DBS db_name jyzhao jyzhao db_unique_name jyzhao jyzhao_s instance_name jyz

Oracle 11g DataGuard搭建(一) - 单节点到单节点

(一)DataGuard概要 DataGuard中文称为”数据卫士“,提供了数据库高可用性.数据保护和灾难恢复的功能.DataGuard通过建立primary数据库和standby数据库来确立参照关系,DataGuard将主库(primary)的redo日志传递给备库(standby),然后在备库中应用redo进行同步. 备库又分为2种类型:物理备库和逻辑备库 物理standby是通过块拷贝方式同步,通过接受并应用primary数据库的redo log,以介质恢复的方式同步.在物理备库中,数据是

『ORACLE』DG搭建时备库的db_name报错

因为搭建DG时备库中的db_name为SBCD,实际应该是主库db_name的PROD1 所以在[主库]执行如下rman操作命令时会报错控制文件记录的数据库名与实际拷贝的数据库名不相同 RMAN> duplicate target database for standby from active database; Starting Duplicate Db at 01-MAY-17using target database control file instead of recovery ca

解决oralce 11g dg搭建报错:ORA-16664、ORA-16714、ORA-16810问题--转

下面不是小编错误报告只是转了网络一篇,同时也解决了我的问题所以复制过来给各位参考. 最近在弄11g的dg时,遇到如下问题,记录下.首先在主上查看报如下错误: DGMGRL> show configuration; Configuration - queue_zs_dg Protection Mode: MaxPerformance  Databases:    queuedb   - Primary database    queuedb02 - Physical standby databas

Oracle 11g 快速搭建脚本

一.root用户 1.安装前准备 mv /home/vsftpd/linux.x64_11gR2_database_* /tmp && cd /tmp unzip linux.x64_11gR2_database_1of2.zip && unzip linux.x64_11gR2_database_2of2.zip echo "centos" > /etc/hostanme echo "192.168.10.13 centos"

oracle 11g dg 部署rman方式要点记录

1.环境介绍 ip hostname sid db_name db_unique_name net service name 192.168.56.118 oraclep yunhaip yunhaip yunhaip yunhaip 192.168.56.117 oracles yunhaip yunhaip yunhais yunhais 2.修改hostname hostnamectl set-hostname oraclep 3.db部署 主:创建库,从:不创建数据库就是没有dbca那一

Oracle 11g 两个节点RAC 搭建单实例DG详细步骤以及注意事项

环境介绍: OS: 都是 [[email protected] ~]# uname -a Linux java3 2.6.18-308.el5 #1 SMP Tue Feb 21 20:06:06 EST 2012 x86_64 x86_64 x86_64 GNU/Linux 主库:  数据库版本:11.2.0.3.0  两个节点的RAC  节点一:192.168.15.26  节点二:192.168.15.27 standby 数据库版本:  11.2.0.3.0      IP 192.16

Oracle 11g RAC到单实例ASM的物理Standby搭建

一.DG环境配置 此次搭建Standby的主库为:" RedHat 6.5+11G+RAC+ASM安装与配置(三节点)",11g单实例ASM安装使用ASMLib的方式,不在使用UDEV方式,磁盘为本机磁盘,非远程挂载的磁盘.本次搭建包含了11g单实例ASM的详细安装过程. 1. 基本环境 主库: 实例名:racdb1,racdb2,racdb3        DB_NAME:racdb              DB_UNIQUE_NAME:racdb 备库: 实例名:racdg