分类: Oracle
2012-01-31 16:48:30
Oracle 官网有关单实例迁移到RAC的一个步骤说明:
How to Convert 10g Single-Instance database to 10g RAC using Manual Conversion procedure [ID 747457.1]
http://blog.csdn.net/tianlesoftware/archive/2010/12/09/6065903.aspx
RMAN 备份异机恢复 并创建新DBID
http://blog.csdn.net/tianlesoftware/archive/2011/03/11/6240983.aspx
一. 大致操作步骤如下:
1. 安装Clusterware 和 ASM 实例
2. 备份源库,并将备份集copy到rac 节点上
3. 在RAC 上还原并修改初始化参数文件,还原控制文件和数据文件
4. 增加undo 表空间和redo log 线程组,创建密钥文件
5. 配置RAC监听
6. 将数据库等资源添加到CRS
注意: 迁移的2个db版本版本要一致。包括小版本。 比如10.2.0.4.0.
我这个测试的时候是从10.2.0.1.0 迁移到10.2.0.4.0. 结果在open resetlogs的时候报错了,必须要先升级后,才能打开。
Redhat 5.4 Orcle RAC 数据库 从10.2.0.1升级到 10.2.0.4
http://blog.csdn.net/tianlesoftware/archive/2010/09/16/5888069.aspx
二. 具体操作步骤
2.1 安装Clusterware 和ASM 实例
这个参考Blog:
Redhat 5.4 Oracle 10g RAC Openfiler+Multipath + RAW+ ASM 安装文档
http://blog.csdn.net/tianlesoftware/archive/2010/12/01/6048792.aspx
安装之后的进程如下:
[oracle@rac1 u01]$ sh crs_stat.sh
Name Target State Host
------------------------------ ---------- --------- -------
ora.rac1.ASM1.asm ONLINE ONLINE rac1
ora.rac1.gsd ONLINE ONLINE rac1
ora.rac1.ons ONLINE ONLINE rac1
ora.rac1.vip ONLINE ONLINE rac1
ora.rac2.ASM2.asm ONLINE ONLINE rac2
ora.rac2.gsd ONLINE ONLINE rac2
ora.rac2.ons ONLINE ONLINE rac2
ora.rac2.vip ONLINE ONLINE rac2
2.2 在源库用RMAN 备份,并将备份文件copy到rac上
相关备份脚本,参考Blog:
Linux 平台下 RMAN 全备 和 增量备份 shell 脚本
http://blog.csdn.net/tianlesoftware/archive/2010/07/16/5740630.aspx
Nocatalog 下的RMAN 增量备份 shell脚本
http://blog.csdn.net/tianlesoftware/archive/2011/01/26/6164931.aspx
源库实例名:anqing,为了确认迁移成功,我们现在源库上创建一个表dave,并插入一条记录。
SQL> create table dave(id number,hometown varchar2(100));
Table created.
SQL> insert into dave values(1,'');
1 row created.
SQL> commit;
Commit complete.
用nocatalog 方式进行0级备份。
备份之后的信息如下:
RMAN> list backup summary;
using target database control file instead of recovery catalog
List of Backups
===============
Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
1 B 0 A DISK 23-MAY-12 1 1 NO ANQING_LEV0
2 B 0 A DISK 23-MAY-12 1 1 NO ANQING_LEV0
5 B 0 A DISK 23-MAY-12 1 1 NO ANQING_LEV0
6 B 0 A DISK 23-MAY-12 1 1 NO ANQING_LEV0
7 B A A DISK 23-MAY-12 1 1 NO ARC_BAK
8 B A A DISK 23-MAY-12 1 1 NO ARC_BAK
9 B F A DISK 23-MAY-12 1 1 NO BAK_CTLFILE
10 B F A DISK 23-MAY-12 1 1 NO SPFILE
注:我虚拟机上的系统时间没改,所以这里显示的时间是2012年5月23日。
将备份文件SCP 到RAC 服务器:
[oracle@singledb backup]$ scp * 192.168.2.42:/u01/backup
oracle@192.168.2.42's password:
anqing_lev0_01nbo3f3_1_1_20120523 100% 350MB 1.8MB/s 03:14
anqing_lev0_02nbo3f3_1_1_20120523 100% 142MB 2.7MB/s 00:53
anqing_lev0_03nbo3f3_1_1_20120523 100% 21MB 3.1MB/s 00:07
anqing_lev0_04nbo3f4_1_1_20120523 100% 376KB 376.0KB/s 00:00
anqing_spfile_0anbo3jl_1_1_20120523 100% 96KB 96.0KB/s 00:00
arch_07nbo3je_1_1_20120523 100% 28MB 3.1MB/s 00:09
arch_08nbo3je_1_1_20120523 100% 2560 2.5KB/s 00:00
ctl_file_09nbo3jk_1_1_20120523 100% 6944KB 3.4MB/s 00:02
2.3 还原并修改初始化文件
2.3.1 还原spfile 到pfile
[oracle@rac1 ~]$ export ORACLE_SID=anqing1
[oracle@rac1 ~]$ rman target /
Recovery Manager: Release 10.2.0.4.0 - Production on Wed May 18 22:54:27 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database (not started)
RMAN> startup nomount
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initanqing1.ora'
starting Oracle instance without parameter file for retrival of spfile
Oracle instance started
Total System Global Area 159383552 bytes
Fixed Size 1266344 bytes
Variable Size 58723672 bytes
Database Buffers 96468992 bytes
Redo Buffers 2924544 bytes
RMAN> restore spfile to pfile '/u01/app/oracle/product/10.2.0/db_1/dbs/initanqing1.ora'
2> from '/u01/backup/anqing_spfile_0anbo3jl_1_1_20120523';
Starting restore at 18-MAY-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=33 devtype=DISK
channel ORA_DISK_1: autobackup found: /u01/backup/anqing_spfile_0anbo3jl_1_1_20120523
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 18-MAY-11
RMAN>
看一下我们刚才恢复的参数文件:
[oracle@rac1 backup]$ cd /u01/app/oracle/product/10.2.0/db_1/dbs/
[oracle@rac1 dbs]$
[oracle@rac1 dbs]$ ls
ab_+ASM1.dat hc_anqing.dat hc_dave1.dat initanqing.ora init.ora orapw+ASM1
ab_+ASM2.dat hc_+ASM1.dat hc_rac1.dat init+ASM1.ora init.ora.4122011215823 snapcf_dave1.f
core_10447 hc_+ASM2.dat hc_rac2.dat initdw.ora initrac1.ora spfilerac1.ora
[oracle@rac1 dbs]$ cat initanqing.ora
anqing.__db_cache_size=96468992
anqing.__java_pool_size=4194304
anqing.__large_pool_size=4194304
anqing.__shared_pool_size=58720256
anqing.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/anqing/adump'
*.background_dump_dest='/u01/app/oracle/admin/anqing/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/u01/app/oracle/oradata/anqing/control01.ctl','/u01/app/oracle/oradata/anqing/control02.ctl','/u01/app/oracle/oradata/anqing/control03.ctl'
*.core_dump_dest='/u01/app/oracle/admin/anqing/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='anqing'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=anqingXDB)'
*.job_queue_processes=10
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.pga_aggregate_target=16777216
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=167772160
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/anqing/udump'
这里面都是单实例的参数,我们需要把这个改成RAC的参数。
2.3.2 查看ASM 实例的相关目录信息
[oracle@rac1 ~]$ export ORACLE_SID=+ASM1
[oracle@rac1 ~]$ sqlplus / as sysdba;
SQL*Plus: Release 10.2.0.4.0 - Production on Wed May 18 23:09:32 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
SYS@+ASM1(rac1)> col state format a10
SYS@+ASM1(rac1)> col name format a15
SYS@+ASM1(rac1)> col failgroup format a20
SYS@+ASM1(rac1)> set line 200
SYS@+ASM1(rac1)> select state,redundancy,total_mb,free_mb,name,failgroup from v$asm_disk;
STATE REDUNDA TOTAL_MB FREE_MB NAME FAILGROUP
---------- ------- ---------- ---------- --------------- --------------------
NORMAL UNKNOWN 11993 10088 DATA DATA
NORMAL UNKNOWN 7993 38 FRA_0000 FRA_0000
SYS@+ASM1(rac1)> select group_number,name,state,type,total_mb,free_mb,unbalanced from v$asm_diskgroup;
GROUP_NUMBER NAME STATE TYPE TOTAL_MB FREE_MB U
------------ --------------- ---------- ------ ---------- ---------- -
1 DATA MOUNTED EXTERN 11993 10088 N
2 FRA MOUNTED EXTERN 7993 38 N
使用ASMCMD命令:
[oracle@rac1 ~]$ export ORACLE_SID=+ASM1
[oracle@rac1 ~]$ asmcmd
ASMCMD> help
asmcmd [-p] [command]
The environment variables ORACLE_HOME and ORACLE_SID determine the
instance to which the program connects, and ASMCMD establishes a
bequeath connection to it, in the same manner as a SQLPLUS / AS
SYSDBA. The user must be a member of the SYSDBA group.
Specifying the -p option allows the current directory to be displayed
in the command prompt, like so:
ASMCMD [+DATAFILE/ORCL/CONTROLFILE] >
[command] specifies one of the following commands, along with its
parameters.
Type "help [command]" to get help on a specific ASMCMD command.
commands:
--------
cd
du
find
help
ls
lsct
lsdg
mkalias
mkdir
pwd
rm
rmalias
ASMCMD> ls
DATA/
FRA/
-- 这个是我们的两个磁盘组
ASMCMD> cd DATA
ASMCMD> ls
DAVE/
DB_UNKNOWN/
RAC/
-- 每个实例都对应一个目录,如果我们在创建参数的时候,没有这个目录,可以手工的先创建一下这个目录
ASMCMD> cd ..
ASMCMD> ls
DATA/
FRA/
ASMCMD> cd FRA
ASMCMD> ls
DAVE/
RAC/
ASMCMD>
2.3.3 修改初始话参数
注意事项:
(1)RMAN 异机恢复的db_name 必须和备份的一致,如果说想改成其他名称,可以等还原之后,在用nid 命令修改。
(2)控制文件需要指定到共享设备上
(3)检查audit_file_dest,background_dump_dest, core_dump_dest,log_archive_dest_1,user_dump_dest等参数的位置。 如果2个节点和共享位置没有对应的目录,先把目录建好。
[oracle@rac1 admin]$ pwd
/u01/app/oracle/admin
[oracle@rac1 admin]$ mkdir anqing
[oracle@rac1 admin]$ ls
anqing +ASM rac
[oracle@rac1 admin]$ cd anqing
[oracle@rac1 anqing]$ mkdir adump
[oracle@rac1 anqing]$ mkdir bdump
[oracle@rac1 anqing]$ mkdir cdump
[oracle@rac1 anqing]$ mkdir dpdump
[oracle@rac1 anqing]$ mkdir hdump
[oracle@rac1 anqing]$ mkdir pfile
[oracle@rac1 anqing]$ mkdir udump
[oracle@rac1 anqing]$ ll
total 28
drwxr-xr-x 2 oracle oinstall 4096 May 18 23:40 adump
drwxr-xr-x 2 oracle oinstall 4096 May 18 23:40 bdump
drwxr-xr-x 2 oracle oinstall 4096 May 18 23:40 cdump
drwxr-xr-x 2 oracle oinstall 4096 May 18 23:41 dpdump
drwxr-xr-x 2 oracle oinstall 4096 May 18 23:41 hdump
drwxr-xr-x 2 oracle oinstall 4096 May 18 23:41 pfile
drwxr-xr-x 2 oracle oinstall 4096 May 18 23:41 udump
之前一个RAC 环境的ASM 目录如下,我们可以参考这个目录来建:
ASMCMD> ls
DATA/
FRA/
ASMCMD> cd DATA
-- 看下DATA目录下的目录层级
ASMCMD> ls
RAC/
ASMCMD> cd RAC
ASMCMD> ls
CONTROLFILE/
DATAFILE/
TEMPFILE/
ONLINELOG/
PARAMETERFILE/
spfilerac.ora
ASMCMD> cd CONTROLFILE
ASMCMD> ls
Current.260.746634201
ASMCMD> cd ..
ASMCMD> cd DATAFILE
ASMCMD> ls
SYSAUX.257.746634087
SYSTEM.256.746634087
UNDOTBS1.258.746634089
UNDOTBS2.264.746634255
USERS.259.746634089
ASMCMD> cd ..
ASMCMD> cd TEMPFILE
ASMCMD> ls
TEMP.263.746634229
ASMCMD> cd ..
ASMCMD> ls
CONTROLFILE/
DATAFILE/
TEMPFILE/
spfilerac.ora
ASMCMD> cd ..
ASMCMD> cd ..
ASMCMD> ls
DATA/
FRA/
ASMCMD> cd FRA
--看下FRA 目录下的层级
ASMCMD> ls
RAC/
ASMCMD> cd RAC
ASMCMD> ls
1_95_746989315.arc
1_96_746989315.arc
CONTROLFILE/
--归档文件因为我指定到这个目录了,所以限制在这里,这里可以在建一个目录,专门存放归档文件
ASMCMD> cd CONTROLFILE
ASMCMD> ls
Current.256.746634203
ASMCMD>
官网文档说明需要添加如下参数:
*.cluster_database = TRUE
*.cluster_database_instances = 2
*.undo_management=AUTO
最终我们修改之后的pfile 文件如下:
[oracle@rac1 dbs]$ cat initanqing.ora
*.audit_file_dest='/u01/app/oracle/admin/anqing/adump'
*.background_dump_dest='/u01/app/oracle/admin/anqing/bdump'
*.cluster_database_instances=2
*.cluster_database=true
*.compatible='10.2.0.1.0'
*.control_files='+DATA/anqing/controlfile/control01.ctl','+FRA/anqing/controlfile/control02.ctl'
*.core_dump_dest='/u01/app/oracle/admin/anqing/cdump'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='anqing'
*.db_recovery_file_dest='+FRA'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=racXDB)'
anqing1.instance_name='anqing1'
anqing2.instance_name='anqing2'
anqing1.instance_number=1
anqing2.instance_number=2
*.job_queue_processes=10
*.log_archive_dest_1='LOCATION=+FRA/anqing/archivelog'
*.log_archive_format='%t_%s_%r.arc'
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_login_passwordfile='exclusive'
*.sga_target=285212672
anqing1.thread=1
anqing2.thread=2
*.undo_management='AUTO'
anqing1.undo_tablespace='UNDOTBS1'
anqing2.undo_tablespace='UNDOTBS2'
*.user_dump_dest='/u01/app/oracle/admin/anqing/udump'
2.3.4 用修改的pfile 来创建spfile,注意放在共享设备上
[oracle@rac1 ~]$ sqlplus / as sysdba;
SQL*Plus: Release 10.2.0.4.0 - Production on Thu May 19 00:15:54 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to an idle instance.
> startup nomount;
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initanqing1.ora'
> create spfile='+DATA/ANQING/PARAMETERFILE/spfileanqing.ora' from pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initanqing1.ora';
File created.
>
到ASM里验证一下:
ASMCMD> pwd
+DATA/ANQING/PARAMETERFILE
ASMCMD> ls
spfileanqing.ora
在所有节点上,修改pfile内容,将其指向共享设备上的spfile:
[oracle@rac1 dbs]$ echo "SPFILE='+DATA/ANQING/PARAMETERFILE/spfileanqing.ora'" > /u01/app/oracle/product/10.2.0/db_1/dbs/initanqing1.ora
[oracle@rac1 dbs]$ cat initanqing.ora
SPFILE='+DATA/ANQING/PARAMETERFILE/spfileanqing.ora'
2.4 创建口令文件
在所有节点执行:
[oracle@rac1 dbs]$ orapwd file=?/dbs/orapwanqing1 password=oracle
[oracle@rac2 admin]$ orapwd file=?/dbs/orapwanqing2 password=oracle
2.5 还原控制文件
在其中一个节点上执行。
2.5.1 用spfile,将DB 启动到nomount 状态
[oracle@rac1 dbs]$ sqlplus / as sysdba;
SQL*Plus: Release 10.2.0.4.0 - Production on Thu May 19 10:29:16 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to an idle instance.
> startup nomount;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1267068 bytes
Variable Size 88083076 bytes
Database Buffers 192937984 bytes
Redo Buffers 2924544 bytes
> show parameter spfile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string +DATA/anqing/parameterfile/spf ileanqing.ora
这次启动没有报没有参数文件报错了。
2.5.2 RMAN 执行对控制文件的恢复
[oracle@rac1 dbs]$ rman target /
Recovery Manager: Release 10.2.0.4.0 - Production on Thu May 19 10:31:55 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: anqing (not mounted)
RMAN> restore controlfile from '/u01/backup/ctl_file_09nbo3jk_1_1_20120523';
Starting restore at 19-MAY-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=150 instance=anqing1 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:17
output filename=+DATA/anqing/controlfile/control01.ctl
output filename=+FRA/anqing/controlfile/control02.ctl
Finished restore at 19-MAY-11
RMAN>
这个位置是我们在初始化参数里指定的,到ASM 实例里验证下:
ASMCMD> cd FRA
ASMCMD> ls
ANQING/
DAVE/
RAC/
ASMCMD> cd anqing
ASMCMD> ls
ARCHIVELOG/
CONTROLFILE/
ASMCMD> cd controlfile
ASMCMD> ls
control02.ctl
current.429.751545173
这里除了我们指定的,还自动生成了一个,这个control02.ctl 是我们current.429.751545173 文件的一个别名。 我们确认一下:
ASMCMD> ls -l
Type Redund Striped Time Sys Name
N control01.ctl => +DATA/ANQING/CONTROLFILE/current.272.751545171
CONTROLFILE UNPROT FINE MAY 19 10:00:00 Y current.272.751545171
有关ASM 别名,参考我的Blog:racle ASM 详解
http://blog.csdn.net/tianlesoftware/archive/2010/02/21/5314541.aspx
ASM文件名字的格式是固定的:+group/dbname/file type/tag.file.incarnation
在创建db时系统自动创建的几个表空间(system,undotbs,sysaux,users)对应的都是真实的数据文件,即ASM 文件默认的命名格式。而且这个信息都写到了控制文件里。
如果我们使用别名的话,会方便很多。 对于这些创建数据库时自动创建的表空间,我们要他们使用别名,除了手工创建对应别名外,还需要重建控制文件,并且在重建时,datafile 里写别名的信息。 这样数据库也就使用别名了。
对这个现象的一个说明:
ASM 有自己的文件固定格式,如果我们在指定参数或者文件名时,指定了具体的文件名,那么这个文件名会以别名的方式指向ASM中的文件。
2.6 restore数据库
在其中一个节点执行
2.6.1 将数据库启动到MOUNT状态
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
2.6.2 查看源库数据文件存储位置信息
注意一点,我们单实例和RAC 实例存储数据文件的位置不同,如果我们使用rman 的duplicate,那么我们使用log_file_name_convert 和 db_file_name_convert来进行转换,在这个实验中,我们使用的是RMAN的异机恢复,所以只能在restore的时候用set newname来进行转换。
SQL> set linesize 80
SQL> select file_id,file_name from dba_data_files;
FILE_ID FILE_NAME
---------- ---------------------------------------------------------------------
4 /u01/app/oracle/oradata/anqing/users01.dbf
3 /u01/app/oracle/oradata/anqing/sysaux01.dbf
2 /u01/app/oracle/oradata/anqing/undotbs01.dbf
1 /u01/app/oracle/oradata/anqing/system01.dbf
SQL> select file_id,file_name from dba_temp_files;
FILE_ID FILE_NAME
---------- ---------------------------------------------------------------------
1 /u01/app/oracle/oradata/anqing/temp01.dbf
2.6.3 在RAC上restore 数据文件
set newname for datafile 1 to '+DATA/anqing/DATAFILE/system01.dbf';
set newname for datafile 2 to '+DATA/anqing/DATAFILE/undotbs01.dbf';
set newname for datafile 3 to '+DATA/anqing/DATAFILE/sysaux01.dbf';
set newname for datafile 4 to '+DATA';
set newname for tempfile 1 to '+DATA/anqing/TEMPFILE/temp01.dbf';
restore database;
switch datafile all;
switch tempfile all;
}
注意:
(1)我们datafile 3 和 4的区别,datafile 4 我没有指定具体的文件名,那么在还原时会使用ASM 自己的命名方式来命名datafile4. 其他的文件会创建别名。
(2)对switch的说明:
对于nocatalog 模式下,rman备份的信息是保存在控制文件里的,包括文件的路径信息。 这里的switch的作用,就是更新控制文件里的信息。
(3)restore 的时候不会对temp 表空间进行restore。所以等restore 之后,我们需要手工创建temp表空间。
不过在这个测试里,我们还是对tempfile 进行了指定。 但是这个操作只更新控制文件,不恢复数据文件。
脚本执行结果如下:
RMAN> run {
2> set newname for datafile 1 to '+DATA/anqing/DATAFILE/system01.dbf';
3> set newname for datafile 2 to '+DATA/anqing/DATAFILE/undotbs01.dbf';
4> set newname for datafile 3 to '+DATA/anqing/DATAFILE/sysaux01.dbf';
5> set newname for datafile 4 to '+DATA';
6> set newname for tempfile 1 to '+DATA/anqing/TEMPFILE/temp01.dbf';
restore database;
7> 8> switch datafile all;
9> switch tempfile all;
10> }
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 19-MAY-11
using channel ORA_DISK_1
channel ORA_DISK_1: restoring datafile 00004
input datafile copy recid=1 stamp=751548119 filename=/u01/app/oracle/product/10.2.0/db_1/dbs/ +DATA
destination for restore of datafile 00004: +DATA
channel ORA_DISK_1: copied datafile copy of datafile 00004
output filename=+DATA/anqing/datafile/users.273.751548233 recid=2 stamp=751548232
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to +DATA/anqing/datafile/undotbs01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/anqing_lev0_03nbo3f3_1_1_20120523
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/backup/anqing_lev0_03nbo3f3_1_1_20120523 tag=ANQING_LEV0
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00003 to +DATA/anqing/datafile/sysaux01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/anqing_lev0_02nbo3f3_1_1_20120523
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/backup/anqing_lev0_02nbo3f3_1_1_20120523 tag=ANQING_LEV0
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to +DATA/anqing/datafile/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/anqing_lev0_01nbo3f3_1_1_20120523
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/backup/anqing_lev0_01nbo3f3_1_1_20120523 tag=ANQING_LEV0
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 19-MAY-11
datafile 1 switched to datafile copy
input datafile copy recid=6 stamp=751548297 filename=+DATA/anqing/datafile/system01.dbf
datafile 2 switched to datafile copy
input datafile copy recid=7 stamp=751548297 filename=+DATA/anqing/datafile/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=8 stamp=751548297 filename=+DATA/anqing/datafile/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=9 stamp=751548297 filename=+DATA/anqing/datafile/users.273.751548233
renamed temporary file 1 to +DATA/anqing/TEMPFILE/temp01.dbf in control file
-- 从这里可以看到,对tempfile 仅仅是rename。即更新控制文件。
到ASM 实例里查看一下:
ASMCMD> cd DATAFILE
ASMCMD> ls
SYSAUX.275.751548237
SYSTEM.276.751548261
UNDOTBS1.274.751548233
USERS.273.751548233
sysaux01.dbf
system01.dbf
undotbs01.dbf
ASMCMD>
ASMCMD> ls -l
Type Redund Striped Time Sys Name
DATAFILE UNPROT COARSE MAY 19 11:00:00 Y SYSAUX.275.751548237
DATAFILE UNPROT COARSE MAY 19 11:00:00 Y SYSTEM.276.751548261
DATAFILE UNPROT COARSE MAY 19 11:00:00 Y UNDOTBS1.274.751548233
DATAFILE UNPROT COARSE MAY 19 11:00:00 Y USERS.273.751548233
N sysaux01.dbf => +DATA/ANQING/DATAFILE/SYSAUX.275.751548237
N system01.dbf => +DATA/ANQING/DATAFILE/SYSTEM.276.751548261
N undotbs01.dbf => +DATA/ANQING/DATAFILE/UNDOTBS1.274.751548233
-- 映射别名
ASMCMD> cd tempfile
ASMCMD> ls
ASMCMD>
--tempfile 对应的目录为空,即没有恢复数据文件。
2.8 recover 数据库
在执行restore的节点执行,因为备份文件在该节点上。
RMAN> recover database;
Starting recover at 19-MAY-11
using channel ORA_DISK_1
starting media recovery
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=3
channel ORA_DISK_1: reading from backup piece /u01/backup/arch_08nbo3je_1_1_20120523
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/backup/arch_08nbo3je_1_1_20120523 tag=ARC_BAK
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=2
channel ORA_DISK_1: reading from backup piece /u01/backup/arch_07nbo3je_1_1_20120523
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/backup/arch_07nbo3je_1_1_20120523 tag=ARC_BAK
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
archive log filename=+FRA/anqing/archivelog/1_2_784072335.arc thread=1 sequence=2
archive log filename=+FRA/anqing/archivelog/1_3_784072335.arc thread=1 sequence=3
unable to find archive log
archive log thread=1 sequence=4
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 05/19/2011 12:13:52
RMAN-06054: media recovery requesting unknown log: thread 1 seq 4 lowscn 460025
最后一行的错误说明:
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 9 and starting SCN of 823627
这里是提醒恢复到一个未知的scn号。在alter database mount之后,通过set until scn或者set until time命令设置恢复到的scn号或时间。就可以避免这个错误。
2.9 处理online redo
因为此时另一个节点还没有配好,所以我们只能在执行恢复的节点上处理redo。
[oracle@rac1 backup]$ sqlplus / as sysdba;
SQL*Plus: Release 10.2.0.4.0 - Production on Thu May 19 12:19:08 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
SYS@anqing1(rac1)> set wrap off;
SYS@anqing1(rac1)> select * from v$logfile;
rows will be truncated
GROUP# STATUS TYPE MEMBER
---------- ------- ------- -----------------------------------------------------
3 ONLINE /u01/app/oracle/oradata/anqing/redo03.log
2 ONLINE /u01/app/oracle/oradata/anqing/redo02.log
1 ONLINE /u01/app/oracle/oradata/anqing/redo01.log
+DATA/anqing/onlinelog/redo02.log
SYS@anqing1(rac1)> alter database rename file '/u01/app/oracle/oradata/anqing/redo02.log' to '+DATA/anqing/onlinelog/redo02.log'; SYS@anqing1(rac1)> alter database rename file '/u01/app/oracle/oradata/anqing/redo03.log' to '+DATA/anqing/onlinelog/redo03.log';
SYS@anqing1(rac1)> select * from v$logfile;
rows will be truncated
GROUP# STATUS TYPE MEMBER
---------- ------- ------- -----------------------------------------------------
3 ONLINE +DATA/anqing/onlinelog/redo03.log
2 ONLINE +DATA/anqing/onlinelog/redo02.log
1 ONLINE +DATA
ASMCMD> pwd
+DATA/anqing/onlinelog
ASMCMD> ls
ASMCMD>
注意这个时候,对应目录还是空的,当我们open db 的时候,oracle 会自动创建online redo log。我们这里修改的目的就是改变online redo 的位置。
2.10 open resetlogs 打开DB
在恢复的节点执行该操作。
SYS@anqing1(rac1)> alter database open resetlogs;
我这里因为版本的问题, 报错了,升级之后才成功open.
SYS@anqing1(rac1)> select name,open_mode from v$database;
NAME OPEN_MODE
--------- ----------
ANQING READ WRITE
SYS@anqing1(rac1)> select comp_name, version, status from sys.dba_registry;
COMP_NAME VERSION STATUS
------------------------------ ------------------------------ ------------------
Oracle Database Catalog Views 10.2.0.4.0 VALID
Oracle Database Packages and T 10.2.0.4.0 VALID
Oracle Workspace Manager 10.2.0.4.3 VALID
JServer JAVA Virtual Machine 10.2.0.4.0 VALID
Oracle XDK 10.2.0.4.0 VALID
Oracle Database Java Packages 10.2.0.4.0 VALID
Oracle Expression Filter 10.2.0.4.0 VALID
Oracle Data Mining 10.2.0.4.0 VALID
Oracle Text 10.2.0.4.0 VALID
Oracle XML Database 10.2.0.4.0 VALID
Oracle Rule Manager 10.2.0.4.0 VALID
COMP_NAME VERSION STATUS
------------------------------ ------------------------------ ------------------
Oracle interMedia 10.2.0.4.0 VALID
OLAP Analytic Workspace 10.2.0.4.0 VALID
Oracle OLAP API 10.2.0.4.0 VALID
OLAP Catalog 10.2.0.4.0 VALID
Spatial 10.2.0.4.0 VALID
Oracle Enterprise Manager 10.2.0.4.0 VALID
17 rows selected.
因为我们在控制文件里已经指定了online redo 和temp file。 所以在open resetlog的时候会检查这些文件,如果不在,会自动创建这2个文件。
2.11 检查并修改几个初始化参数
SYS@anqing1(rac1)> select * from v$option where parameter = 'Real Application Clusters';
PARAMETER VALUE
---------------------------------------------
Real Application Clusters TRUE
SYS@anqing1(rac1)> show parameter cluster
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cluster_database boolean FALSE
cluster_database_instances integer 1
cluster_interconnects string
SYS@anqing1(rac1)> show parameter thread
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
parallel_threads_per_cpu integer 2
thread integer 1
SYS@anqing1(rac1)> show parameter instance_number
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
instance_number integer 1
由上述返回结果可知,RAC特性是支持的,不过尚未启用集群数据库,因此接下来首先要改的,就是enable CLUSTER DATABASE,操作如下:
SYS@anqing1(rac1)> alter system set cluster_database=true scope=spfile;
System altered.
修改2个节点的配置参数:
SYS@anqing1(rac1)> alter system set cluster_database_instances=2 scope=spfile;
System altered.
SYS@anqing1(rac1)> alter system set instance_number=1 scope=spfile sid='anqing1';
System altered.
SYS@anqing1(rac1)> alter system set instance_number=2 scope=spfile sid='anqing2';
System altered.
SYS@anqing1(rac1)> alter system set thread=1 scope=spfile sid='anqing1';
System altered.
SYS@anqing1(rac1)> alter system set thread=2 scope=spfile sid='anqing2';
System altered.
2.12 创建节点2的undo 表空间
SYS@anqing1(rac1)> show parameter undo_tablespace
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace string UNDOTBS1
这个是rac1上节点的信息,我们在之前的在spfile参数指定的rac2节点的undo 空间是.
所以这里我们创建该undo 表空间,并指定相关参数。
SYS@anqing1(rac1)> create undo tablespace UNDOTBS2 datafile '+DATA/ANQING/datafile/undotbs02.dbf' size 500m;
Tablespace created.
--这里我们直接指定别名
ASMCMD> pwd
+DATA/ANQING/datafile
ASMCMD> ls
SYSAUX.275.751548237
SYSTEM.276.751548261
UNDOTBS1.274.751548233
UNDOTBS2.281.751559213
USERS.273.751548233
sysaux01.dbf
system01.dbf
undotbs01.dbf
undotbs02.dbf
SYS@anqing1(rac1)> alter system set undo_tablespace='UNDOTBS2' scope=spfile sid='anqing2';
System altered.
2.13 添加rac2 节点的redo 文件
rac 的redo 是接其他节点来的,我们之前的rac1上已经有3组,所以我们这里从4开始,在添加2组给rac2,使用thread 2.
SYS@anqing1(rac1)> alter database add logfile thread 2 group 4 '+DATA' size 100m;
Database altered.
SYS@anqing1(rac1)> alter database add logfile thread 2 group 5 '+DATA' size 100m;
Database altered.
SYS@anqing1(rac1)> alter database enable thread 2;
Database altered.
2.14 重启节点1和节点2 上的实例,使相关参数生效
节点1:
SYS@anqing1(rac1)> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@anqing1(rac1)> startup
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1267068 bytes
Variable Size 146803332 bytes
Database Buffers 134217728 bytes
Redo Buffers 2924544 bytes
Database mounted.
Database opened.
SYS@anqing1(rac1)> show parameter cluster
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cluster_database boolean TRUE
cluster_database_instances integer 2
cluster_interconnects string
SYS@anqing1(rac1)>
节点2:
[oracle@rac2 dbs]$ sqlplus / as sysdba;
SQL*Plus: Release 10.2.0.4.0 - Production on Thu May 19 14:50:06 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to an idle instance.
> startup
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1267068 bytes
Variable Size 88083076 bytes
Database Buffers 192937984 bytes
Redo Buffers 2924544 bytes
Database mounted.
Database opened.
> show parameter cluster
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cluster_database boolean TRUE
cluster_database_instances integer 2
cluster_interconnects string
最后确认:
SYS@anqing1(rac1)> select instance_number,instance_name,host_name from gv$instance;
INSTANCE_NUMBER INSTANCE_NAME HOST_NAME
--------------- ---------------- -----------------------------------------------
2 anqing2 rac2
1 anqing1 rac1
到现在已经是集群了,不过还有一些收尾的工作要做。
2.15 执行catclust.sql脚本来创建相关视图
$ORACLE_HOME/rdbms/admin/catclust.sql to create cluster database specific views within the existing instance
SYS@anqing1(rac1)> @$ORACLE_HOME/rdbms/admin/catclust.sql
2.16 重建Temp 表空间
在恢复的时候,会自动创建TEMP 表空间。和一个前辈聊到过这个问题,他说这个temp 文件好像没有起到作用。 尤其是数据量大的时候,他建议重建添加temp 数据文件。 这个还是小心为好,反正重建一些也不费什么事。但是万一出问题,就是大麻烦。
步骤如下:
SYS@anqing1(rac1)> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
+DATA/anqing/tempfile/temp01.dbf
SYS@anqing1(rac1)> alter tablespace temp add tempfile '+DATA/anqing/tempfile/temp02.dbf' size 100M;
Tablespace altered.
SYS@anqing1(rac1)> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
+DATA/anqing/tempfile/temp01.dbf
+DATA/anqing/tempfile/temp02.dbf
SYS@anqing1(rac1)> alter database tempfile '+DATA/anqing/tempfile/temp01.dbf' offline;
Database altered.
SYS@anqing1(rac1)> alter database tempfile '+DATA/anqing/tempfile/temp01.dbf' drop including datafiles;
Database altered.
SYS@anqing1(rac1)> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
+DATA/anqing/tempfile/temp02.dbf
2.17 添加集群的监听
使用nomachine 连上任一节点,用netca 配置一下。参考:
远程桌面工具 -- NoMachine
http://blog.csdn.net/tianlesoftware/archive/2010/11/11/6003610.aspx
添加监听之前:
[oracle@rac1 u01]$ sh crs_stat.sh
Name Target State Host
------------------------------ ---------- --------- -------
ora.rac1.ASM1.asm ONLINE ONLINE rac1
ora.rac1.gsd ONLINE ONLINE rac1
ora.rac1.ons ONLINE ONLINE rac1
ora.rac1.vip ONLINE ONLINE rac1
ora.rac2.ASM2.asm ONLINE ONLINE rac2
ora.rac2.gsd ONLINE ONLINE rac2
ora.rac2.ons ONLINE ONLINE rac2
ora.rac2.vip ONLINE ONLINE rac2
添加监听之后:
[oracle@rac1 u01]$ sh crs_stat.sh
Name Target State Host
------------------------------ ---------- --------- -------
ora.rac1.ASM1.asm ONLINE ONLINE rac1
ora.rac1.LISTENER_RAC1.lsnr ONLINE ONLINE rac1
ora.rac1.gsd ONLINE ONLINE rac1
ora.rac1.ons ONLINE ONLINE rac1
ora.rac1.vip ONLINE ONLINE rac1
ora.rac2.ASM2.asm ONLINE ONLINE rac2
ora.rac2.LISTENER_RAC2.lsnr ONLINE ONLINE rac2
ora.rac2.gsd ONLINE ONLINE rac2
ora.rac2.ons ONLINE ONLINE rac2
ora.rac2.vip ONLINE ONLINE rac2
2.18 将其他信息注册到CRS里
[oracle@rac1 u01]$ srvctl add database -d anqing -o $ORACLE_HOME -p +DATA/ANQING/PARAMETERFILE/spfileanqing.ora
[oracle@rac1 u01]$ srvctl add instance -d anqing -i anqing1 -n rac1
[oracle@rac1 u01]$ srvctl add instance -d anqing -i anqing2 -n rac2
修改instance 和 asm 之间的依赖关系:
srvctl modify instance -d
[oracle@rac1 u01]$ srvctl modify instance -d anqing -i anqing1 -s +ASM1
[oracle@rac1 u01]$ srvctl modify instance -d anqing -i anqing2 -s +ASM2
在来查看:
[oracle@rac1 u01]$ sh crs_stat.sh
Name Target State Host
------------------------------ ---------- --------- -------
ora.anqing.anqing1.inst OFFLINE OFFLINE
ora.anqing.anqing2.inst OFFLINE OFFLINE
ora.anqing.db OFFLINE OFFLINE
ora.rac1.ASM1.asm ONLINE ONLINE rac1
ora.rac1.LISTENER_RAC1.lsnr ONLINE ONLINE rac1
ora.rac1.gsd ONLINE ONLINE rac1
ora.rac1.ons ONLINE ONLINE rac1
ora.rac1.vip ONLINE ONLINE rac1
ora.rac2.ASM2.asm ONLINE ONLINE rac2
ora.rac2.LISTENER_RAC2.lsnr ONLINE ONLINE rac2
ora.rac2.gsd ONLINE ONLINE rac2
ora.rac2.ons ONLINE ONLINE rac2
ora.rac2.vip ONLINE ONLINE rac2
这里并没有启动,因为我们的服务是刚添加上来的,还没有同步。 我们启动一下就ok了。
[oracle@rac1 u01]$ srvctl start database -d anqing
启动之后在查,各个进程正常:
[oracle@rac1 u01]$ sh crs_stat.sh
Name Target State Host
------------------------------ ---------- --------- -------
ora.anqing.anqing1.inst ONLINE ONLINE rac1
ora.anqing.anqing2.inst ONLINE ONLINE rac2
ora.anqing.db ONLINE ONLINE rac1
ora.rac1.ASM1.asm ONLINE ONLINE rac1
ora.rac1.LISTENER_RAC1.lsnr ONLINE ONLINE rac1
ora.rac1.gsd ONLINE ONLINE rac1
ora.rac1.ons ONLINE ONLINE rac1
ora.rac1.vip ONLINE ONLINE rac1
ora.rac2.ASM2.asm ONLINE ONLINE rac2
ora.rac2.LISTENER_RAC2.lsnr ONLINE ONLINE rac2
ora.rac2.gsd ONLINE ONLINE rac2
ora.rac2.ons ONLINE ONLINE rac2
ora.rac2.vip ONLINE ONLINE rac2
2.19 配置RAC 的Failover 和 Loadbalance
这两块的理论知识参考我的Blog:
Oracle RAC LoadBalance
http://blog.csdn.net/tianlesoftware/archive/2010/03/05/5347775.aspx
Oracle RAC Failover 详解
http://blog.csdn.net/tianlesoftware/archive/2010/03/03/5340788.aspx
在这里我们配置一下Client-side 的TAF. 具体步骤参考:
local_listener 与 remote_listener 参数说明
http://blog.csdn.net/tianlesoftware/archive/2010/12/20/6087045.aspx
中的第三小节。
2.20 最后创建查看一下我们开始创建的表:
C:/Users/Administrator.DavidDai>sqlplus sys/oracle@rac as sysdba;
SQL*Plus: Release 11.2.0.1.0 Production on Thu May 19 16:05:57 2011
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
SQL> set wrap off;
SQL> set linesize 80
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
anqing1
SQL> select * from dave;
ID HOMETOWN
---------- ---------------------------------
1安徽省安庆市怀宁县
单实例迁移到RAC 到此结束。步骤还是有点多,所以在操作的时候,仔细一点。