- 环境描述
本文讨论的内容建立在两台redhat5.3 X86_64服务器上,数据库版本为oracle 10.2.0.4。
两个节点都安装了Oracle Database Server,并在主库服务器上创建完DB_NAME=gridctl的数据库,备库服务器只安装了数据库软件,没有创建数据库实例,具体的操作系统版本和数据库版本如下:
#uname -a
Linux standbydb 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
[@more@]主库Primary db server:
hostname: primarydb
ip: 168.10.13.192
sid: gridctl
datafile directory: /oradata/gridctl/
备库Standby db server:
hostname:standbydb
ip: 168.10.13.193
sid: newgridctl
Datafile directory:/oradata/newgridctl/
Two nodes:
#more /etc/hosts
168.10.13.192 primarydb
168.10.13.193 standbydb
DB_NAME=gridctl
ORACLE_HOME:/oracle/product/10.2.0/db_1
Archivelog_dest:/oradata/archivelog/primary_arc
Standby_archivelog_dest:/oradata/archivelog/newstandby_arc
- 准备工作
准备工作主要包括主、备数据库的相关配置文件(SPFILE,LISTENER.ORA,TNSNAMES.ORA,ORAPW$ORACLE_SID)的创建或者配置;相关dump文件路径和数据文件路径的创建;主库rman全库备份集生成和standby controlfile生成。
2.1 配置主库服务 器的spfile,备库服务器的spfile
如果主库与备库的数据文件,redo文件的路径不相同,需要在备库服务器上设置下面三个参数:
*.db_file_name_convert='/oradata/gridctl/','/oradata/newgridctl/'
*.log_file_name_convert='/oradata/gridctl/','/oradata/newgridctl/'
*.standby_file_management=AUTO
SQL>alter system set db_file_name_convert='/oradata/gridctl/','/oradata/newgridctl/' scope=spfile;
SQL>alter system set log_file_name_convert='/oradata/gridctl/','/oradata/newgridctl/' scope=spfile;
SQL>alter system set standby_file_management=AUTO scope=spfile;
[oracle@standbydb dbs]$ more initnewgridctl.ora
*.audit_file_dest='/oracle/admin/newgridctl/adump'
*.background_dump_dest='/oracle/admin/newgridctl/bdump'
*.control_files='/oradata/newgridctl/newstd_control.dbf'
*.core_dump_dest='/oracle/admin/newgridctl/cdump'
*.db_create_file_dest='/oradata/newgridctl'
*.db_name='gridctl'
*.log_archive_dest_1='LOCATION=/oradata/archivelog/primary_arc'
*.log_archive_dest_2='service=standby mandatory reopen=60'
*.standby_archive_dest='/oradata/archivelog/newstandby_arc'
*.user_dump_dest='/oracle/admin/newgridctl/udump'
。。。。。。
*.db_file_name_convert='/oradata/gridctl/','/oradata/newgridctl/'
*.log_file_name_convert='/oradata/gridctl/','/oradata/newgridctl/'
*.standby_file_management=AUTO
。。。。。。
2.2 配置主库服务器、备库服务器的tnsnames.ora,listener.ora
两个节点的tnsnames.ora的内容都包含下面的内容:
[oracle@ admin]$ more tnsnames.ora
PRIMARY=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = primarydb )(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = gridctl)
)
)
NEWSTANDBY=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = standbydb )(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = newgridctl)
)
)
两个节点的listener.ora的内容都包括下面的内容:
[oracle@primarydb admin]$ more listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = gridctl)
(ORACLE_HOME = /oracle/product/10.2.0/db_1)
(SID_NAME = gridctl)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = primarydb)(PORT = 1521))
)
[oracle@standbydb admin]$ more listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME =newgridctl)
(ORACLE_HOME = /oracle/product/10.2.0/db_1)
(SID_NAME = newgridctl)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = standbydb)(PORT = 1521))
)
2.1,2.2的内容请参看我的博客文章"Step Configure DataGuard (10g) Physical Standby Database On Linux X86_64(1/2)",网址为:http://djb1008.itpub.net/post/42280/504822
2.3 在备库上创建相关数据文件路径,dump路径,将备库启动到nomount状态
[oracle@standbydb ~]$ echo $ORACLE_SID
newgridctl
创建实例newgridctl的dump文件存放所需目录
[oracle@standbydb admin]$ cd /oracle/admin
[oracle@standbydb admin]$ mkdir newgridctl
[oracle@standbydb admin]$ cd newgridctl
[oracle@standbydb newgridctl]$ mkdir adump bdump cdump udump
创建备库服务器的数据库数据文件存放目录
[oracle@standbydb oradata]$ cd /oradata
[oracle@standbydb oradata]$ mkdir newgridctl
启动备库服务器的数据库到nomount状态
[oracle@standbydb newgridctl]$ sqlplus / as sysdba
Connected to an idle instance.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 1073741824 bytes
Fixed Size 2089472 bytes
Variable Size 545263104 bytes
Database Buffers 524288000 bytes
Redo Buffers 2101248 bytes
2.4 在主库使用RMAN 创建一个数据库备份集
[oracle@primarydb ~]$ rman target /
RMAN> run{
allocate channel d1 type disk;
backup full database format '/oradata/db_%U.bak'
plus archivelog format '/oradata/arc_%U.bak';
Sql 'alter system archive log current';
release channel d1;}
Starting backup at 07-SEP-10
input archive log thread=1 sequence=207 recid=1 stamp=728673992
。。。。。。
input archive log thread=1 sequence=243 recid=59 stamp=729080164
。。。。。。
channel d1: specifying datafile(s) in backupset
input datafile fno=00001 name=/oradata/gridctl/system01.dbf
。。。。。。
input datafile fno=00006 name=/oradata/gridctl/mgmt_ecm_depot1.dbf
piece handle=/oradata/db_0aln9qqi_1_1.bak tag=TAG20100907T105819 comment=NONE
channel d1: backup set complete, elapsed time: 00:00:02
。。。。。。
released channel: d1
2.5 使用rman的copy命令创建一个standby control file
[oracle@primarydb ~]$ rman target /
RMAN> copy current controlfile for standby to '/oradata/newstd_control.ctl';
。。。。。。
output filename=/oradata/newstd_control.ctl tag=TAG20100907T105116 recid=2 stamp=729082276
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 07-SEP-10
2.6 将主库服务器的备份集文件,standby control file通过ftp复制到备库服务器。
Ftp 完成后的结果如下:
[oracle@standbydb oradata]$ ls -lt
total 1812612
-rw-r--r-- 1 oracle oinstall 6930432 Sep 7 11:03 newstd_control.ctl
-rw-r--r-- 1 oracle oinstall 7012352 Sep 7 11:03 db_0aln9qqi_1_1.bak
-rw-r--r-- 1 oracle oinstall 581025792 Sep 7 11:02 db_09ln9qqb_1_1.bak
-rw-r--r-- 1 oracle oinstall 629637120 Sep 7 11:02 db_04ln9q5l_1_1.bak
-rw-r--r-- 1 oracle oinstall 629637120 Sep 7 11:02 arc_08ln9qpr_1_1.bak
- 执行DUPLICATE命令,创建一个不同目录结构的standby db
3.1 在主库上执行DUPLICATE命令前的确认工作
在这里再次申明一下,执行duplicate操作前,需要检查几点内容,如下所述:
Oracle在duplcate操作时有点奇怪,怪在那里呢?
1).要在主库上执行rman的登录操作,并且auxiliary连接到备库.
$rman target / auxiliary sys/pwdofsys@standby
2).要在主库的rman环境里执行duplicate 命令.
RMAN>run{duplicate target database for standby;}
3). rman的备份集文件需要拷贝到备机的相同目录(不使用主库服务器的备份集文件)
4).文件名称或者文件路径的修改,需要在备库上设置三个convert参数,主库不需要设置这些参数。
以上的这4怪,恰恰是rman创建standby db的4个陷阱,跳过这四个陷阱,duplicate就顺很多。
3.2 在主库上执行DUPLICATE命令,完成备库的创建工作
下面就开始执行DUPLICATE命令,进行备库的创建工作。
[oracle@primarydb oradata]$ rman target / auxiliary sys/aidu2010@newstandby
connected to target database: GRIDCTL (DBID=3373887875)
connected to auxiliary database: GRIDCTL (not mounted)
RMAN> run{
2> duplicate target database for standby;
3> }
Starting Duplicate Db at 07-SEP-10
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=430 devtype=DISK
contents of Memory Script:
{
restore clone standby controlfile;
sql clone 'alter database mount standby database';
}
executing Memory Script
Starting restore at 07-SEP-10
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: copied control file copy
input filename=/oradata/newstd_control.ctl
output filename=/oradata/newgridctl/newstd_control.ctl
Finished restore at 07-SEP-10
sql statement: alter database mount standby database
released channel: ORA_AUX_DISK_1
contents of Memory Script:
{
set newname for tempfile 1 to
"/oradata/newgridctl/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/oradata/newgridctl/system01.dbf";
set newname for datafile 2 to
"/oradata/newgridctl/undotbs01.dbf";
set newname for datafile 3 to
"/oradata/newgridctl/sysaux01.dbf";
set newname for datafile 4 to
"/oradata/newgridctl/users01.dbf";
set newname for datafile 5 to
"/oradata/newgridctl/mgmt.dbf";
set newname for datafile 6 to
"/oradata/newgridctl/mgmt_ecm_depot1.dbf";
restore
check readonly
clone database
;
}
executing Memory Script
executing command: SET NEWNAME
renamed temporary file 1 to /oradata/newgridctl/temp01.dbf in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 07-SEP-10
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=430 devtype=DISK
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /oradata/newgridctl/system01.dbf
restoring datafile 00002 to /oradata/newgridctl/undotbs01.dbf
restoring datafile 00003 to /oradata/newgridctl/sysaux01.dbf
restoring datafile 00004 to /oradata/newgridctl/users01.dbf
restoring datafile 00005 to /oradata/newgridctl/mgmt.dbf
restoring datafile 00006 to /oradata/newgridctl/mgmt_ecm_depot1.dbf
channel ORA_AUX_DISK_1: reading from backup piece /oradata/db_0dlnaesf_1_1.bak
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/oradata/db_0dlnaesf_1_1.bak tag=TAG20100907T164047
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 07-SEP-10
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy recid=12 stamp=729106481 filename=/oradata/newgridctl/system01.dbf
datafile 2 switched to datafile copy
input datafile copy recid=13 stamp=729106481 filename=/oradata/newgridctl/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=14 stamp=729106481 filename=/oradata/newgridctl/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=15 stamp=729106481 filename=/oradata/newgridctl/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=16 stamp=729106481 filename=/oradata/newgridctl/mgmt.dbf
datafile 6 switched to datafile copy
input datafile copy recid=17 stamp=729106481 filename=/oradata/newgridctl/mgmt_ecm_depot1.dbf
Finished Duplicate Db at 07-SEP-10
注意: duplicate命令是在主库上运行的,而备份集介质需要从备库的相同目录(/oradata)取。
3.3 检查备库数据库的状态和角色
[oracle@standbydb ~]$ sqlplus / as sysdba
SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
---------- ----------------
MOUNTED PHYSICAL STANDBY
3.4 在备库服务器上执行日志文件的介质恢复,与主库的运行状态同步。
SQL> alter database recover managed standby database disconnect from session;
SQL>!
[oracle@standbydb ~]$tail -f alert_newgridctl.log
Wed Sep 8 08:07:07 2010
Media Recovery Log /oradata/archivelog/newstandby_arc1_254_724504451.dbf
Media Recovery Log /oradata/archivelog/newstandby_arc1_255_724504451.dbf
Media Recovery Log /oradata/archivelog/newstandby_arc1_256_724504451.dbf
Media Recovery Log /oradata/archivelog/newstandby_arc1_257_724504451.dbf
Identified End-Of-Redo for thread 1 sequence 257
Wed Sep 8 08:07:07 2010
Media Recovery End-Of-Redo indicator encountered
Wed Sep 8 08:07:07 2010
Media Recovery Applied until change 9886776
Wed Sep 8 08:07:07 2010
MRP0: Media Recovery Complete: End-Of-REDO (newgridctl)
Resetting standby activation ID 3378482509 (0xc95f8d4d)
Wed Sep 8 08:07:08 2010
MRP0: Background Media Recovery process shutdown (newgridctl)
3.5 主、备库归档日志切换与应用
主库先进行日志切换
[oracle@primarydb admin]$ sqlplus / as sysdba
SQL> alter system switch logfile;
System altered.
备库的alert日志的应用情况:
[oracle@standbydb bdump]$ tail -f alert_newgridctl.log
Thu Sep 9 10:04:41 2010
RFS[1]: Archived Log: '/oradata/archivelog/newstandby_arc/1_267_724504451.dbf'
Thu Sep 9 10:04:45 2010
Media Recovery Log /oradata/archivelog/newstandby_arc/1_267_724504451.dbf
Media Recovery Waiting for thread 1 sequence 268
查询备库数据库中的日志应用的情况:
[oracle@standbydb oradata]$ sqlplus / as sysdba
SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
SEQUENCE# FIRST_TIM NEXT_TIME APP
---------- --------- --------- ---
267 09-SEP-10 09-SEP-10 YES
1 rows selected.
到此已经使用rman在线(主库数据库没有停机,也不需要停机)创建了一个备库,并且实现了与主库的同步。本文对主备库的切换不做描述,主备库的切换操作请参看我的另外一遍文章“Step By Step Configure DataGuard (10g) Physical Standby Database On Linux X86_64(2/2) ”,网址为:http://djb1008.itpub.net/post/42280/504948
注: 本文针对的是主备库数据文件不同目录结构,需要设置convert参数;如果主备库的数据文件的目录结构相同,则跳过2.1节的设置convert等参数的环节,其它的照旧执行就可以了。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/32980/viewspace-1038109/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/32980/viewspace-1038109/