---创建asm实例 [oracle@edsir1p8-PROD4~]$sqlplus/assysdba sql*Plus:Release11.2.0.1.0ProductiononThuJun2209:48:032017 Copyright(c)1982,2009,Oracle.Allrightsreserved. Connectedtoanidleinstance. sql>startup ORACLEinstancestarted. TotalSystemGlobalArea129724416bytes FixedSize1334996bytes VariableSize113246508bytes DatabaseBuffers8388608bytes RedoBuffers6754304bytes Databasemounted. DatabaSEOpened. ---查看当前数据库文件的形式 sql>selectnamefromv$datafile; NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/PROD4/PROD4/system01.dbf /u01/app/oracle/oradata/PROD4/PROD4/sysaux01.dbf /u01/app/oracle/oradata/PROD4/PROD4/undotbs01.dbf /u01/app/oracle/oradata/PROD4/PROD4/users01.dbf /u01/app/oracle/oradata/PROD4/PROD4/example01.dbf sql>selectnamefromv$controlfile; NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/PROD4/PROD4/control01.ctl /u01/app/oracle/oradata/PROD4/PROD4/control02.ctl /home/oracle/control03.ctl sql>selectmemberfromv$logfile; MEMBER -------------------------------------------------------------------------------- /u01/app/oracle/oradata/PROD4/PROD4/redo03.log /u01/app/oracle/oradata/PROD4/PROD4/redo02.log /u01/app/oracle/oradata/PROD4/PROD4/redo01.log sql>selectnamefromv$tempfile; NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/PROD4/PROD4/temp01.dbf --都是文件系统形式 ---用rman进行拷贝文件(以asm的形式),需要asm实例的支持 ---在grid命令下 ---./asmca --1、确定归档时开着的 sql>archiveloglist DatabaselogmodeArchiveMode AutomaticarchivalEnabled Archivedestination/home/oracle/arch Oldestonlinelogsequence24 Nextlogsequencetoarchive26 Currentlogsequence26 --2、copy文件系统文件格式为asm [oracle@edsir1p8-PROD4~]$echo$ORACLE_SID PROD4 [oracle@edsir1p8-PROD4~]$rmantarget/ RecoveryManager:Release11.2.0.1.0-ProductiononThuJun2209:59:382017 Copyright(c)1982,Oracleand/oritsaffiliates.Allrightsreserved. connectedtotargetdatabase:PROD4(DBID=1612213667) RMAN>BACKUPascopydatabaseformat'+DATA'; RMAN-03009:failureofbackupcommandonORA_DISK_1channelat06/25/201714:04:09 ORA-19602:cannotbackuporcopyactivefileinNOARCHIVELOGmode---归档没有开 sql>archiveloglist; DatabaselogmodeNoArchiveMode AutomaticarchivalDisabled Archivedestination/u01/app/oracle/product/11.2.0/db_1/dbs/arch Oldestonlinelogsequence5 Currentlogsequence sql>shutdownimmediate sql>startupmount sql>altersystemsetlog_archive_dest_1='location=/home/oracle/arch';---目录创建好 sql>alterdatabasearchivelog; sql>archiveloglist; sql>alterdatabaSEOpen; RMAN>BACKUPascopydatabaseformat'+DATA'; ......... Finishedbackupat22-JUN-17 --只会复制.dbf,不会复制temp.dbf的文件 --进到asmcmd里面查看是否copy成功 [oracle@edsir1p8-+ASM~]$echo$ORACLE_SID +ASM [oracle@edsir1p8-+ASM~]$asmcmd ASMCMD>ls DATA/ DATA3/ ASMCMD>cdDATA ASMCMD>ls ASM/ PROD4/ ASMCMD>cdPROD4 ASMCMD>ls BACKUPSET/ CONTROLFILE/ DATAFILE/ ASMCMD>cddatafile ASMCMD>ls EXAMPLE.259.947325847 SYSAUX.256.947325777 SYSTEM.257.947325691 UNDOTBS1.258.947325823 USERS.261.947325859 ASMCMD>pwd +DATA/PROD4/datafile--需要用到 ASMCMD>cd.. ASMCMD>ls BACKUPSET/ CONTROLFILE/ DATAFILE/ ASMCMD>cdcontrolfile ASMCMD>pwd +data/prod4/controlfile---参数文件里需要指定他的位置 ASMCMD>ls Backup.260.947325855 --创建一个表,模拟数据库在变化 --prod4操作: sql>createtablet1asselect*fromdba_objects; Tablecreated. ---切归档 sql>altersystemswitchlogfile; Systemaltered. --指定控制文件,控制文件指向各种文件 --改参数文件,以这个文件启动数据库到mount [oracle@edsir1p8-PROD4~]$vibb.ora *.control_files='+data/prod4/controlfile/Backup.260.947325855' [oracle@edsir1p8-PROD4~]$exportORACLE_SID=p4--(随便的名字) ---只要文件对,用什么实例都能连进去 [oracle@edsir1p8-p4~]$sqlplus/assysdba sql*Plus:Release11.2.0.1.0ProductiononThuJun2210:30:272017 Copyright(c)1982,Oracle.Allrightsreserved. Connectedtoanidleinstance sql>startupmountpfile='/home/oralce/p4.ora'; LRM-00109:couldnotopenparameterfile'/home/oralce/p4.ora' ORA-01078:failureinprocessingsystemparameters --原因: [oracle@edsir1p8-p4~]$echo$ORACLE_HOME /u01/app/oracle/product/11.2.0/grid --解决: [root@edsir1p8~]#su-oracle [oracle@edsir1p8-~]$exportORACLE_SID=p4 [oracle@edsir1p8-p4~]$echo$ORACLE_SID p4 [oracle@edsir1p8-p4~]$sqlplus/assysdba -bash:sqlplus:commandnotfound [oracle@edsir1p8-p4~]$.oraenvPROD4 ORACLE_SID=[p4]? TheOraclebaseforORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1is/u01/app/oracle [oracle@edsir1p8-p4~]$.oraenv ORACLE_SID=[p4]?PROD4 TheOraclebaseforORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1is/u01/app/oracle [oracle@edsir1p8-PROD4~]$exportORACLE_SID=p4 [oracle@edsir1p8-p4~]$echo$ORACLE_SID p4 [oracle@edsir1p8-p4~]$sqlplus/assysdba sql*Plus:Release11.2.0.1.0ProductiononThuJun2211:04:002017 Copyright(c)1982,Oracle.Allrightsreserved. Connectedtoanidleinstance. sql>startupmountpfile='/home/oracle/p4.ora'; ORACLEinstancestarted. TotalSystemGlobalArea129724416bytes FixedSize1334996bytes VariableSize83886380bytes DatabaseBuffers37748736bytes RedoBuffers6754304bytes ORA-01102:cannotmountdatabaseinexclusivemode---单机只能有一个实例去开启一个文件 ----通过删文件解决 [oracle@edsir1p8-p4~]$echo$ORACLE_HOME /u01/app/oracle/product/11.2.0/db_1 [oracle@edsir1p8-PROD4dbs]$pwd /u01/app/oracle/product/11.2.0/db_1/dbs [oracle@edsir1p8-PROD4dbs]$rm-frlkPROD4--这个会把实例锁起来 sql>selectnamefromv$datafile; NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/PROD4/PROD4/system01.dbf /u01/app/oracle/oradata/PROD4/PROD4/sysaux01.dbf /u01/app/oracle/oradata/PROD4/PROD4/undotbs01.dbf /u01/app/oracle/oradata/PROD4/PROD4/users01.dbf /u01/app/oracle/oradata/PROD4/PROD4/example01.dbf --在rman里改 [oracle@edsir1p8-p4~]$echo$ORACLE_SID p4 [oracle@edsir1p8-p4~]$echo$ORACLE_HOME /u01/app/oracle/product/11.2.0/db_1 --从备份中拷贝 RMAN>catalogstartwith'+data';--将DATA备份集恢复 ---做文件的路径修改 RMAN>switchdatabasetocopy; datafile1switchedtodatafilecopy"+DATA/prod4/datafile/system.257.947325691" datafile2switchedtodatafilecopy"+DATA/prod4/datafile/sysaux.256.947325777" datafile3switchedtodatafilecopy"+DATA/prod4/datafile/undotbs1.258.947325823" datafile4switchedtodatafilecopy"+DATA/prod4/datafile/users.261.947325859" datafile5switchedtodatafilecopy"+DATA/prod4/datafile/example.259.947325847" --数据库恢复,--会把归档里的内容做一遍 RMAN>recoverdatabase; sql>selectnamefromv$datafile; NAME -------------------------------------------------------------------------------- +DATA/prod4/datafile/system.257.947325691 +DATA/prod4/datafile/sysaux.256.947325777 +DATA/prod4/datafile/undotbs1.258.947325823 +DATA/prod4/datafile/users.261.947325859 +DATA/prod4/datafile/example.259.947325847 ---然后关生产库 [oracle@edsir1p8-p4~]$.oraenv ORACLE_SID=[p4]?PROD4 TheOraclebaseforORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1is/u01/app/oracle [oracle@edsir1p8-PROD4~]$sqlplus/assysdba sql*Plus:Release11.2.0.1.0ProductiononThuJun2211:20:072017 Copyright(c)1982,Oracle.Allrightsreserved. Connectedto: OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-Production WiththePartitioning,OLAP,DataMiningandRealApplicationTestingoptions sql>shutdownimmediate;---注意关的位置,在openp4之前 [oracle@edsir1p8-PROD4~]$exportORACLE_SID=p4 [oracle@edsir1p8-p4~]$echo$ORACLE_SID p4 [oracle@edsir1p8-p4~]$sqlplus/assysdba sql*Plus:Release11.2.0.1.0ProductiononThuJun2211:21:182017 Copyright(c)1982,AutomaticStorageManagement,DataMining andRealApplicationTestingoptions sql>alterdatabaSEOpen; alterdatabaSEOpen * ERRORatline1: ORA-01589:mustuseRESETLOGSorNORESETLOGSoptionfordatabaSEOpen sql>alterdatabaSEOpenresetlogs; Databasealtered. sql>selectnamefromv$datafile; NAME -------------------------------------------------------------------------------- +DATA/prod4/datafile/system.257.947325691 +DATA/prod4/datafile/sysaux.256.947325777 +DATA/prod4/datafile/undotbs1.258.947325823 +DATA/prod4/datafile/users.261.947325859 +DATA/prod4/datafile/example.259.947325847 sql>selectnamefromv$controlfile; NAME -------------------------------------------------------------------------------- +DATA/prod4/controlfile/backup.260.947325855 sql>selectmemberfromv$logfile; MEMBER -------------------------------------------------------------------------------- /u01/app/oracle/oradata/PROD4/PROD4/redo03.log /u01/app/oracle/oradata/PROD4/PROD4/redo02.log /u01/app/oracle/oradata/PROD4/PROD4/redo01.log -----还不是 --1.添加redo日志 sql>alterdatabaseaddlogfilemember'+data'togroup1; Databasealtered. sql>alterdatabaseaddlogfilemember'+data'togroup2; Databasealtered. sql>alterdatabaseaddlogfilemember'+data'togroup3; Databasealtered --2.切换日志 sql>altersystemswitchlogfile; Systemaltered. sql>/ Systemaltered. sql>/ Systemaltered. --3、删除就的redo sql>alterdatabasedroplogfilemember'/u01/app/oracle/oradata/PROD4/PROD4/redo01.log'; alterdatabasedroplogfilemember'/u01/app/oracle/oradata/PROD4/PROD4/redo01.log' * ERRORatline1: ORA-00362:memberisrequiredtoformavalidlogfileingroup1 ORA-01517:logmember:'/u01/app/oracle/oradata/PROD4/PROD4/redo01.log' ---是因为没有切日志 sql>alterdatabasedroplogfilemember'/u01/app/oracle/oradata/PROD4/PROD4/redo01.log'; Databasealtered. sql>alterdatabasedroplogfilemember'/u01/app/oracle/oradata/PROD4/PROD4/redo02.log'; alterdatabasedroplogfilemember'/u01/app/oracle/oradata/PROD4/PROD4/redo02.log' * ERRORatline1: ORA-01609:log2isthecurrentlogforthread1-cannotdropmembers ORA-00312:onlinelog2thread1: '/u01/app/oracle/oradata/PROD4/PROD4/redo02.log' ORA-00312:onlinelog2thread1:'+DATA/prod4/onlinelog/group_2.264.947330771' --解决: --当前的redo,不能删,切 sql>altersystemswitchlogfile; Systemaltered. sql>alterdatabasedroplogfilemember'/u01/app/oracle/oradata/PROD4/PROD4/redo02.log'; Databasealtered. sql>alterdatabasedroplogfilemember'/u01/app/oracle/oradata/PROD4/PROD4/redo03.log'; Databasealtered. --查看redolog sql>selectmemberfromv$logfile; MEMBER -------------------------------------------------------------------------------- +DATA/prod4/onlinelog/group_1.263.947330761 +DATA/prod4/onlinelog/group_2.264.947330771 +DATA/prod4/onlinelog/group_3.265.947330777 --解决tmp.dbf sql>altertablespacetempaddtempfile'+DATA'size20M; Tablespacealtered. sql>altertablespacetempdroptempfile'/u01/app/oracle/oradata/PROD4/PROD4/temp 01.dbf'; Tablespacealtered. --查看tempfile sql>selectnamefromv$tempfile; NAME -------------------------------------------------------------------------------- +DATA/prod4/tempfile/temp.266.947331451 --查看创建的表是否存在 selectcount(*)fromt1; sql>createspfilefrommemory; Filecreated. --关数据库 sql>shutdownimmediate; [oracle@edsir1p8-p4db_1]$cddbs [oracle@edsir1p8-p4dbs]$ls hc_DBUA0.datinit.oraorapwEMREPpeshm_EMREP_0spfilePROD4.ora hc_EMREP.datinitPROD4.oraorapwPROD4peshm_PROD4_0 hc_p4.datlkEMREPpeshm__0spfileEMREP.ora hc_PROD4.datlkPROD4peshm_DBUA0_0spfilep4.ora --一定注意PROD4的实例关掉 [oracle@edsir1p8-p4dbs]$mvspfilePROD4.oraspfilePROD4.ora.bak --p4实例关掉 [oracle@edsir1p8-p4dbs]$mvspfilep4.oraspfilePROD4.ora [oracle@edsir1p8-p4dbs]$pwd /u01/app/oracle/product/11.2.0/db_1/dbs [oracle@edsir1p8-p4dbs]$.oraenv ORACLE_SID=[p4]?PROD4 TheOraclebaseforORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1is/u01/app/oracle [oracle@edsir1p8-PROD4dbs]$sqlplus/assysdba sql*Plus:Release11.2.0.1.0ProductiononThuJun2211:43:472017 Copyright(c)1982,Oracle.Allrightsreserved. Connectedtoanidleinstance. sql>startup ORACLEinstancestarted. TotalSystemGlobalArea129724416bytes FixedSize1334996bytes VariableSize100663596bytes DatabaseBuffers20971520bytes RedoBuffers6754304bytes Databasemounted. DatabaSEOpened. --重新再查一遍 -----注意实例别用混了 sql>showparametercontrol NAMETYPEVALUE ----------------------------------------------------------------------------- _optimizer_extended_stats_usage_continteger224 rol _optimizer_join_order_controlinteger3 control_file_record_keep_timeinteger7 control_filesstring+DATA/prod4/controlfile/backup .260.947325855 control_management_pack_accessstringDIAGNOSTIC+TUNING sql>selectnamefromv$controlfile; NAME -------------------------------------------------------------------------------- +DATA/prod4/controlfile/backup.260.947325855 注意:在操作之前该关闭的要关闭,否则会报内部错误