一:实验环境介绍

虚拟机系统:    RHEL Linux 6.4(64位)

数据库版本:    Oracle 11gR2 11.2.0.4 (64位)

IP地址规划:

主数据库

192.168.11.120

SID:pri

db_name:pri

db_unique_name:pri

备份数据库

192.168.11.121

SID:std

db_name:pri

db_unique_name:std

安装完成后可以通过以下命令查询:

select dbid,name,open_mode,db_unique_name from v$database;

select instance_name from v$instance;

基础要求:(1)安装两台虚拟机分别作为主库和备库,硬盘大小随意。但要保证

根分区有20G,别给太小了就行。物理内存1G,SWAP 2G

关于Active database duplication方式:(必看)

在Oracle 10g下,我们可以使用RMAN duplicate 命令创建一个具有不同DBID 的复制库。 到了Oracle 11gR2, RMAN 的duplicate 有2种方法实现:

1. Active database duplication    (本文所使用的方式,适用于11gR2之后的版本)

2. Backup-based duplication        (传统方式,10g,11g通用)

Active database duplication 通过网络,直接copy target 库到auxiliary 库,然后创建复制库。这种方法就不需要先用RMAN 备份数据库,然后将备份文件发送到auxiliary端。

这个功能的作用是非常大的。 尤其是对T级别的库。 因为对这样的库进行备份,然后将备份集发送到备库,在进行duplicate 的代价是非常大的。 一备份要占用时间,二要占用备份空间,三在网络传送的时候,还需要占用带宽和时间。所以Active database duplicate 很好的解决了以上的问题。 它对大库的迁移非常有用。

如果是从RAC duplicate 到单实例,操作是一样的。 如果是从单实例duplicate 到RAC。 那么先duplicate 到 单实例。 然后将单实例转换成RAC。

二:安装数据库软件前的系统配置        (主库和备库端都要做下列操作)

1.基本配置:

一定要用新装的系统(这里以红帽企业版6.4为例),系统要求最低配置1G内存,2Gswap分区,根分区20G以上,装好系统后先配置好yum,IP地址,/etc/sysconfig/network文件中的主机名,以及/etc/hosts文件中的IP地址和主机名的对应关系。

主库IP:192.168.11.120

主库主机名:ora11g

备库IP:192.168.11.121

备库主机名:ora11g-dg

2.装包

binutils-2.20.51.0.2-5.11.el6 (x86_64)

compat-libcap1-1.10-1 (x86_64)

compat-libstdc++-33-3.2.3-69.el6 (x86_64)

compat-libstdc++-33-3.2.3-69.el6.i686

gcc-4.4.4-13.el6 (x86_64)

gcc-c++-4.4.4-13.el6 (x86_64)

glibc-2.12-1.7.el6 (i686)

glibc-2.12-1.7.el6 (x86_64)

glibc-devel-2.12-1.7.el6 (x86_64)

glibc-devel-2.12-1.7.el6.i686

ksh

pdksh-5.2.14-21.x86_64.rpm

libgcc-4.4.4-13.el6 (i686)

libgcc-4.4.4-13.el6 (x86_64)

libstdc++-4.4.4-13.el6 (x86_64)

libstdc++-4.4.4-13.el6.i686

libstdc++-devel-4.4.4-13.el6 (x86_64)

libstdc++-devel-4.4.4-13.el6.i686

libaio-0.3.107-10.el6 (x86_64)

libaio-0.3.107-10.el6.i686

libaio-devel-0.3.107-10.el6 (x86_64)

libaio-devel-0.3.107-10.el6.i686

make-3.81-19.el6

sysstat-9.0.4-11.el6 (x86_64)

unixODBC-2.2.14-11.el6 (x86_64) or later

unixODBC-2.2.14-11.el6.i686 or later

unixODBC-devel-2.2.14-11.el6 (x86_64) or later

unixODBC-devel-2.2.14-11.el6.i686 or later

3.创建相关的组与用户:

/usr/sbin/groupadd oinstall

/usr/sbin/groupadd -g 502 dba

/usr/sbin/groupadd -g 503 oper

/usr/sbin/useradd -u 502 -g oinstall -G dba,oper oracle

# passwd oracle

4.创建所需的目录并赋予特定的属主和属组

mkdir -p /u01/app/oracle

chown -R oracle:oinstall /u01/app

chmod -R 775 /u01/app

5.编辑limits.conf 文件

vim /etc/security/limits.conf

添加下面5行内容:

vim /etc/security/limits.conf

oracle              soft    nproc   2047

oracle              hard    nproc   16384

oracle              soft    nofile  1024

oracle              hard    nofile  65536

oracle              soft    stack   10240

6.编辑sysctl.conf文件,设置相关参数

vim /etc/sysctl.conf

