一.搭建环境
虚拟机系统: CentOS6.10(final)(64位)
数据库版本: Oracle 11gR2 11.2.0.4 (64位)
IP地址规划:
192.168.88.111 | 192.168.88.112 |
---|---|
SID:fsda | SID:fsdb |
db_name:pri | db_name:pri |
db_unique_name:fsda | db_unique_name:fsdb |
在数据安装完后,可用下面的命令检查配置是否正确
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种方法实现:
Active database duplication (本文所使用的方式,适用于11gR2之后的版本)
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.基本配置:
一定要用新装的系统(这里以CentOS版6.10(final)为例),系统要求最低配置内存1G,swap分区2G,根分区20G以上,装好系统后先配置好yum,IP地址,/etc/sysconfig/network文件中的主机名,以及/etc/hosts文件中的IP地址和主机名的对应关系。
主库IP:192.168.88.111
主库主机名:pri
备库IP:192.168.88.112
备库主机名:sla
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.创建相关的组与用户
groupadd oinstall
groupadd -g 502 dba
groupadd -g 503 oper
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
在行末添加如下参数
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
在行末添加如下参数
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/db
export ORACLE_SID=fsda (备库端设置为fsdb)
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
关闭iptables和selinux
service iptables stop
chkconfig iptables off
[root@pri ~]#vi /etc/selinux/config
将SELINUX的值改为disabled
# 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的镜像到/tmp目录下,并把3个包解压
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用户进入/tmp/database目录中,执行runInstaller 开始安装 (database是默认解压完的目录名)
$ ./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@pri 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.88.112:$ORACLE_HOME/dbs/orapfsdb
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
查看当前线程与日志组的对应关系及日志组的大小:
SQL> 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环境,单实例不考虑)
查看当前有哪些日志组及其成员:
SQL> col member for a50
SQL> 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@pri oradata]$ cd /u01/app/oracle/oradata/
[oracle@pri oradata]$ ls
standbylog fsda
新建4个日志组作为standby redolog日志组,大小与原来的日志组一致,由于已经存在group1-3,,所以group号只能从4开始
SQL>
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
查看当前有哪些日志组及其成员:
SQL> set pagesize 100
SQL> col member for a60
SQL> 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的路径:
SQL> 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/db/dbs/ initfsda.ora
[oracle@pri ~]$ cd $ORACLE_HOME/dbs
fsda.__db_cache_size=318767104
fsda.__java_pool_size=4194304
fsda.__large_pool_size=4194304
fsda.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
fsda.__pga_aggregate_target=335544320
fsda.__sga_target=503316480
fsda.__shared_io_pool_size=0
fsda.__shared_pool_size=163577856
fsda.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/fsda/adump'
*.audit_trail='db'
*.compatible=' 11.2.0.4.0 '
*.control_files='/u01/app/oracle/oradata/fsda/control01.ctl','/u01/app/oracle/flash_recovery_area/fsda/control02.ctl'
*.db_block_size=8192
*.db_domain='' "
*.db_name='fsda'
*.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=fsdaXDB)
*.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=(fsda,fsdb)' fsda主数据库SID,fsdb备份数据库SID
*.log_archive_dest_1='location=/u01/app/oracle/arch valid_for=(all_logfiles,all_roles) db_unique_name=fsda' 主 数据库的归档日志路径和SID
*.log_archive_dest_2='service=fsdb valid_for=(online_logfiles,primary_role) db_unique_name=fsdb' 备份数据库的SID
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.log_archive_max_processes=4
*.fal_server='fsdb' 备份数据库的SID
*.fal_client='fsda' 主数据库的SID
*.db_file_name_convert='/u01/app/oracle/oradata/fsdb','/u01/app/oracle/oradata/fsda' 第一个目录是备份数据库数据文件路径(备份服务器上有此目录),第二个是主数据库数据文件路径
*.log_file_name_convert='/u01/app/oracle/oradata/fsdb','/u01/app/oracle/oradata/fsda' 第一个目录是备份数据库数据文件路径(备份服务器上有此目录),第二个是主数据库数据文件路径
*.standby_file_management='auto'
修改完毕,保存退出
手工创建/u01/app/oracle/arch
[oracle@pri dbs]$ mkdir –p /u01/app/oracle/arch
5:用修改过的pfile重新创建一个spfile,用于重启数据库 (此步骤只在主库上做)
关闭数据库:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
用修改过的pfile重新创建一个spfile:
SQL> create spfile from pfile;
此时把数据库改为归档模式(如果当初建库时选择了启用归档,则此步骤忽略),由于当前数据库已关闭,首先需要把数据库启动到mount状态
SQL> startup mount;
ORACLE instance started.
Database mounted.
SQL> alter database archivelog; //启用归档模式
Database altered.
SQL> alter database open; //OPEN数据库
Database altered.
SQL> 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 20
Next log sequence to archive 22
Current log sequence 22
如上,归档路径已经改为/u01/app/oracle/arch,证明对pfile的修改已生效
查看当前数据库是否使用spfile启动:
SQL> show parameter spfile;
NAME TYPE VALUE
----------- ----------- -----------------------------------------------------------------
spfile string /u01/app/oracle/product/11.2/db_1/dbs/spfilefsda.ora
如上,若能看到spfile的路径,则证明数据库是使用spfile启动的,若没有值,则说明是用pfile启动的。
确认数据库已经启用归档模式和强制日志模式:
SQL> select name,log_mode,force_logging from v$database;
NAME LOG_MODE FOR
--------- ------------------- -------
FSDA 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/db/network/admin/listener.ora
#Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.88.111)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = fsda)
(ORACLE_HOME = /u01/app/oracle/product/11.2/db)
(SID_NAME = fsda)
)
)
ADR_BASE_LISTENER = /u01/app/oracle
备库:
[oracle@sla ~]$ cd $ORACLE_HOME/network/admin
[oracle@sla admin]$ vim listener.ora //参照如下修改
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.88.112)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = fsdb)
(ORACLE_HOME = /u01/app/oracle/product/11.2/db)
(SID_NAME = fsdb)
)
)
ADR_BASE_LISTENER = /u01/app/oracle
使新增加的监听生效: (主库和备库端都要做)
[oracle@pri admin]$ lsnrctl stop
[oracle@pri admin]$ lsnrctl start
确认新增加的静态监听有效:
主库:
[oracle@pri ~]$ lsnrctl status
..........................................(N行省略)
Services Summary...
Service "fsda" has 1 instance(s).
Instance "fsda", status UNKNOWN, has 1 handler(s) for this service...
Instance "fsda", status READY, has 1 handler(s) for this service...
Service "fsdaXDB" has 1 instance(s).
Instance "fsda", status READY, has 1 handler(s) for this service...
The command completed successfully
备库:
[oracle@sla ~]$ 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@pri admin]$ pwd
/u01/app/oracle/product/11.2/db/network/admin
[oracle@pri admin]$ ls
listener.ora samples tnsnames.ora
listener.ora_bak shrept.lst tnsnames.ora_bak
[oracle@opri admin]$ vim tnsnames.ora //参照如下更改
#tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2/db/network/admin/tnsnames.ora
#Generated by Oracle configuration tools.
fsda =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.88.111)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = fsda)
)
)
fsdb =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.88.112)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = fsdb)
)
)
为了保证主库和备库的tnsnames.ora文件中的内容完全相同,可以把修改后的文件直接传给备库。
[oracle@pri admin]$ scp tnsnames.ora 192.168.88.112:$ORACLE_HOME/network/admin
tnsnames.ora 100% 925 0.9KB/s 00:00
配置完后,确保在任意一端上都能tnsping通对方:
[oracle@pri admin]$ tnsping sla
[oracle@sla admin]$ tnsping pri
8:在备库端,修改pfile参数文件 (只在备库端做)
首先,在主库端把pfile拷贝给备库端的$ORACLE_HOME/dbs目录下,并重命名:
[oracle@pri ~]$ cd $ORACLE_HOME/dbs
[oracle@pri dbs]$ ls
hc_std.dat init.ora initfsda.ora lkSTD orapwstd spfilestd.ora
[oracle@pri dbs]$ scp initfsda.ora 192.168.88.112:$ORACLE_HOME/dbs/initfsdb.ora
initfsda.ora 100% 1497 2.4KB/s 00:00
然后在备库端进行修改:
[oracle@sla ~]$ cd $ORACLE_HOME/dbs
[oracle@sla dbs]$ more initfsdb.ora
fsdb.__db_cache_size=318767104
fsdb.__java_pool_size=4194304
fsdb.__large_pool_size=4194304
fsdb_oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
fsdb.__pga_aggregate_target=335544320
fsdb.__sga_target=503316480
fsdb.__shared_io_pool_size=0
fsdb.__shared_pool_size=163577856
fsdb.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/fsdb/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/fsdb/control01.ctl','/u01/app/oracle/oradata/fsdb/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=fsdbXDB)'
*.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='fsdb'
*.log_archive_config='dg_config=(fsda,fsdb)'
*.log_archive_dest_1='location=/u01/app/oracle/arch valid_for=(all_logfiles,all_
roles) db_unique_name=fsdb'
*.log_archive_dest_2='service=pri valid_for=(online_logfiles,primary_role) db
_unique_name=fsda'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.log_archive_max_processes=4
*.fal_server='fsda'
*.fal_client='fsdb'
*.db_file_name_convert='/u01/app/oracle/oradata/fsda','/u01/app/oracle/oradata
/fsdb'
*.log_file_name_convert='/u01/app/oracle/oradata/fsda','/u01/app/oracle/oradat
a/fsdb'
*.standby_file_management='auto'
修改完毕,保存退出
注意:整个搭建过程最需要留意的就是主库和备库的PFILE配置,建议修改完后仔细对照主备库PFILE的区别
9:在备库端手工创建所需的目录(备库端做,不提前创建的话恢复时会报错!)
mkdir -pv /u01/app/oracle/admin/fsdb/adump
mkdir -pv /u01/app/oracle/diag/rdbms/fsdb/fsdb/trace
mkdir -pv /u01/app/oracle/arch
mkdir -pv /u01/app/oracle/oradata/fsdb
mkdir -pv /u01/app/oracle/oradata/standbylog
mkdir -pv /u01/app/oracle/flash_recovery_area
10:用修改后的pfile创建一个spfile,用于启动数据库(备库端做)
[oracle@sla ~]$ sqlplus / as sysdba
Connected to an idle instance.
sys@sla> create spfile from pfile;
File created.
将数据库启动到nomount状态:
sys@sla 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
[oracle@sla ~]$ rman target sys/oracle@fsda auxiliary sys/oracle@fsdb
Recovery Manager: Release 11.2.0.3.0 - Production on Thur Nov 7 22:43:13 2019
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: FSDA (DBID=775616459)
connected to auxiliary database: FSDA (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/db/dbs/orapwfsda' auxiliary format
'/u01/app/oracle/product/11.2/db/dbs/orapwfsdb' ;
}
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/fsdb/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/db/dbs/snapcf_fsda.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/fsdb/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/u01/app/oracle/oradata/fsdb/system01.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/fsdb/sysaux01.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/fsdb/undotbs01.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/fsdb/users01.dbf";
backup as copy reuse
datafile 1 auxiliary format
"/u01/app/oracle/oradata/fsdb/system01.dbf" datafile
2 auxiliary format
"/u01/app/oracle/oradata/fsdb/sysaux01.dbf" datafile
3 auxiliary format
"/u01/app/oracle/oradata/fsdb/undotbs01.dbf" datafile
4 auxiliary format
"/u01/app/oracle/oradata/fsdb/users01.dbf" ;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/fsdb/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/fsda/system01.dbf
output file name=/u01/app/oracle/oradata/fsdb/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/fsda/sysaux01.dbf
output file name=/u01/app/oracle/oradata/fsdb/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/fsda/undotbs01.dbf
output file name=/u01/app/oracle/oradata/fsdb/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/fsda/users01.dbf
output file name=/u01/app/oracle/oradata/fsdb/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/fsdb/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=906635463 file name=/u01/app/oracle/oradata/fsdb/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=906635463 file name=/u01/app/oracle/oradata/fsdb/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=906635463 file name=/u01/app/oracle/oradata/fsdb/users01.dbf
Finished Duplicate Db at 16-MAR-16
RMAN>
恢复数据库结束
12:开启备库
登陆并查看数据库当前状态:
[oracle@sla ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Thur Nov 7 22:59:43 2019
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@fsdb> startup
sys@fsdb> select status from v$instance;
STATUS
------------
MOUNTED
RMAN恢复完直接就是mount状态
13:备库启动日志应用(启用备库前确认归档日志是否都已拷贝)
sys@fsdb> alter database recover managed standby database disconnect from session;
Database altered.
停止日志应用的命令是:alter database recover managed standby database cancel;
查看日志应用情况:
sys@fsdb> set pagesize 100
sys@fsdb> select sequence#,applied from v$archived_log order by 1;
SEQUENCE# APPLIED
---------- ---------
9 YES
10 YES
11 YES
如上,如果发现有个NO的,也是正常的,说明该日志在主库上还没有归档,可以在主库上运行alter system switch logfile;命令来进行日志切换,再到备库查看日志应用情况
14:分别查看主库和备库的归档序列号是否一致:
先在主库手动切换一下日志:
sys@fsda> alter system switch logfile;
System altered.
然后查看主库:
sys@fsda> 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 23
Next log sequence to archive 25
Current log sequence 25
备库:
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/arch
Oldest online log sequence 23
Next log sequence to archive 0
Current log sequence 25
结果完全一致,至此,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 25 IDLE //归档传输进程
RFS UNKNOWN 0 IDLE
MRP0 N/A 25 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 20 CLOSING
ARCH ARCH 21 CLOSING
ARCH ARCH 0 CONNECTED
ARCH ARCH 22 CLOSING
MRP0 N/A 23 WAIT_FOR_LOG
RFS ARCH 0 IDLE
RFS UNKNOWN 0 IDLE
RFS UNKNOWN 0 IDLE
RFS LGWR 23 IDLE
9 rows selected.
DataGuard的三种数据保护模式:
(1)MAXIMIZE PROTECTION(最大保护模式):
最大数据保护与无数据分歧,LGWR将同时传送到备用节点,在主节点事务确认之前,备用节点也必须完全收到日志数据。如果网络不好,引起LGWR不能传送数据,将引起严重的性能问题,导致主节点DOWN机。
(2)MAXIMIZE AVAILABILITY(最大可用模式):
无数据丢失模式,允许数据分歧,允许异步传送。正常情况下运行在最大保护模式,在主节点与备用节点的网络断开或连接不正常时,自动切换到最大性能模式,主节点的操作还是可以继续的。在网络不好的情况下有较大的性能影响。
(3)MAXIMIZE PERFORMANCE(最大性能模式):
这种模式应当可以说是从8i继承过来的备用服务器模式,异步传送,无数据同步检查,可能丢失数据,但是能获得主节点的最大性能。