从oracle11g开始,支持windows与linux异构dg,同时也开时支持备节点只读打开。所以在企业中,可以实现读写分离,客户知道这个新特性后,要求我们帮他们部署一套这样的active dataguard,来分担他们生产库的压力。下面,我就把我的实施过程发布出来与大家共享!
1、安装操作系统及数据库软件
具体的安装、建库等操作,请参阅《DBA强化实战系列第一期:centos6.4安装oracle11.2.0.4单实例asm》。注意,建库,只需要在一台机器上建就可以了!
2、开始配置adg的准备工作
2.1主节点操作,配置归档
[oracle@mytest1 bin]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.4.0 Production on Thu Jan 2 16:08:29 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
配置强制归档,这是建dg必须的,因为在我们实际过程中,不允许有nologging的方式存在,这样会造成数据不一致
SQL> alter database force logging;
Database altered.
配置归档设置归档路径及格式
SQL> alter system set log_archive_format='%S_%t_%r.log' scope=spfile;
System altered.
SQL> alter system set log_archive_dest_state_1='ENABLE';
System altered.
SQL> alter system set log_archive_dest_1='location=+datadg';
System altered.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 2989854720 bytes
Fixed Size 2256912 bytes
Variable Size 822087664 bytes
Database Buffers 2147483648 bytes
Redo Buffers 18026496 bytes
Database mounted.
SQL> !lsnrctl stop
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 02-JAN-2014 16:11:59
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
The command completed successfully
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
--注意,到这一步,主节点的归档就基本上配置完成了。数据库重启后,注册一下监听
SQL> alter system register;
System altered.
2.2主节点操作,在线备份数据库,参数文件等,并传输到备节点
本次备份的时候,把数据库及控制文件也进行了备份,注意control的选择为standby的方式了!
[oracle@mytest1 bin]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jan 2 16:26:36 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: oradgdb (DBID=3596765127)
RMAN> backup as compressed backupset full database include current controlfile for standby format '/u02/dbfull_%T_%s_%p.bak' plus archivelog format '/u02/archfull_%T_%s_%p.bak';
Starting backup at 2012-03-05 16:26:43
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=45 device type=DISK
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=5 RECID=1 STAMP=835806404
channel ORA_DISK_1: starting piece 1 at 2012-03-05 16:26:45
channel ORA_DISK_1: finished piece 1 at 2012-03-05 16:26:46
piece handle=/u02/archfull_20140102_1_1.bak tag=TAG20140102T162645 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2012-03-05 16:26:46
Starting backup at 2012-03-05 16:26:46
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DATADG/oradgdb/datafile/system.256.835804411
input datafile file number=00002 name=+DATADG/oradgdb/datafile/sysaux.257.835804411
input datafile file number=00003 name=+DATADG/oradgdb/datafile/undotbs1.258.835804411
input datafile file number=00004 name=+DATADG/oradgdb/datafile/users.259.835804411
channel ORA_DISK_1: starting piece 1 at 2012-03-05 16:26:46
channel ORA_DISK_1: finished piece 1 at 2012-03-05 16:27:21
piece handle=/u02/dbfull_20140102_2_1.bak tag=TAG20140102T162646 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including standby control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 2012-03-05 16:27:23
channel ORA_DISK_1: finished piece 1 at 2012-03-05 16:27:24
piece handle=/u02/dbfull_20140102_3_1.bak tag=TAG20140102T162646 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2012-03-05 16:27:24
Starting backup at 2012-03-05 16:27:24
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=6 RECID=2 STAMP=835806444
channel ORA_DISK_1: starting piece 1 at 2012-03-05 16:27:24
channel ORA_DISK_1: finished piece 1 at 2012-03-05 16:27:25
piece handle=/u02/archfull_20140102_4_1.bak tag=TAG20140102T162724 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2012-03-05 16:27:25
RMAN> quit
Recovery Manager complete.
[oracle@mytest1 bin]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.4.0 Production on Thu Jan 2 16:35:02 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
--创建standby的参数文件
SQL> create pfile='/u02/standby.ora' from spfile;
File created.
[oracle@mytest1 u02]$ scp standby.ora 10.10.1.52:/u02
[email protected]'s password:
standby.ora 100% 772 0.8KB/s 00:00
[oracle@mytest1 u02]$ cd $ORACLE_HOME
[oracle@mytest1 db1]$ cd dbs
[oracle@mytest1 dbs]$ ls -a
. hc_oradgdb.dat initoradgdb.ora orapworadgdb
.. init.ora lkoradgdb snapcf_oradgdb.f
--创建完成后,将$ORACLE_HOME/dbs/的所有文件,以及刚才备份的内容、参数文件都传到备节点上!
[oracle@mytest1 dbs]$ pwd
/u01/app/oracle/product/11.2.0/db1/dbs
[oracle@mytest1 dbs]$ scp * 10.10.1.52:/u01/app/oracle/product/11.2.0/db1/dbs/
[email protected]'s password:
hc_oradgdb.dat 100% 1544 1.5KB/s 00:00
init.ora 100% 2851 2.8KB/s 00:00
initoradgdb.ora 100% 41 0.0KB/s 00:00
lkoradgdb 100% 24 0.0KB/s 00:00
orapworadgdb 100% 1536 1.5KB/s 00:00
snapcf_oradgdb.f 100% 9520KB 9.3MB/s 00:00
[oracle@mytest1 u02]$ scp * 10.10.1.52:/u02
[email protected]'s password:
archfull_20140102_1_1.bak 100% 5679KB 5.6MB/s 00:00
archfull_20140102_4_1.bak 100% 3072 3.0KB/s 00:00
dbfull_20140102_2_1.bak 100% 278MB 69.5MB/s 00:04
dbfull_20140102_3_1.bak 100% 1072KB 1.1MB/s 00:00
standby.ora 100% 772 0.8KB/s 00:00
输入密码等,很快传完
3、备节点操作,修改参数文件等
--修改从主节点传过来的参数文件
[oracle@mytest2 u02]$ vi standby.ora
*.fal_client='prdb'
*.fal_server='stdb'
*.standby_file_management='AUTO'
注意,这里的prdb,stdb,这个配置是对应tnsnames里面配置的别名
加入以上3行,即可。如果文件路径不同,还需要加入以下参数
*.db_file_name_convert
*.log_file_name_convert
我本次都使用了相同的路径,数据使用的是datadg。
--创建备节点参数文件
[oracle@mytest2 u02]$ export ORACLE_HOME=/u01/app/grid/product/11.2.0/crs
[oracle@mytest2 u02]$ export ORACLE_SID=+ASM
[oracle@mytest2 u02]$ cd /u01/app/grid/product/11.2.0/crs/bin
[oracle@mytest2 bin]$ ./asmcmd
ASMCMD> cd DATADG
ASMCMD> mkdir oradgdb
然后退出后
[oracle@mytest2 u02]$ export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db1
[oracle@mytest2 u02]$ export ORACLE_SID=oradgdb
[oracle@mytest2 u02]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.4.0 Production on Thu Jan 2 16:08:29 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
SQL> create spfile='+DATADG/oradgdb/spfileoradgdb.ora' from pfile='/u02/standby.ora';
这个路径可以从主节查看show parameter spfile。
说明:由于我安装grid以及oracle rdbms均是采用的oracle用户,所以在操作过程中需要切换实例等
4、编辑主备节点的tnsnames.ora,listener.ora,sqlnet.ora
注意,这个操作在主备节点均要进行
--编辑tnsnames.ora,sqlnet.ora
[oracle@mytest2 admin]$ vi tnsnames.ora
prdb =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.1.51)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = oradgdb)
)
)
stdb =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.1.52)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = oradgdb)
)
)
sqlnet.ora进行如下编辑即可:
MES.DIRECTORY_PATH= (TNSNAMES)
说明,tnsnames.ora,sqlnet.ora主备节点相同,编辑好后,直接相互拷贝就行了!
注意,在这里备节点的配置: SID = oradgdb ,有朋友在这里卡住了,因为在恢复的过程中,备节点只能到nomount状态,只能用sid连接,否则过不了!
--编辑监听
主节点监听:
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.1.51)(PORT = 1521))
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = oradgdb)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db1)
(SID_NAME = oradgdb)
)
)
备节点监听:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = oradgdb)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db1)
(SID_NAME = oradgdb)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.1.52)(PORT = 1521))
)
)
)
5、开始还原操作
还原操作在主节点进行操作,通过连接备节点的到开始状态的实例进行
5.1备节点启动到nomount状态
SQL> startup nomount
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORA-09925: Unable to create audit trail file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 9925
由于oracle11g是默认开启了audit功能,所以要先建路径
[oracle@mytest2 bin]$ mkdir -p /u01/app/oracle/admin/oradgdb/adump
[oracle@mytest2 bin]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.4.0 Production on Thu Jan 2 17:19:51 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
SQL> startup nomount;
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORA-01081: cannot start already-running ORACLE - shut it down first
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup nomount;
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORACLE instance started.
Total System Global Area 2989854720 bytes
Fixed Size 2256912 bytes
Variable Size 822087664 bytes
Database Buffers 2147483648 bytes
Redo Buffers 18026496 bytes
到此,备节点已经启动到nomount状态了,可以在主节点操作还原了!
另外,特别注意,在备节点、主节点注意关闭防火墙,否则在连接的时候会报以下错误!
RMAN> connect auxiliary sys/Root123@stdb;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-04006: error from auxiliary database: ORA-12543: TNS:destination host unreachable
同时,监听也要注意,我们使用crs_stop,停掉监听,用lsnrctl 开启!
5.2主节点操作还原数据库到备节点
[oracle@mytest1 bin]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jan 2 20:30:04 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: oradgdb (DBID=3596765127)
RMAN> connect auxiliary sys/Root123@stdb;
connected to auxiliary database: oradgdb (DBID=3596765127)
RMAN> duplicate target database for standby nofilenamecheck
Starting Duplicate Db at 2012-03-05 18:02:38
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=23 device type=DISK
contents of Memory Script:
{
sql clone "alter system set control_files =
''+DATADG/oradgdb/controlfile/current.257.835812159'' comment=
''Set by RMAN'' scope=spfile";
restore clone standby controlfile;
}
executing Memory Script
sql statement: alter system set control_files = ''+DATADG/oradgdb/controlfile/current.257.835812159'' comment= ''Set by RMAN'' scope=spfile
Starting restore at 2012-03-05 18:02:39
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u02/dbfull_20140102_3_1.bak
channel ORA_AUX_DISK_1: piece handle=/u02/dbfull_20140102_3_1.bak tag=TAG20140102T162646
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=+DATADG/oradgdb/controlfile/current.258.835812161
Finished restore at 2012-03-05 18:02:41
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 clone tempfile 1 to new;
switch clone tempfile all;
set newname for clone datafile 1 to new;
set newname for clone datafile 2 to new;
set newname for clone datafile 3 to new;
set newname for clone datafile 4 to new;
restore
clone database
;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to +DATADG in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 2012-03-05 18:02:47
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to +DATADG
channel ORA_AUX_DISK_1: restoring datafile 00002 to +DATADG
channel ORA_AUX_DISK_1: restoring datafile 00003 to +DATADG
channel ORA_AUX_DISK_1: restoring datafile 00004 to +DATADG
channel ORA_AUX_DISK_1: reading from backup piece /u02/dbfull_20140102_2_1.bak
channel ORA_AUX_DISK_1: piece handle=/u02/dbfull_20140102_2_1.bak tag=TAG20140102T162646
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 2012-03-05 18:03:43
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=835812223 file name=+DATADG/oradgdb/datafile/system.259.835812169
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=835812223 file name=+DATADG/oradgdb/datafile/sysaux.260.835812169
datafile 3 switched to datafile copy
input datafile copy RECID=7 STAMP=835812223 file name=+DATADG/oradgdb/datafile/undotbs1.261.835812169
datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=835812223 file name=+DATADG/oradgdb/datafile/users.262.835812169
Finished Duplicate Db at 2012-03-05 18:03:44
在这里,可以看到还原已经完成,并且,从备节点上查看,数据库已经到mount状态了
--在备节点查看,并执行还原
SQL> select status from v$instance;
STATUS
------------
MOUNTED
SQL> recover managed standby database disconnect;
6、在备节点添加standby log
SQL> alter database add standby logfile group 5 size 50m;
Database altered.
SQL> alter database add standby logfile group 6 size 50m;
Database altered.
SQL> alter database add standby logfile group 7 size 50m;
Database altered.
7、参数调整
--主节点操作
SQL> alter system set log_archive_dest_state_2='ENABLE';
System altered.
SQL> alter system set ARCHIVE_LAG_TARGET=3600 scope=both;
System altered.
日志的切换时间为3600秒,即一个小时,这个可以根据需要来调整
SQL> alter system set STANDBY_FILE_MANAGEMENT=AUTO scope=both;
System altered.
主节点增加文件后,备节也主动增加文件,这个要注意!
SQL> alter system set log_archive_dest_2='SERVICE=stdb lgwr sync valid_for=(online_logfile,primary_role) db_unique_name=stdb';
System altered.
注意传输模式的调整,这个根据安全级别来定
8、将备节点启动到active状态
SQL> startup mount;
Total System Global Area 2989854720 bytes
Fixed Size 2256912 bytes
Variable Size 822087664 bytes
Database Buffers 2147483648 bytes
Redo Buffers 18026496 bytes
Database mounted.
SQL> select open_mode,database_role,db_unique_name from v$database;
OPEN_MODE DATABASE_ROLE DB_UNIQUE_NAME
-------------------- ---------------- ------------------------------
MOUNTED PHYSICAL STANDBY oradgdb
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
SQL> select open_mode,database_role,db_unique_name from v$database;
OPEN_MODE DATABASE_ROLE DB_UNIQUE_NAME
-------------------- ---------------- ------------------------------
READ ONLY WITH APPLY PHYSICAL STANDBY oradgdb
可以看到,数据库已经以只读的方式打开了
SQL> select status from v$standby_log;
STATUS
----------
UNASSIGNED
UNASSIGNED
UNASSIGNED
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
+DATADG/oradgdb/onlinelog/group_3.265.835812225
+DATADG/oradgdb/onlinelog/group_2.264.835812223
+DATADG/oradgdb/onlinelog/group_1.263.835812223
+DATADG/oradgdb/onlinelog/group_5.266.835812379
+DATADG/oradgdb/onlinelog/group_6.267.835812395
+DATADG/oradgdb/onlinelog/group_7.268.835812403
9、验证数据
主节点操作
SQL> create table mytest as select * from dba_users;
Table created.
备节点查询看一下
SQL> select count(*) from mytest;
COUNT(*)
----------
30
证明数据已经传过来了
主备节点的日志情况
主节点
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination +DATADG
Oldest online log sequence 20
Next log sequence to archive 22
Current log sequence 22
备节点:
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination +DATADG
Oldest online log sequence 20
Next log sequence to archive 0
Current log sequence 22
完全一致。我们的设置是lgwr的同步模式!
至此配置全部完成
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29371470/viewspace-1066607/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29371470/viewspace-1066607/