添加/修改下列内容:(注意!下面的参数,若是已经存在,则直接修改数值,不要再添加同样的参数,相同的参数只能有一个!如果需要修改的参数已经大于下面的数字,则不用修改,请仔细核对!)

vim /etc/sysctl.conf

fs.aio-max-nr = 1048576

fs.file-max = 6815744

kernel.shmall = 2097152

kernel.shmmax = 4294967295

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 = 1048576

#sysctl –p 使其生效

# /sbin/sysctl -p

保存退出后,别忘了用sysctl -p命令使参数生效!

7.编辑vim /home/oracle/.bash_profile文件,配置相关环境变量

添加下列几行:

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1

export ORACLE_SID=pri (备库端设置为std)

export LD_LIBRARY_PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/local/bin:

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

export PATH=$ORACLE_HOME/bin:$PATH

注意服务器需要关闭iptablesselinux

linux6.4系统:iptables –F

Service iptables save

Setenforce 0

Vi /etc/selinux/config

[oracle@ora11g admin]$ more /etc/selinux/config

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

# enforcing - SELinux security policy is enforced.

# permissive - SELinux prints warnings instead of enforcing.

# disabled - No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE= can take one of these two values:

# targeted - Targeted processes are protected,

# mls - Multi Level Security protection.

SELINUXTYPE=targeted

三:开始安装oracle11g数据库软件        (主库和备库端都要做下列操作)

1.挂载oracle11g的镜像到/mnt/cdrom 目录下,并把3个包解压到/usr/local/src 目录下

cd /mnt/cdrom/

unzip p13390677_112040_Linux-x86-64_1of7.zip -d /usr/local/src

unzip p13390677_112040_Linux-x86-64_2of7.zip -d /usr/local/src

unzip p13390677_112040_Linux-x86-64_3of7.zip -d /usr/local/src

(只装数据库的话,解压前两个包即可,第三个包是grid)

2. root身份执行xhost +,然后切换到oracle用户进入/usr/local/src/database目录中,执行runInstaller 开始安装 (database是默认解压完的目录名)

# xhost +

# su - oracle

$ ./runInstaller

注意:安装oracle11g要求分辨率最低为1024x768,不然无法完整显示安装过程

安装过程:略

注意:主库在安装完软件后需要进行DBCA建库操作,推荐不要启用归档模式,会节省时间,备库端不要建库!可以开启监听程序

四:开始搭建Dataguard

1:将数据库改为强制日志模式            (此步骤只在主库上做)

[oracle@pri ~]$ sqlplus / as sysdba

查看当前是否强制日志模式:

SYS@pri> select name,log_mode,force_logging from v$database;

NAME LOG_MODE FOR

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

PRI         NOARCHIVELOG NO

SYS@pri> alter database force logging;

Database altered.

SYS@pri> select name,log_mode,force_logging from v$database;

NAME LOG_MODE FOR

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

PRI         NOARCHIVELOG YES

2:创建密码文件                        (此步骤只在主库上做)

注意:两端分别创建自己的密码文件好像有问题,备库的密码文件需要跟主库一致,否则导致日志传输不到备库,有待验证。我最后是将主库的密码文件直接copy到备库,重命名后使用。

[oracle@pri ~]$ cd $ORACLE_HOME/dbs

[oracle@ora11g dbs]$ ls

hc_pri.dat  init.ora  initpri.ora  lkPRI  orapwpri  snapcf_pri.f  spfilepri.ora

已经有一个密码文件了

[oracle@pri dbs]$ orapwd file=orapwpri password=oracle force=y

这条命令可以手动生成密码文件,force=y的意思是强制覆盖当前已有的密码文件(如果有可以不建立)

将主库的密码文件copy给备库,并重命名

[oracle@pri dbs]$ scp orapwpri 192.168.11.121:$ORACLE_HOME/dbs/orapwstd

3:创建standby redolog日志组            (此步骤只在主库上做)

原则:

1:standby redo log的文件大小与primary 数据库online redo log 文件大小相同

2:standby redo log日志文件组的个数依照下面的原则进行计算:

Standby redo log组数公式>=(每个instance日志组个数+1)*instance个数

假如只有一个节点,这个节点有三组redolog,

所以Standby redo log组数>=(3+1)*1 == 4

所以至少需要创建4组Standby redo log

查看当前线程与日志组的对应关系及日志组的大小:

SYS@pri> select thread#,group#,bytes/1024/1024 from v$log;

THREAD# GROUP# BYTES/1024/1024

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

1 1 50

1 2 50

1 3 50

如上,我现在的环境有三组redolog,每个日志组的大小都是50M,

所以Standby redo log组数>=(3+1)*1== 4

所以至少需要创建4组Standby redo log,大小均为50M

(thread:线程,只有在多实例数据库才有用的参数,例如RAC环境,单实例不考虑)

