一、环境介绍
Redhat 5.8+Oracle 10g rac (10.2.0.5)+ASM
二、需求:新建一个磁盘组hzdw2019,利用新的磁盘组(HZDW2019)替换原来的DATA磁盘组
三、步骤
3.1、为新磁盘组划分磁盘(略)
3.2、实施数据库全备
全备脚本如下:
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
crosscheck backup;
sql 'alter system archive log current';
backup database format '+hzdw2019/db_%d_%T_%U';
sql 'alter system archive log current';
backup archivelog all format '+hzdw2019/arc_%t_%s' delete all input;
backup current controlfile format '+hzdw2019/cntrl_%s_%p_%s';
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt obsolete;
delete noprompt backup of database completed before 'sysdate - 7';
release channel c1;
release channel c2;
release channel c3;
}
3.3、创建pfile文件
SQL> startup nomount pfile='/home/oracle/init_2019.ora';
3.4、各节点关闭数据库
3.5、节点一使用pfile启动数据库到nomount
SQL> startup nomount pfile='/home/oracle/init_2019.ora';
ORACLE instance started.
Total System Global Area 918552576 bytes
Fixed Size 2100552 bytes
Variable Size 255853240 bytes
Database Buffers 654311424 bytes
Redo Buffers 6287360 bytes
SQL>
3.6、还原控制文件
RMAN> restore controlfile from '+hzdw2019/cntrl_12_1_12';
Starting restore at 11-MAR-19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=147 instance=rac1 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
output filename=+HZDW2019/rac/controlfile/current.272.1002622331
Finished restore at 11-MAR-19
RMAN>
3.7、修改数据库到mount
RMAN> sql 'alter database mount';
sql statement: alter database mount
released channel: ORA_DISK_1
RMAN>
3.8、注册备份集信息
RMAN> catalog start with '+hzdw2019';
searching for all files that match the pattern +hzdw2019
List of Files Unknown to the Database
=====================================
File Name: +hzdw2019/cntrl_12_1_12
Do you really want to catalog the above files (enter YES or NO)? no
RMAN>
不能发现备份片信息,所以采用手动注册的方式:
RMAN> catalog backuppiece '+hzdw2019/db_rac_20190311_03ts5i43_1_1';
cataloged backuppiece
backup piece handle=+HZDW2019/db_rac_20190311_03ts5i43_1_1 recid=11 stamp=1002639056
RMAN> catalog backuppiece '+hzdw2019/db_rac_20190311_04ts5i43_1_1';
cataloged backuppiece
backup piece handle=+HZDW2019/db_rac_20190311_04ts5i43_1_1 recid=12 stamp=1002639077
RMAN> catalog backuppiece '+hzdw2019/db_rac_20190311_05ts5i44_1_1';
cataloged backuppiece
backup piece handle=+HZDW2019/db_rac_20190311_05ts5i44_1_1 recid=13 stamp=1002639094
RMAN> catalog backuppiece '+hzdw2019/db_rac_20190311_07ts5i6k_1_1';
cataloged backuppiece
backup piece handle=+HZDW2019/db_rac_20190311_07ts5i6k_1_1 recid=14 stamp=1002639106
RMAN>
3.9、执行数据库还原
还原脚本如下:
run {
allocate channel c0 type disk;
allocate channel c1 type disk;
allocate channel c2 type disk;
set newname for datafile 1 to '+hzdw2019/rac/datafile/system';
set newname for datafile 2 to '+hzdw2019/rac/datafile/undotbs1';
set newname for datafile 3 to '+hzdw2019/rac/datafile/sysaux';
set newname for datafile 4 to '+hzdw2019/rac/datafile/users';
set newname for datafile 5 to '+hzdw2019/rac/datafile/example';
set newname for datafile 6 to '+hzdw2019/rac/datafile/undotbs2';
restore database;
switch datafile all;
release channel c0;
release channel c1;
release channel c2;
}
RMAN> run {
allocate channel c0 type disk;
allocate channel c1 type disk;
allocate channel c2 type disk;
set newname for datafile 1 to '+hzdw2019/rac/datafile/system';
set newname for datafile 2 to '+hzdw2019/rac/datafile/undotbs1';
set newname for datafile 3 to2> 3> 4> 5> 6> 7> '+hzdw2019/rac/datafile/sysaux';
set newname for datafile 4 to '+hzdw2019/rac/datafile/users';
set newname for datafile 5 to '+hzdw2019/rac/datafile/example';
set newname for datafile 6 to '+hzdw2019/rac/datafile/undotbs2';
restore database;
switch datafile all;
release channel c0;
release channel c1;
release channel c2;
}8> 9> 10> 11> 12> 13> 14> 15> 16>
allocated channel: c0
channel c0: sid=146 instance=rac1 devtype=DISK
allocated channel: c1
channel c1: sid=145 instance=rac1 devtype=DISK
allocated channel: c2
channel c2: sid=142 instance=rac1 devtype=DISK
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 11-MAR-19
channel c0: starting datafile backupset restore
channel c0: specifying datafile(s) to restore from backup set
restoring datafile 00002 to +HZDW2019/rac/datafile/undotbs1
restoring datafile 00003 to +HZDW2019/rac/datafile/sysaux
channel c0: reading from backup piece +HZDW2019/db_rac_20190311_03ts5i43_1_1
channel c1: starting datafile backupset restore
channel c1: specifying datafile(s) to restore from backup set
restoring datafile 00004 to +HZDW2019/rac/datafile/users
restoring datafile 00006 to +HZDW2019/rac/datafile/undotbs2
channel c1: reading from backup piece +HZDW2019/db_rac_20190311_05ts5i44_1_1
channel c2: starting datafile backupset restore
channel c2: specifying datafile(s) to restore from backup set
restoring datafile 00001 to +HZDW2019/rac/datafile/system
restoring datafile 00005 to +HZDW2019/rac/datafile/example
channel c2: reading from backup piece +HZDW2019/db_rac_20190311_04ts5i43_1_1
channel c1: restored backup piece 1
piece handle=+HZDW2019/db_rac_20190311_05ts5i44_1_1 tag=TAG20190311T095059
channel c1: restore complete, elapsed time: 00:02:17
channel c2: restored backup piece 1
piece handle=+HZDW2019/db_rac_20190311_04ts5i43_1_1 tag=TAG20190311T095059
channel c2: restore complete, elapsed time: 00:02:43
channel c0: restored backup piece 1
piece handle=+HZDW2019/db_rac_20190311_03ts5i43_1_1 tag=TAG20190311T095059
channel c0: restore complete, elapsed time: 00:02:46
Finished restore at 11-MAR-19
datafile 1 switched to datafile copy
input datafile copy recid=8 stamp=1002639415 filename=+HZDW2019/rac/datafile/system
datafile 2 switched to datafile copy
input datafile copy recid=9 stamp=1002639415 filename=+HZDW2019/rac/datafile/undotbs1
datafile 3 switched to datafile copy
input datafile copy recid=10 stamp=1002639415 filename=+HZDW2019/rac/datafile/sysaux
datafile 4 switched to datafile copy
input datafile copy recid=11 stamp=1002639415 filename=+HZDW2019/rac/datafile/users
datafile 5 switched to datafile copy
input datafile copy recid=12 stamp=1002639416 filename=+HZDW2019/rac/datafile/example
datafile 6 switched to datafile copy
input datafile copy recid=13 stamp=1002639416 filename=+HZDW2019/rac/datafile/undotbs2
released channel: c0
released channel: c1
released channel: c2
RMAN>
3.10、注册归档备份片信息并执行恢复数据库操作
RMAN> catalog backuppiece '+hzdw2019/arc_1002621154_10';
cataloged backuppiece
backup piece handle=+HZDW2019/arc_1002621154_10 recid=15 stamp=1002639588
RMAN> catalog backuppiece '+hzdw2019/arc_1002621156_11';
cataloged backuppiece
backup piece handle=+HZDW2019/arc_1002621156_11 recid=16 stamp=1002639605
RMAN>
RMAN> recover database;
Starting recover at 11-MAR-19
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=146 instance=rac1 devtype=DISK
starting media recovery
archive log thread 1 sequence 91 is already on disk as file +DATA/rac/onlinelog/group_2.262.979404775
archive log thread 1 sequence 92 is already on disk as file +DATA/rac/onlinelog/group_1.261.979404773
archive log thread 2 sequence 70 is already on disk as file +DATA/rac/onlinelog/group_4.267.979404883
archive log thread 2 sequence 71 is already on disk as file +DATA/rac/onlinelog/group_3.266.979404883
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=90
channel ORA_DISK_1: reading from backup piece +HZDW2019/arc_1002621154_10
channel ORA_DISK_1: restored backup piece 1
piece handle=+HZDW2019/arc_1002621154_10 tag=TAG20190311T095233
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=+HZDW2019/rac/archivelog/2019_03_11/thread_1_seq_90.261.1002639629 thread=1 sequence=90
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=2 sequence=69
channel ORA_DISK_1: reading from backup piece +HZDW2019/arc_1002621156_11
channel ORA_DISK_1: restored backup piece 1
piece handle=+HZDW2019/arc_1002621156_11 tag=TAG20190311T095233
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=+HZDW2019/rac/archivelog/2019_03_11/thread_2_seq_69.259.1002639631 thread=2 sequence=69
archive log filename=+DATA/rac/onlinelog/group_2.262.979404775 thread=1 sequence=91
archive log filename=+DATA/rac/onlinelog/group_4.267.979404883 thread=2 sequence=70
archive log filename=+DATA/rac/onlinelog/group_3.266.979404883 thread=2 sequence=71
archive log filename=+DATA/rac/onlinelog/group_1.261.979404773 thread=1 sequence=92
media recovery complete, elapsed time: 00:00:07
Finished recover at 11-MAR-19
RMAN>
3.11、恢复完成后打开数据库
SQL> alter database open resetlogs;
Database altered.
SQL> select status from v$instance;
STATUS
------------
OPEN
SQL>
3.12、更换redo路径
3.12.1、查看当前数据库的redo信息
SQL> select a.GROUP#,a.THREAD#,a.SEQUENCE#,b.MEMBER,a.ARCHIVED,a.STATUS,a.bytes/1024/1024 from v$log a,v$logfile b where a.GROUP#=b.GROUP#;
GROUP# THREAD# SEQUENCE# MEMBER ARC STATUS A.BYTES/1024/1024
---------- ---------- ---------- ------------------------------------------------------------ --- ---------------- -----------------
2 1 4 +DATA/rac/onlinelog/group_2.262.979404775 NO CURRENT 50
1 1 3 +DATA/rac/onlinelog/group_1.261.979404773 YES ACTIVE 50
3 2 1 +DATA/rac/onlinelog/group_3.266.979404883 YES INACTIVE 50
4 2 2 +DATA/rac/onlinelog/group_4.267.979404883 NO CURRENT 50
SQL>
3.12.2、添加新的redo文件
alter database add logfile thread 1 group 5 size 50m;
alter database add logfile thread 1 group 6 size 50m;
alter database add logfile thread 2 group 7 size 50m;
alter database add logfile thread 2 group 8 size 50m;
SQL> alter database add logfile thread 1 group 5 size 50m;
Database altered.
SQL> select a.GROUP#,a.THREAD#,a.SEQUENCE#,b.MEMBER,a.ARCHIVED,a.STATUS,a.bytes/1024/1024 from v$log a,v$logfile b where a.GROUP#=b.GROUP#;
GROUP# THREAD# SEQUENCE# MEMBER ARC STATUS A.BYTES/1024/1024
---------- ---------- ---------- ------------------------------------------------------------ --- ---------------- -----------------
2 1 4 +DATA/rac/onlinelog/group_2.262.979404775 NO CURRENT 50
1 1 3 +DATA/rac/onlinelog/group_1.261.979404773 YES INACTIVE 50
3 2 1 +DATA/rac/onlinelog/group_3.266.979404883 YES INACTIVE 50
4 2 2 +DATA/rac/onlinelog/group_4.267.979404883 NO CURRENT 50
5 1 0 +HZDW2019/rac/onlinelog/group_5.280.1002641221 YES UNUSED 50
SQL> alter database add logfile thread 1 group 6 size 50m;
Database altered.
SQL> alter database add logfile thread 2 group 7 size 50m;
Database altered.
SQL> alter database add logfile thread 2 group 8 size 50m;
Database altered.
SQL>
3.12.3、手动执行数据库redo切换
SQL> alter system switch logfile;
System altered.
SQL>
SQL> select a.GROUP#,a.THREAD#,a.SEQUENCE#,b.MEMBER,a.ARCHIVED,a.STATUS,a.bytes/1024/1024 from v$log a,v$logfile b where a.GROUP#=b.GROUP#;
GROUP# THREAD# SEQUENCE# MEMBER ARC STATUS A.BYTES/1024/1024
---------- ---------- ---------- ------------------------------------------------------------ --- ---------------- -----------------
2 1 8 +DATA/rac/onlinelog/group_2.262.979404775 YES INACTIVE 50
1 1 7 +DATA/rac/onlinelog/group_1.261.979404773 YES INACTIVE 50
3 2 5 +DATA/rac/onlinelog/group_3.266.979404883 NO CURRENT 50
4 2 2 +DATA/rac/onlinelog/group_4.267.979404883 YES INACTIVE 50
5 1 9 +HZDW2019/rac/onlinelog/group_5.280.1002641221 YES INACTIVE 50
6 1 10 +HZDW2019/rac/onlinelog/group_6.281.1002641273 NO CURRENT 50
7 2 3 +HZDW2019/rac/onlinelog/group_7.282.1002641301 YES INACTIVE 50
8 2 4 +HZDW2019/rac/onlinelog/group_8.283.1002641311 YES INACTIVE 50
8 rows selected.
SQL>
3.12.4、删除老的redo文件
SQL> alter database drop logfile group 2;
Database altered.
SQL> alter database drop logfile group 3;
alter database drop logfile group 3
*
ERROR at line 1:
ORA-01623: log 3 is current log for instance rac2 (thread 2) - cannot drop
ORA-00312: online log 3 thread 2: '+DATA/rac/onlinelog/group_3.266.979404883'
SQL>
SQL> select a.GROUP#,a.THREAD#,a.SEQUENCE#,b.MEMBER,a.ARCHIVED,a.STATUS,a.bytes/1024/1024 from v$log a,v$logfile b where a.GROUP#=b.GROUP#;
GROUP# THREAD# SEQUENCE# MEMBER ARC STATUS A.BYTES/1024/1024
---------- ---------- ---------- ------------------------------------------------------------ --- ---------------- -----------------
3 2 5 +DATA/rac/onlinelog/group_3.266.979404883 NO CURRENT 50
4 2 2 +DATA/rac/onlinelog/group_4.267.979404883 YES INACTIVE 50
5 1 9 +HZDW2019/rac/onlinelog/group_5.280.1002641221 YES INACTIVE 50
6 1 10 +HZDW2019/rac/onlinelog/group_6.281.1002641273 NO CURRENT 50
7 2 3 +HZDW2019/rac/onlinelog/group_7.282.1002641301 YES INACTIVE 50
8 2 4 +HZDW2019/rac/onlinelog/group_8.283.1002641311 YES INACTIVE 50
6 rows selected.
SQL> alter system switch logfile;
System altered.
SQL> select a.GROUP#,a.THREAD#,a.SEQUENCE#,b.MEMBER,a.ARCHIVED,a.STATUS,a.bytes/1024/1024 from v$log a,v$logfile b where a.GROUP#=b.GROUP#;
GROUP# THREAD# SEQUENCE# MEMBER ARC STATUS A.BYTES/1024/1024
---------- ---------- ---------- ------------------------------------------------------------ --- ---------------- -----------------
3 2 5 +DATA/rac/onlinelog/group_3.266.979404883 NO CURRENT 50
4 2 2 +DATA/rac/onlinelog/group_4.267.979404883 YES INACTIVE 50
5 1 11 +HZDW2019/rac/onlinelog/group_5.280.1002641221 NO CURRENT 50
6 1 10 +HZDW2019/rac/onlinelog/group_6.281.1002641273 YES ACTIVE 50
7 2 3 +HZDW2019/rac/onlinelog/group_7.282.1002641301 YES INACTIVE 50
8 2 4 +HZDW2019/rac/onlinelog/group_8.283.1002641311 YES INACTIVE 50
6 rows selected.
SQL> alter system switch logfile;
System altered.
SQL> select a.GROUP#,a.THREAD#,a.SEQUENCE#,b.MEMBER,a.ARCHIVED,a.STATUS,a.bytes/1024/1024 from v$log a,v$logfile b where a.GROUP#=b.GROUP#;
GROUP# THREAD# SEQUENCE# MEMBER ARC STATUS A.BYTES/1024/1024
---------- ---------- ---------- ------------------------------------------------------------ --- ---------------- -----------------
3 2 5 +DATA/rac/onlinelog/group_3.266.979404883 YES INACTIVE 50
4 2 6 +DATA/rac/onlinelog/group_4.267.979404883 NO CURRENT 50
5 1 11 +HZDW2019/rac/onlinelog/group_5.280.1002641221 YES ACTIVE 50
6 1 12 +HZDW2019/rac/onlinelog/group_6.281.1002641273 NO CURRENT 50
7 2 3 +HZDW2019/rac/onlinelog/group_7.282.1002641301 YES INACTIVE 50
8 2 4 +HZDW2019/rac/onlinelog/group_8.283.1002641311 YES INACTIVE 50
6 rows selected.
SQL> alter database drop logfile group 3;
Database altered.
SQL> select a.GROUP#,a.THREAD#,a.SEQUENCE#,b.MEMBER,a.ARCHIVED,a.STATUS,a.bytes/1024/1024 from v$log a,v$logfile b where a.GROUP#=b.GROUP#;
GROUP# THREAD# SEQUENCE# MEMBER ARC STATUS A.BYTES/1024/1024
---------- ---------- ---------- ------------------------------------------------------------ --- ---------------- -----------------
4 2 6 +DATA/rac/onlinelog/group_4.267.979404883 NO CURRENT 50
5 1 11 +HZDW2019/rac/onlinelog/group_5.280.1002641221 YES ACTIVE 50
6 1 12 +HZDW2019/rac/onlinelog/group_6.281.1002641273 NO CURRENT 50
7 2 3 +HZDW2019/rac/onlinelog/group_7.282.1002641301 YES INACTIVE 50
8 2 4 +HZDW2019/rac/onlinelog/group_8.283.1002641311 YES INACTIVE 50
SQL> alter system switch logfile;
System altered.
SQL> select a.GROUP#,a.THREAD#,a.SEQUENCE#,b.MEMBER,a.ARCHIVED,a.STATUS,a.bytes/1024/1024 from v$log a,v$logfile b where a.GROUP#=b.GROUP#;
GROUP# THREAD# SEQUENCE# MEMBER ARC STATUS A.BYTES/1024/1024
---------- ---------- ---------- ------------------------------------------------------------ --- ---------------- -----------------
4 2 6 +DATA/rac/onlinelog/group_4.267.979404883 NO CURRENT 50
5 1 13 +HZDW2019/rac/onlinelog/group_5.280.1002641221 NO CURRENT 50
6 1 12 +HZDW2019/rac/onlinelog/group_6.281.1002641273 YES ACTIVE 50
7 2 3 +HZDW2019/rac/onlinelog/group_7.282.1002641301 YES INACTIVE 50
8 2 4 +HZDW2019/rac/onlinelog/group_8.283.1002641311 YES INACTIVE 50
SQL> alter system switch logfile;
System altered.
SQL> select a.GROUP#,a.THREAD#,a.SEQUENCE#,b.MEMBER,a.ARCHIVED,a.STATUS,a.bytes/1024/1024 from v$log a,v$logfile b where a.GROUP#=b.GROUP#;
GROUP# THREAD# SEQUENCE# MEMBER ARC STATUS A.BYTES/1024/1024
---------- ---------- ---------- ------------------------------------------------------------ --- ---------------- -----------------
4 2 6 +DATA/rac/onlinelog/group_4.267.979404883 YES INACTIVE 50
5 1 13 +HZDW2019/rac/onlinelog/group_5.280.1002641221 YES ACTIVE 50
6 1 14 +HZDW2019/rac/onlinelog/group_6.281.1002641273 NO CURRENT 50
7 2 7 +HZDW2019/rac/onlinelog/group_7.282.1002641301 NO CURRENT 50
8 2 4 +HZDW2019/rac/onlinelog/group_8.283.1002641311 YES INACTIVE 50
SQL> alter database drop logfile group 4;
Database altered.
SQL> select a.GROUP#,a.THREAD#,a.SEQUENCE#,b.MEMBER,a.ARCHIVED,a.STATUS,a.bytes/1024/1024 from v$log a,v$logfile b where a.GROUP#=b.GROUP#;
GROUP# THREAD# SEQUENCE# MEMBER ARC STATUS A.BYTES/1024/1024
---------- ---------- ---------- ------------------------------------------------------------ --- ---------------- -----------------
5 1 13 +HZDW2019/rac/onlinelog/group_5.280.1002641221 YES ACTIVE 50
6 1 14 +HZDW2019/rac/onlinelog/group_6.281.1002641273 NO CURRENT 50
7 2 7 +HZDW2019/rac/onlinelog/group_7.282.1002641301 NO CURRENT 50
8 2 4 +HZDW2019/rac/onlinelog/group_8.283.1002641311 YES INACTIVE 50
SQL>
需要注意的是:
1、每个实例必须至少有两个日志组;
2、当一个日志组处于ACTIVE或者CURRENT的状态时不可删除;
3、删除日志组的操作只对数据库进行更改,操作系统的文件尚未删除;
4、当删除时适用DROP LOGFILE GROUP N语句时,此时GROUP N内的所有成员都将被删除。