♣
题目部分
在Oracle中,将单实例备份集恢复为rac数据库的步骤有哪些?
♣
答案部分
将单实例备份集恢复为rac数据库的过程基本上就是先将备份集恢复为单实例的数据库,然后再将数据库转换为RAC库。
数据库的备份可以使用如下的脚本:
1run 2{ 3 allocate channel c1 type disk; 4 allocate channel c2 type disk; 5 backup database format '/home/oracle/rman_back/full_%n_%T_%t_%s_%p.bak'; 6 sql 'alter system archive log current'; 7 backup archivelog all format '/home/oracle/rman_back/arch_%d_%T_%s_%p.bak' delete input; 8 backup current controlfile format '/home/oracle/rman_back/ctl_%d_%T_%s_%p.bak'; 9 release channel c1; 10 release channel c2; 11} 12
将单实例备份集恢复为rac数据库常用的命令如下所示:
1ORACLE_SID=lhrdb 2ORACLE_SID=lhrrac21 3 4mkdir +DATA/lhrrac2/ 5startup nomount 6restore spfile to '+DATA/lhrrac2/spfilelhrrac2.ora' from '/home/oracle/rman_back/full_LHRDBxxx_20180711_981220001_4_1.bak'; 7 8/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initlhrrac21.ora 9SPFILE='+DATA/lhrrac2/spfilelhrrac2.ora' 10 11echo "SPFILE='+DATA/lhrrac2/spfilelhrrac2.ora'" > /u01/app/oracle/product/11.2.0/dbhome_1/dbs/initlhrrac22.ora 12 13 14create pfile='/tmp/a.txt' from spfile; 15*.audit_file_dest='/u01/app/oracle/admin/lhrdb/adump' 16*.audit_trail='db' 17*.compatible='11.2.0.0.0' 18*.control_files='+DATA','+FRA' 19*.db_block_size=8192 20*.db_domain='' 21*.db_name='lhrdb' 22*.db_recovery_file_dest='+FRA' 23*.db_recovery_file_dest_size=4322230272 24*.diagnostic_dest='/u01/app/oracle' 25*.dispatchers='(PROTOCOL=TCP) (SERVICE=lhrdbXDB)' 26*.memory_target=415236096 27*.open_cursors=300 28*.processes=150 29*.remote_login_passwordfile='EXCLUSIVE' 30*.undo_tablespace='UNDOTBS1' 31 32create spfile='+DATA/lhrrac2/spfilelhrrac2.ora' from pfile='/tmp/b.txt'; 33 34startup nomount force; 35restore controlfile from '/home/oracle/rman_back/ctl_LHRDB_20180711_7_1.bak'; 36alter database mount; 37 38set line 9999 pagesize 9999 39col FILE_NAME format a60 40select 'datafile' file_type, file#,name FILE_NAME,status,enabled from v$datafile 41union all 42select 'tempfile',file#,name FILE_NAME,status,enabled from v$tempfile 43union all 44select 'logfile',group# file#,member FILE_NAME,status,'' from v$logfile 45union all 46select 'controlfile', to_number('') ,name FILE_NAME,status,'' from v$controlfile; 47 48 49set pagesize 200 linesize 200 50select 'set newname for datafile ' || a.FILE# || ' to "' || a.NAME || '";' from v$datafile a 51union all 52select 'set newname for tempfile ' || a.FILE# || ' to "' || a.NAME || '";' from v$tempfile a 53union all 54SELECT 'SQL "ALTER DATABASE RENAME FILE ''''' || a.MEMBER || ''''' to ''''' || a.MEMBER || ''''' ";' FROM v$logfile a; 55 56 57 58set pagesize 200 linesize 200 59select 'set newname for datafile ' || a.FILE# || ' to "+DATA";' from v$datafile a 60union all 61select 'set newname for tempfile ' || a.FILE# || ' to "+DATA";' from v$tempfile a 62union all 63SELECT 'SQL "ALTER DATABASE RENAME FILE ''''' || a.MEMBER || ''''' to ''''+DATA'''' ";' FROM v$logfile a; 64 65 66set newname for datafile 1 to "+DATA"; 67set newname for datafile 2 to "+DATA"; 68set newname for datafile 3 to "+DATA"; 69set newname for datafile 4 to "+DATA"; 70set newname for datafile 5 to "+DATA"; 71set newname for tempfile 1 to "+DATA"; 72SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/lhrdb/redo03.log'' to ''+DATA'' "; 73SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/lhrdb/redo02.log'' to ''+DATA'' "; 74SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/lhrdb/redo01.log'' to ''+DATA'' "; 75 76 77 78run { 79 ALLOCATE CHANNEL c1 DEVICE TYPE DISK; 80 set newname for datafile 1 to "+DATA"; 81 set newname for datafile 2 to "+DATA"; 82 set newname for datafile 3 to "+DATA"; 83 set newname for datafile 4 to "+DATA"; 84 set newname for datafile 5 to "+DATA"; 85 set newname for tempfile 1 to "+DATA"; 86 SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/lhrdb/redo03.log'' to ''+DATA'' "; 87 SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/lhrdb/redo02.log'' to ''+DATA'' "; 88 SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/lhrdb/redo01.log'' to ''+DATA'' "; 89 restore database; 90 SWITCH DATAFILE ALL; 91 SWITCH TEMPFILE ALL; 92 release channel c1; 93 } 94 95list backupset of archivelog all; 96RUN{ 97set until sequence 6; 98recover database; 99} 100 101alter database open resetlogs; 102
以上步骤执行完后依然是一个单实例的数据库,因此需要将数据库转换为RAC库。需要修改集群参数,redo和undo的相关内容:
1select * from v$option where parameter = 'Real Application Clusters'; 2 3--集群参数 4alter system set cluster_database=true scope=spfile; 5alter system set cluster_database_instances=2 scope=spfile; 6 7alter system set instance_number=1 scope=spfile sid='lhrrac21'; 8alter system set instance_number=2 scope=spfile sid='lhrrac22'; 9 10--redo 11select THREAD# ,STATUS from v$thread; 12alter system set thread=1 scope=spfile sid='lhrrac21'; 13alter system set thread=2 scope=spfile sid='lhrrac22'; 14alter database add logfile thread 2 group 4 '+FRA' size 50M; 15alter database add logfile thread 2 group 5 '+FRA' size 50M; 16alter database add logfile thread 2 group 6 '+FRA' size 50M; 17 18col instance format a20 19select thread#,instance,status,enabled from v$thread; 20alter database enable thread 2 ; 21 22 23--undo 24create undo tablespace undotbs2 datafile '+DATA' SIZE 50m; 25alter system set undo_tablespace='undotbs1' scope=spfile sid='lhrrac21'; 26alter system set undo_tablespace='undotbs2' scope=spfile sid='lhrrac22'; 27show spparameter undo 28 29 30srvctl remove db -d lhrdb -f 31srvctl add database -d lhrdb -o $ORACLE_HOME -p +DATA/lhrrac2/spfilelhrrac2.ora 32srvctl config database -d lhrdb 33srvctl add instance -d lhrdb -i lhrrac21 -n raclhr-11gR2-N1 34srvctl add instance -d lhrdb -i lhrrac22 -n raclhr-11gR2-N2 35srvctl config database -d lhrdb 36srvctl start db -d lhrdb 37 38---重建集群相关的视图 39@$ORACLE_HOME/rdbms/admin/catclust.sql
& 说明:
有关将单实例备份集恢复为rac数据库的更多内容可以参考我的BLOG:http://blog.itpub.net/26736162/viewspace-1682250/。
本文选自《Oracle程序员面试笔试宝典》,作者:小麦苗
About Me:小麦苗
● 本文作者:小麦苗,只专注于数据库的技术,更注重技术的运用
● 作者博客地址:http://blog.itpub.net/26736162/abstract/1/
● 本系列题目来源于作者的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解
● 版权所有,欢迎分享本文,转载请保留出处
● QQ:646634621 QQ群:618766405
● 提供OCP、OCM和高可用部分最实用的技能培训
● 题目解答若有不当之处,还望各位朋友批评指正,共同进步
DBA宝典
长按下图识别二维码或微信扫描下图二维码来关注小麦苗的微信公众号:xiaomaimiaolhr,学习最实用的数据库技术。