查看当前有哪些日志组及其成员:

SYS@pri> col member for a50

SYS@pri> select group#,member from v$logfile;

GROUP# MEMBER

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

3 /u01/app/oracle/oradata/pri/redo03.log

2 /u01/app/oracle/oradata/pri/redo02.log

1 /u01/app/oracle/oradata/pri/redo01.log

先手动创建standby log日志组所需的目录:

(创建新目录只是为了便于区分,并非必须)

[oracle@ora11g oradata]$ cd /u01/app/oracle/oradata/

[oracle@ora11g oradata]$ ls

standbylog pri

新建4个日志组作为standby redolog日志组,大小与原来的日志组一致:

由于已经存在group1-3,,所以group号只能从4开始

SYS@pri>

alter database add standby logfile group 4 '/u01/app/oracle/oradata/standbylog/std_redo04.log' size 50m;

alter database add standby logfile group 5 '/u01/app/oracle/oradata/standbylog/std_redo05.log' size 50m;

alter database add standby logfile group 6 '/u01/app/oracle/oradata/standbylog/std_redo06.log' size 50m;

alter database add standby logfile group 7 '/u01/app/oracle/oradata/standbylog/std_redo07.log' size 50m;

查看standby 日志组的信息:

SYS@pri> select group#,sequence#,status, bytes/1024/1024 from v$standby_log;

GROUP# SEQUENCE# STATUS BYTES/1024/1024

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

4 0 UNASSIGNED 50

5 0 UNASSIGNED 50

6 0 UNASSIGNED 50

7 0 UNASSIGNED 50

查看当前有哪些日志组及其成员:

SYS@pri> set pagesize 100

SYS@pri> col member for a60

SYS@pri> select group#,member from v$logfile order by group#;

GROUP#     MEMBER

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

1     /u01/app/oracle/oradata/pri/redo01.log

2     /u01/app/oracle/oradata/pri/redo02.log

3     /u01/app/oracle/oradata/pri/redo03.log

4     /u01/app/oracle/oradata/standbylog/std_redo04.log

5     /u01/app/oracle/oradata/standbylog/std_redo05.log

6     /u01/app/oracle/oradata/standbylog/std_redo06.log

7     /u01/app/oracle/oradata/standbylog/std_redo07.log

4:修改主库的pfile参数文件        (此步骤只在主库上做)

查看spfile的路径:

SYS@pri> show parameter spfile;

NAME TYPE VALUE

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

spfile string /u01/app/oracle/product/11.2.0/db_1/dbs/spfilepri.ora

用spfile创建一个pfile,用于修改:

SYS@pri> create pfile from spfile;

修改主库的pfile:

/u01/app/oracle/product/11.2.0/db_1/dbs/ initpri.ora

[oracle@pri ~]$ cd $ORACLE_HOME/dbs

pri.__db_cache_size=318767104

pri.__java_pool_size=4194304

pri.__large_pool_size=4194304

pri.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment

pri.__pga_aggregate_target=335544320

pri.__sga_target=503316480

pri.__shared_io_pool_size=0

pri.__shared_pool_size=163577856

pri.__streams_pool_size=0

*.audit_file_dest='/u01/app/oracle/admin/pri/adump'

*.audit_trail='db'

*.compatible=' 11.2.0.4.0 '

*.control_files='/u01/app/oracle/oradata/pri/control01.ctl','/u01/app/oracle/flash_recovery_area/pri/control02.ctl'

*.db_block_size=8192

*.db_domain=''

*.db_name='pri'

*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'

*.db_recovery_file_dest_size=4070572032

*.diagnostic_dest='/u01/app/oracle'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=priXDB)'

*.log_archive_format='%t_%s_%r.dbf'

*.memory_target=836763648

*.open_cursors=300

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.undo_tablespace='UNDOTBS1'

以下内容是需要新增加的:

*.db_unique_name='pri' DG主库和备库的db_name必须一致,db_unique_name不一致

*.log_archive_config='dg_config=(pri,std)' pri主数据库SID,std备份数据库SID

*.log_archive_dest_1='location=/u01/app/oracle/arch valid_for=(all_logfiles,all_roles) db_unique_name=pri' 主数据库的归档日志路径和SID

*.log_archive_dest_2='service=std valid_for=(online_logfiles,primary_role) db_unique_name=std' 备份数据库的SID

*.log_archive_dest_state_1=enable

*.log_archive_dest_state_2=enable

*.log_archive_max_processes=4

*.fal_server='std' 备份数据库的SID

*.fal_client='pri' 主数据库的SID

*.db_file_name_convert='/u01/app/oracle/oradata/std','/u01/app/oracle/oradata/pri' 第一个目录是备份数据库数据文件路径(备份服务器上有此目录),第二个是主数据库数据文件路径

