企业级 oracle11G r2 DataGuard 安装配置
安装环境
IP地址与机器名 /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
172.16.0.173 oracle173 #primary
172.16.0.174 oracle174 #standby
准备安装环境172.16.0.173 oracle173 #primary把数据库软件与实例,监听安装好。
172.16.0.174 oracle174 #standby 只安装数据库软件
1.修改oracle173 #primaryr 的tnsnames.ora文件
[oracle@oracle173 ~]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/
[oracle@oracle173 admin]$ vi tnsnames.ora
orcl02 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle174)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
orcl01 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle173)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle173)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
2.修改oracle173 #primaryr 的listener.ora
[oracle@oracle173 admin]$ vi listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle173)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
3.拷oracle173 #primary 的listener.ora、tnsnames.ora及密码文件 orapworcl 到oracle174
#standby,并修改listener.ora、tnsnames.ora文件
[oracle@oracle173admin]$cd /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/
$ scp listener.ora oracle174:/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/
$ scp tnsnames.ora oracle174:/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/
[oracle@oracle173 admin]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/dbs/
$ scp orapworcl oracle174:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
[oracle@oracle174 ~]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/
[oracle@oracle174 admin]$ vi listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle174)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
[oracle@oracle174 admin]$ vi tnsnames.ora
orcl02 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle174)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
orcl01 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle173)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle174)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
4.启动监听
[oracle@oracle173 dbs]$ lsnrctl start
[oracle@oracle174 admin]$ lsnrctl start
5.创建oracle目录
#oracle173 #primary
[root@oracle173 ~]# mkdir -p /u02/app/oracle/oradata/orcl/
[root@oracle173 ~]# chown -R oracle:oinstall /u02
[root@oracle173 ~]# chmod -R +x /u02
#oracle174 #standby
[root@oracle174 ~]# mkdir -p /u02/app/oracle/oradata/orcl/
[root@oracle174 ~]# chown -R oracle:oinstall /u02
[root@oracle174 ~]# chmod -R +x /u02
[oracle@oracle174 admin]$ mkdir -p /u01/app/oracle/oradata/orcl/
[oracle@oracle174 admin]$ mkdir -p /u01/app/oracle/flash_recovery_area/orcl/
[oracle@oracle174 admin]$ mkdir -p /u01/app/oracle/admin/orcl/adump/
[oracle@oracle174 admin]$ mkdir -p /u01/app/oracle/admin/orcl/dpdump/
[oracle@oracle174 admin]$ mkdir -p /u01/app/oracle/admin/orcl/pfile/
[oracle@oracle174 admin]$ mkdir -p /u01/app/oracle/admin/orcl/scripts/
6.配置oracle173 #primary数据库的参数
[oracle@oracle173 orcl]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Mon Jun 23 21:25:48 2014
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 1653518336 bytes
Fixed Size 2213896 bytes
Variable Size 956303352 bytes
Database Buffers 687865856 bytes
Redo Buffers 7135232 bytes
Database mounted.
Database opened.
SQL> alter database force logging;
Database altered.
SQL> create pfile from spfile;
File created.
[oracle@oracle173 orcl]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/dbs/
[oracle@oracle173 dbs]$ ls
hc_DBUA0.dat init.ora lkORCL spfileorcl.ora
hc_orcl.dat initorcl.ora orapworcl
[oracle@oracle173 dbs]$ mv spfileorcl.ora spfileorcl.ora.bak
[oracle@oracle173 dbs]$ vi initorcl.ora
orcl.__db_cache_size=687865856
orcl.__java_pool_size=16777216
orcl.__db_cache_size=687865856
orcl.__java_pool_size=16777216
orcl.__large_pool_size=16777216
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=671088640
orcl.__sga_target=989855744
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=251658240
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/flash_recovery_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.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=orclXDB)'
#*.log_archive_dest_1='LOCATION=/home/oracle/arch'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=1655701504
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*.db_unique_name=uqn_orcl01
*.log_archive_config='DG_CONFIG=(uqn_orcl01,uqn_orcl02)'
*.log_archive_dest_1='LOCATION=/home/oracle/arch noreopen optional VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=uqn_orcl01'
*.log_archive_dest_2='SERVICE=orcl02 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=uqn_orcl02 ARCH SYNC REOPEN=10'
*.log_archive_dest_state_1=ENABLE
*.log_archive_dest_state_2=ENABLE
*.FAL_SERVER='orcl02'
*.FAL_CLIENT='orcl01'
*.STANDBY_FILE_MANAGEMENT='AUTO'
*.log_file_name_convert='/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/orcl/'
-------------------------------------------
[oracle@oracle173 dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Mon Jun 23 21:48:04 2014
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 1653518336 bytes
Fixed Size 2213896 bytes
Variable Size 956303352 bytes
Database Buffers 687865856 bytes
Redo Buffers 7135232 bytes
Database mounted.
Database opened.
7.拷贝参数文件到standby (oracle174)
[oracle@oracle173 dbs]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/dbs/
$ scp initorcl.ora oracle174:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
8.修改standby(oracle174) 参数文件
[oracle@oracle174 admin]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/dbs/
[oracle@oracle174 dbs]$ vi initorcl.ora
orcl.__db_cache_size=687865856
orcl.__java_pool_size=16777216
orcl.__large_pool_size=16777216
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=671088640
orcl.__sga_target=989855744
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=251658240
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.db_block_size=8192
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=671088640
orcl.__sga_target=989855744
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=251658240
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/flash_recovery_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=671088640
orcl.__sga_target=989855744
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=251658240
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/flash_recovery_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.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=orclXDB)'
#*.log_archive_dest_1='LOCATION=/home/oracle/arch'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=1655701504
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*.db_unique_name=uqn_orcl02
*.log_archive_config='DG_CONFIG=(uqn_orcl01,uqn_orcl02)'
*.log_archive_dest_1='LOCATION=/home/oracle/arch noreopen optional VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=uqn_orcl02'
*.log_archive_dest_2='SERVICE=orcl01 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=uqn_orcl01 ARCH SYNC REOPEN=10'
*.log_archive_dest_state_1=ENABLE
*.log_archive_dest_state_2=ENABLE
*.FAL_SERVER='orcl01'
*.FAL_CLIENT='orcl02'
*.STANDBY_FILE_MANAGEMENT='AUTO'
*.log_file_name_convert='/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/orcl/'
9.在oracle174中创建目录
[oracle@oracle174 ~]$ mkdir /home/oracle/arch
10.备份primary主库(oracle173上)
[oracle@oracle173 dbs]$ rman target/
Recovery Manager: Release 11.2.0.1.0 - Production on Mon Jun 23 22:06:34 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1378624651)
RMAN> run {
allocate channel d1 device type disk;
backup as compressed backupset
incremental level=0 format='/home/oracle/arch/inc0_%d_%T_%s_%p'
tag='inc0' channel=d1 database;
sql "alter system archive log current";
backup as compressed backupset
format=2> 3> 4> 5> 6> 7> 8> '/home/oracle/arch/arch_%d_%T_%s_%p'
tag='arch' channel=d1 archivelog all delete input;
backup as compressed backupset
format='/home/oracle/arch/ctl_%d_%T_%s_%p'
tag='ctl' channel=d1 current controlfile for standby reuse;
}
11.拷贝primary(oracle173)备份文件到standby(oracle174)
[oracle@oracle173 ~]$ cd /home/oracle/arch/
[oracle@oracle173 arch]$ scp * oracle174:/home/oracle/arch/
12. duplicate primary数据库上主库与备库防火墙要关闭
RMAN> connect auxiliary sys/sys_admin@orcl02
connected to auxiliary database: ORCL (not mounted)
RMAN> duplicate target database for standby nofilenamecheck;
13恢复standby数据库(oracle174)
SQL> recover managed standby database disconnect from session;
Media recovery complete.
14.standby数据库启动到open read only状态
SQL> recover managed standby database cancel;
Media recovery complete.
SQL> alter database open read only;
Database altered.
SQL> recover managed standby database disconnect from session;
Media recovery complete.
15.测试DataGuard
# primary数据库(oracle173)
SQL> alter system archive log current;
System altered.
#oracle174
16.通过命令查看是否有归档日志恢复
$ tail -f /u01/app/oracle/diag/rdbms/uqn_orcl02/orcl/trace/alert_orcl.log
17.使用LGWR进程进行primary和standby之间的归档日志传输
#添加standby logfile
standby 添加standby logfile
SQL> recover managed standby database cancel;
Media recovery complete.
SQL> alter database add standby logfile group 6 ('/u02/app/oracle/oradata/orcl/stb_redo01.dbf') size 50M reuse;
Database altered.
SQL> alter database add standby logfile group 7 ('/u02/app/oracle/oradata/orcl/stb_redo02.dbf') size 50M reuse;
Database altered.
SQL> alter database add standby logfile group 8 ('/u02/app/oracle/oradata/orcl/stb_redo03.dbf') size 50M reuse;
Database altered.
SQL> alter database add standby logfile group 9 ('/u02/app/oracle/oradata/orcl/stb_redo04.dbf') size 50M reuse;
Database altered.
#查看standby logfile
SQL> select * from v$standby_log;
18.primary 添加standby logfile
SQL> alter database add standby logfile group 6 ('/u02/app/oracle/oradata/orcl/stb_redo01.dbf') size 50M reuse;
Database altered.
SQL> alter database add standby logfile group 7 ('/u02/app/oracle/oradata/orcl/stb_redo02.dbf') size 50M reuse;
Database altered.
SQL> alter database add standby logfile group 8 ('/u02/app/oracle/oradata/orcl/stb_redo03.dbf') size 50M reuse;
Database altered.
SQL> alter database add standby logfile group 9 ('/u02/app/oracle/oradata/orcl/stb_redo04.dbf') size 50M reuse;
Database altered.
19.修改primary和standby的初始化参数log_archive_dest_2
#primary
[oracle@oracle173 arch]$ vi /u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora
------------------------------------------------------
*.log_archive_dest_2='SERVICE=orcl02 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=uqn_orcl02 LGWR SYNC REOPEN=10'
----------------------------------------------------------
#standby
[oracle@oracle174 arch]$ vi /u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora
------------------------------------------------------
*.log_archive_dest_2='SERVICE=orcl01 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=uqn_orcl01 LGWR SYNC REOPEN=10'
------------------------------------------------------
20.重启primary和standby数据库
#关闭
#primary (oracle173)
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
#standby (oracle174)
SQL> recover managed standby database cancel;
Media recovery complete.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
#启动
#primary (oracle173)
SQL> startup
ORACLE instance started.
Total System Global Area 1653518336 bytes
Fixed Size 2213896 bytes
Variable Size 956303352 bytes
Database Buffers 687865856 bytes
Redo Buffers 7135232 bytes
Database mounted.
Database opened.
#standby (oracle174)
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1653518336 bytes
Fixed Size 2213896 bytes
Variable Size 956303352 bytes
Database Buffers 687865856 bytes
Redo Buffers
SQL> alter database mount standby database;
Database altered.
SQL> alter database open read only;
Database altered.
SQL> recover managed standby database disconnect from session;
Media recovery complete.
21修改参数文件为spfile
创建spfile文件
#primary (oracle173)
SQL> create spfile from pfile;
File created.
#standby (oracle174)
SQL> create spfile from pfile;
File created.
22.重启primary和standby数据库
同上
####################################################################
#测试DataGuard数据
#primary
SQL> create table dg_test(sno number,sname varchar(20));
Table created.
SQL> insert into dg_test values(1,'DataGuard');
1 row created.
SQL> insert into dg_test values(2,'primary');
1 row created.
SQL> insert into dg_test values(3,'standby');
1 row created.
SQL> commit;
Commit complete.
SQL> alter system archive log current;
System altered.
#standby
SQL> select * from dg_test;
SNO SNAME
---------- --------------------
1 DataGuard
2 primary
3 standby