*.log_file_name_convert='/u01/app/oracle/oradata/std','/u01/app/oracle/oradata/pri' 第一个目录是备份数据库数据文件路径(备份服务器上有此目录),第二个是主数据库数据文件路径

*.standby_file_management='auto'

修改完毕,保存退出

手工创建/u01/app/oracle/arch:

[oracle@pri dbs]$ mkdir –p /u01/app/oracle/arch

5:用修改过的pfile重新创建一个spfile,用于重启数据库    (此步骤只在主库上做)

关闭数据库:

SYS@pri> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

用修改过的pfile重新创建一个spfile:

SYS@pri> create spfile from pfile;

此时把数据库改为归档模式:        (如果当初建库时选择了启用归档,则此步骤忽略)

由于当前数据库已关闭,首先需要把数据库启动到mount状态

SYS@pri> startup mount;

ORACLE instance started.

Database mounted.

SYS@pri> alter database archivelog;    启用归档模式

Database altered.

SYS@pri> alter database open;        OPEN数据库

Database altered.

SYS@pri> archive log list;            查看是否启用归档模式

SQL> archive log list;

Database log mode Archive Mode

Automatic archival Enabled

Archive destination /u01/app/oracle/arch

Oldest online log sequence 22

Next log sequence to archive 24

Current log sequence 24

如上,归档路径已经改为/u01/app/oracle/arch,证明对pfile的修改已生效

查看当前数据库是否使用spfile启动:

SYS@pri> show parameter spfile;

NAME TYPE VALUE

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

spfile string /u01/app/oracle/product/11.2.0/db_1/dbs/spfilepri.ora

如上,若能看到spfile的路径,则证明数据库是使用spfile启动的,若没有值,则说明是用pfile启动的。

确认数据库已经启用归档模式和强制日志模式:

SYS@pri> select name,log_mode,force_logging from v$database;

NAME LOG_MODE FOR

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

PRI ARCHIVELOG YES

6:修改监听文件,添加静态监听        (主库、备库都要做)

主库:

[oracle@pri ~]$ cd $ORACLE_HOME/network/admin

[oracle@pri admin]$ vim listener.ora     添加的内容如下红色字体部分:

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

# Generated by Oracle configuration tools.

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

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

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

)

)

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(GLOBAL_DBNAME = pri)

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

(SID_NAME = pri)

)

)

ADR_BASE_LISTENER = /u01/app/oracle

主库修改后最终效果如下图:

备库:

[oracle@pri ~]$ cd $ORACLE_HOME/network/admin

[oracle@pri admin]$ vim listener.ora     添加的内容如下红色字体部分:

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

# Generated by Oracle configuration tools.

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

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

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

)

)

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(GLOBAL_DBNAME = std)

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

(SID_NAME = std)

)

)

ADR_BASE_LISTENER = /u01/app/oracle

备库修改后最终效果如下图:

使新增加的监听生效:    (主库和备库端都要做)

[oracle@pri admin]$ lsnrctl stop

[oracle@pri admin]$ lsnrctl start

确认新增加的静态监听有效:

主库:

[oracle@pri ~]$ lsnrctl status

..........................................(N行省略)

Services Summary...

Service "pri" has 2 instance(s).

Instance "pri", status UNKNOWN, has 1 handler(s) for this service...

Instance "pri", status READY, has 1 handler(s) for this service...

Service "priXDB" has 1 instance(s).

Instance "pri", status READY, has 1 handler(s) for this service...

The command completed successfully

备库:

[oracle@std ~]$ lsnrctl status

..........................................(N行省略)

Services Summary...

Service "std" has 2 instance(s).

Instance "std", status UNKNOWN, has 1 handler(s) for this service...

The command completed successfully

如上,静态监听添加成功

7:编辑网络服务名配置文件tnsnames.ora        (主库和备库端都要做)

[oracle@ora11g admin]$ pwd

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

[oracle@ora11g admin]$ ls

listener.ora samples tnsnames.ora

listener.ora_bak shrept.lst tnsnames.ora_bak

[oracle@ora11g admin]$ more tnsnames.ora

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

# Generated by Oracle configuration tools.

pri =

(DESCRIPTION =

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = pri)

)

)

std =

(DESCRIPTION =

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = std)

)

)

编辑结果如下图:

保证主库和备库的tnsnames.ora文件中的内容完全相同,可以把修改后的文件直接传给备库。

[oracle@ora11g admin]$ scp tnsnames.ora 192.168.11.121:$ORACLE_HOME/network/admin

tnsnames.ora 100% 925 0.9KB/s 00:00

配置完后,确保在任意一端上都能tnsping通对方:

[oracle@pri admin]$ tnsping std

[oracle@std admin]$ tnsping pri

8:在备库端,修改pfile参数文件        (只在备库端做)

首先,在主库端把pfile拷贝给备库端的$ORACLE_HOME/dbs目录下,并重命名:

[oracle@ora11g-dg ~]$ cd $ORACLE_HOME/dbs

[oracle@ora11g-dg dbs]$ ls

hc_std.dat init.ora initstd.ora lkSTD orapwstd spfilestd.ora

[oracle@ora11g dbs]$ scp initpri.ora 192.168.2.253:$ORACLE_HOME/dbs/initstd.ora

initpri.ora 100% 1497 1.5KB/s 00:00

然后在备库端进行修改:

[oracle@ora11g-db ~]$ cd $ORACLE_HOME/dbs

[oracle@ora11g-dg dbs]$ more initstd.ora

pri.__db_cache_size=318767104

pri.__java_pool_size=4194304

pri.__large_pool_size=4194304

pri.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment

pri.__pga_aggregate_target=335544320

pri.__sga_target=503316480

pri.__shared_io_pool_size=0

pri.__shared_pool_size=163577856

pri.__streams_pool_size=0

*.audit_file_dest='/u01/app/oracle/admin/std/adump'

*.audit_trail='db'

*.compatible='11.2.0.0.0'

*.control_files='/u01/app/oracle/oradata/std/control01.ctl','/u01/app/oracle/oradata/std/control02.ctl'

*.db_block_size=8192

*.db_domain=''

*.db_name='pri' DG主库和备库的db_name必须一致,db_unique_name不一致

*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'

*.db_recovery_file_dest_size=4070572032

*.diagnostic_dest='/u01/app/oracle'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=stdXDB)'

*.log_archive_format='%t_%s_%r.dbf'

*.memory_target=836763648

*.open_cursors=300

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.undo_tablespace='UNDOTBS1'

以下需要手工添加

*.db_unique_name='std'

*.log_archive_config='dg_config=(pri,std)'

*.log_archive_dest_1='location=/u01/app/oracle/arch valid_for=(all_logfiles,all_

roles) db_unique_name=std'

*.log_archive_dest_2='service=pri valid_for=(online_logfiles,primary_role) db

_unique_name=pri'

*.log_archive_dest_state_1=enable

*.log_archive_dest_state_2=enable

*.log_archive_max_processes=4

*.fal_server='pri'

*.fal_client='std'

*.db_file_name_convert='/u01/app/oracle/oradata/pri','/u01/app/oracle/oradata

/std'

*.log_file_name_convert='/u01/app/oracle/oradata/pri','/u01/app/oracle/oradat

a/std'

*.standby_file_management='auto'

修改完毕,保存退出

注意:整个搭建过程最需要留意的就是主库和备库的PFILE配置,建议修改完后仔细对照主备库PFILE的区别

9:在备库端手工创建所需的目录    (备库端做,不提前创建的话恢复时会报错!)

mkdir -pv /u01/app/oracle/admin/std/adump

mkdir -pv /u01/app/oracle/diag/rdbms/std/std/trace

mkdir -pv /u01/app/oracle/arch

mkdir -pv /u01/app/oracle/oradata/std

mkdir -pv /u01/app/oracle/oradata/standbylog

mkdir -pv /u01/app/oracle/flash_recovery_area

10:用修改后的pfile创建一个spfile,用于启动数据库        (备库端做)

[oracle@std ~]$ sqlplus / as sysdba

Connected to an idle instance.

SYS@std> create spfile from pfile;

File created.

将数据库启动到nomount状态:

SYS@std> startup nomount;

ORACLE instance started.

Total System Global Area 839282688 bytes

Fixed Size 2233000 bytes

Variable Size 482348376 bytes

Database Buffers 352321536 bytes

Redo Buffers 2379776 bytes

SYS@std>

11:利用RMAN在备库上恢复主库            (备库端做)

[oracle@std ~]$ rman target sys/oracle@pri auxiliary sys/oracle@std

Recovery Manager: Release 11.2.0.3.0 - Production on Tue Apr 15 16:39:28 2014

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

connected to target database: PRI (DBID=775616459)

connected to auxiliary database: PRI (not mounted)

RMAN> duplicate target database for standby from active database nofilenamecheck;

这条命令可以直接恢复数据文件,standby控制文件,standby日志组,非常霸道

Starting Duplicate Db at 16-MAR-16

using target database control file instead of recovery catalog

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=134 device type=DISK

contents of Memory Script:

{

backup as copy reuse

targetfile '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwpri' auxiliary format

'/u01/app/oracle/product/11.2.0/db_1/dbs/orapwstd' ;

}

executing Memory Script

Starting backup at 16-MAR-16

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=140 device type=DISK

Finished backup at 16-MAR-16

contents of Memory Script:

{

backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/std/control01.ctl';

}

executing Memory Script

Starting backup at 16-MAR-16

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

copying standby control file

output file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_pri.f tag=TAG20160316T110737 RECID=2 STAMP=906635257

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

Finished backup at 16-MAR-16

contents of Memory Script:

{

sql clone 'alter database mount standby database';

}

executing Memory Script

sql statement: alter database mount standby database

contents of Memory Script:

{

set newname for tempfile 1 to

"/u01/app/oracle/oradata/std/temp01.dbf";

switch clone tempfile all;

set newname for datafile 1 to

"/u01/app/oracle/oradata/std/system01.dbf";

set newname for datafile 2 to

"/u01/app/oracle/oradata/std/sysaux01.dbf";

set newname for datafile 3 to

"/u01/app/oracle/oradata/std/undotbs01.dbf";

set newname for datafile 4 to

"/u01/app/oracle/oradata/std/users01.dbf";

backup as copy reuse

datafile 1 auxiliary format

"/u01/app/oracle/oradata/std/system01.dbf" datafile

2 auxiliary format

"/u01/app/oracle/oradata/std/sysaux01.dbf" datafile

3 auxiliary format

"/u01/app/oracle/oradata/std/undotbs01.dbf" datafile

4 auxiliary format

"/u01/app/oracle/oradata/std/users01.dbf" ;

sql 'alter system archive log current';

}

executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/std/temp01.dbf in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 16-MAR-16

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

input datafile file number=00001 name=/u01/app/oracle/oradata/pri/system01.dbf

output file name=/u01/app/oracle/oradata/std/system01.dbf tag=TAG20160316T110744

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:38

channel ORA_DISK_1: starting datafile copy

input datafile file number=00002 name=/u01/app/oracle/oradata/pri/sysaux01.dbf

output file name=/u01/app/oracle/oradata/std/sysaux01.dbf tag=TAG20160316T110744

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:09

channel ORA_DISK_1: starting datafile copy

input datafile file number=00003 name=/u01/app/oracle/oradata/pri/undotbs01.dbf

output file name=/u01/app/oracle/oradata/std/undotbs01.dbf tag=TAG20160316T110744

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15

channel ORA_DISK_1: starting datafile copy

input datafile file number=00004 name=/u01/app/oracle/oradata/pri/users01.dbf

output file name=/u01/app/oracle/oradata/std/users01.dbf tag=TAG20160316T110744

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

Finished backup at 16-MAR-16

sql statement: alter system archive log current

contents of Memory Script:

{

switch clone datafile all;

}

executing Memory Script

datafile 1 switched to datafile copy

input datafile copy RECID=2 STAMP=906635463 file name=/u01/app/oracle/oradata/std/system01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=3 STAMP=906635463 file name=/u01/app/oracle/oradata/std/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=4 STAMP=906635463 file name=/u01/app/oracle/oradata/std/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=5 STAMP=906635463 file name=/u01/app/oracle/oradata/std/users01.dbf

Finished Duplicate Db at 16-MAR-16

RMAN>

恢复数据库结束

12:尝试开启备库

登陆并查看数据库当前状态:

[oracle@std ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Tue Jan 14 16:41:50 2014

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SYS@std> startup

SYS@std> select status from v$instance;

STATUS

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

MOUNTED        (RMAN恢复完直接就是mount状态)

13:备库启动日志应用(启用备库前确认归档日志是否都已拷贝)

SYS@std> alter database recover managed standby database disconnect from session;

Database altered.

(停止日志应用的命令是:alter database recover managed standby database cancel;)

查看日志应用情况:

SYS@std> set pagesize 100

SYS@std> select sequence#,applied from v$archived_log order by 1;

SEQUENCE# APPLIED

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

8 YES

9 YES

10 YES

如上,如果发现有个NO的,也是正常的,说明该日志在主库上还没有归档,可以在主库上运行alter system switch logfile;命令来进行日志切换,再到备库查看日志应用情况

14:分别查看主库和备库的归档序列号是否一致:

先在主库手动切换一下日志:

SYS@pri> alter system switch logfile;

System altered.

然后查看主库:

SYS@pri> archive log list;

SQL> archive log list;

Database log mode Archive Mode

Automatic archival Enabled

Archive destination /u01/app/oracle/arch

Oldest online log sequence 22

Next log sequence to archive 24

Current log sequence 24

备库:

SQL> archive log list;

Database log mode Archive Mode

Automatic archival Enabled

Archive destination /u01/app/oracle/arch

Oldest online log sequence 22

Next log sequence to archive 0

Current log sequence 24

结果完全一致,至此,DataGuard的搭建成功!

15:检查命令

查看standby启动的DG进程

SQL> select process,client_process,sequence#,status from v$managed_standby;

PROCESS   CLIENT_P  SEQUENCE# STATUS

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

ARCH      ARCH             23 CLOSING

ARCH      ARCH              0 CONNECTED            //归档进程

ARCH      ARCH             21 CLOSING

ARCH      ARCH              0 CONNECTED

RFS       ARCH              0 IDLE

RFS       UNKNOWN           0 IDLE

RFS       LGWR             24 IDLE               //归档传输进程

RFS       UNKNOWN           0 IDLE

MRP0      N/A              24 APPLYING_LOG      //日志应用进程

9 rows selected.

查看数据库的保护模式:

SQL> select database_role,protection_mode,protection_level,open_mode from v$database;

DATABASE_ROLE    PROTECTION_MODE      PROTECTION_LEVEL     OPEN_MODE

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

PRIMARY          MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE  READ WRITE

#standby 端查看,也是一样的。

SQL> select database_role,protection_mode,protection_level,open_mode from v$database;

DATABASE_ROLE    PROTECTION_MODE      PROTECTION_LEVEL     OPEN_MODE

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

PHYSICAL STANDBY MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE  MOUNTED

查看DG的日志信息

SQL> select * from v$dataguard_status;

16:Open Read Only standby数据库并且开启实时日志应用

SQL> shutdown immediate

ORA-01109: database not open

Database dismounted.

ORACLE instance shut down.

SQL> startup

ORACLE instance started.

Total System Global Area 1188511744 bytes

Fixed Size                  1364228 bytes

Variable Size             754978556 bytes

Database Buffers          419430400 bytes

Redo Buffers               12738560 bytes

Database mounted.

Database opened.

SQL> select database_role,protection_mode,protection_level,open_mode from v$database;

DATABASE_ROLE    PROTECTION_MODE      PROTECTION_LEVEL     OPEN_MODE

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

PHYSICAL STANDBY MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE  READ ONLY

SQL> select process,client_process,sequence#,status from v$managed_standby;

PROCESS   CLIENT_P  SEQUENCE# STATUS

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

ARCH      ARCH              0 CONNECTED

ARCH      ARCH              0 CONNECTED

ARCH      ARCH              0 CONNECTED

ARCH      ARCH             26 CLOSING

RFS       ARCH              0 IDLE

RFS       UNKNOWN           0 IDLE

RFS       LGWR             27 IDLE

7 rows selected.

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

Media recovery complete.

SQL> select process,client_process,sequence#,status from v$managed_standby;

PROCESS   CLIENT_P  SEQUENCE# STATUS

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

ARCH      ARCH              0 CONNECTED

ARCH      ARCH              0 CONNECTED

ARCH      ARCH              0 CONNECTED

ARCH      ARCH             26 CLOSING

RFS       ARCH              0 IDLE

RFS       UNKNOWN           0 IDLE

RFS       LGWR             27 IDLE

MRP0      N/A              27 APPLYING_LOG

8 rows selected.

SQL> select process,client_process,sequence#,status from v$managed_standby;

PROCESS   CLIENT_P  SEQUENCE# STATUS

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

ARCH   ARCH         19 CLOSING

ARCH   ARCH         20 CLOSING

ARCH   ARCH          0 CONNECTED

ARCH   ARCH         21 CLOSING

MRP0   N/A          22 WAIT_FOR_LOG

RFS   ARCH          0 IDLE

RFS   UNKNOWN       0 IDLE

RFS   UNKNOWN       0 IDLE

RFS   LGWR         22 IDLE

9 rows selected.

五:相关知识补充:

1:DataGuard的三种数据保护模式:

(1)MAXIMIZE PROTECTION(最大保护模式):

最大数据保护与无数据分歧,LGWR将同时传送到备用节点,在主节点事务确认之前,备用节点也必须完全收到日志数据。如果网络不好,引起LGWR不能传送数据,将引起严重的性能问题,导致主节点DOWN机。

(2)MAXIMIZE AVAILABILITY(最大可用模式):

无数据丢失模式,允许数据分歧,允许异步传送。正常情况下运行在最大保护模式,在主节点与备用节点的网络断开或连接不正常时,自动切换到最大性能模式,主节点的操作还是可以继续的。在网络不好的情况下有较大的性能影响。

(3)MAXIMIZE PERFORMANCE(最大性能模式):

这种模式应当可以说是从8i继承过来的备用服务器模式,异步传送,无数据同步检查,可能丢失数据,但是能获得主节点的最大性能。

oracle 11g ADG实施手册(亲测,已成功部署多次)的更多相关文章

  1. 转载:oracle 11g ADG实施手册(亲测,已成功部署多次)

    https://www.cnblogs.com/yhfssp/p/7815078.html 一:实验环境介绍 虚拟机系统: RHEL Linux 6.4(64位) 数据库版本: Oracle 11gR ...

  2. Navicat Premium 12.0.24安装与激活(亲测已成功激活)

    另请参见:Navicat Premium 12.0.18 / 12.0.24安装与激活 另请参见:Navicat Premium 12安装与激活(亲测已成功激活) 说明: 本主亲自验证过,可以激活! ...

  3. Navicat Premium 12安装与激活(亲测已成功激活)

    说明:博主所提供的激活文件理论支持Navicat Premium 12.0.16 - 12.0.24简体中文64位,但已测试的版本为Navicat Premium 12.0.22.12.0.23和12 ...

  4. Oracle 11g R2安装手册(图文教程)For Windows

    1.Oracle 11g R2安装手册(图文教程)For Windows 1.下载Oracle 11g R2 for Windows版本,下载地址如下 官方网站: http://download.or ...

  5. 组态ORACLE 11G ADG

    一旦载10g的,没有票据.昨天使用duplicate方法一安装11g ADG,过程艰辛,记录: 一.环境配置 主图书馆 IP地址:192.168.233.128/24 操作系统版本号:rhel5.8 ...

  6. ubuntu安装QQ目前最完善的方法!(亲测,成功)

    wine qq 2012 for linux Ubuntu 64位兼容(12月21日末日版) 由 smile » 2011-04-07 9:08 +-------------------------- ...

  7. Intellij IDEA 2020.1.1 破解 永久有效 亲测100%成功

    申明:本教程 WebStorm 破解补丁.激活码均收集于网络,请勿商用,仅供个人学习使用,如有侵权,请联系作者删除. 前言 作为一个有强迫症的码农,怎么能忍受自己的开发工具跟不上潮流呢?笔者以前一直用 ...

  8. WebStorm 2019.3.1 破解 永久使用 亲测100%成功

    声明:本教程 WebStorm 破解补丁.激活码均收集于网络,请勿商用,仅供个人学习使用,如有侵权,请联系作者删除. 前言 今天问公司前端的美眉,你的激活码哪里来的,她说淘宝买的,我说给我用一下,当时 ...

  9. Ubuntu16.04编译Openjdk8,笔者亲测编译成功

    现在很多语言都不开发运行环境了,都选择在JRE上运行,足以证明JVM的优越.你精通了JVM,未来的路才可能走得轻松.这篇文章是你走近jvm的第一篇,编译Openjdk8源码 编译环境 操作系统:Ubu ...

随机推荐

  1. MFC实现http连接、发送和接收数据

    #include <afxinet.h> // 设置超时 CInternetSession session; session.SetOption(INTERNET_OPTION_CONNE ...

  2. 使用gogs和glide来轻松拉取golang第三方库

    golang的第三方代码拉取一直是让人头疼的问题,在github托管的代码还好,托管在其他网站上的代码总会由于大家都懂的原因,无法访问.纵使是github,在拉取文件数量较多的库时,也是比较慢的. 有 ...

  3. Scala学习笔记(四)—— 数组

    定长数组Array 定义定长数组用Array,有如下几种方法: 初始化一个长度为8的定长数组,其所有元素默认值均为0 scala> new Array[Int](8) res0: Array[I ...

  4. sublime_text3常用操作与快捷键

    1.编辑多列 按鼠标滚轮进行多列选中 键盘ctrl+alt+↓进行多行选中操作 2.快捷键 ctrl+H:替换(F为经典的搜索) ctrl+G:跳到指定行 ctrl+D:选词,连续按选中下面匹配的词, ...

  5. MapWindow记录

    增加MapWinGIS的新功能,编译完MapWinGIS,可以生成Debug和Release版本的x64和Win32四种版本, 自己基于c#的Mapwindow如果要用到新添加的功能,此时就得重新注册 ...

  6. protected修饰符详解

    protected这个修饰符,各大参考书都会这样说:访问权限为类内,包内和子类,因此在父类中定义的方法和成员变量如果为protected修饰的,是可以在不同包中的子类进行访问的,示例代码如下: pac ...

  7. Oracle DELETE和TRUNCATE 的区别

    语法delete from aa truncate table aa 区别 1.delete from后面可以写条件,truncate不可以. 2.delete from记录是一条条删的,所删除的每行 ...

  8. 「日常训练」Regular Bridge(Codeforces Round 306 Div.2 D)

    题意与分析 图论基础+思维题. 代码 #include <bits/stdc++.h> #define MP make_pair #define PB emplace_back #defi ...

  9. Python搭配unittest

    unittest是Python的单元测试框架, 类似于Java里面的TestNG. Unittest.py: import unittest from selenium import webdrive ...

  10. js 加密 crypto-js des加密

    js 加密 crypto-js    https://www.npmjs.com/package/crypto-js   DES  举例:   js 引入:   <script src=&quo ...