标签:oracle
---创建asm实例 [oracle@edsir1p8-PROD4 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 22 09:48:03 2017 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to an idle instance. SQL> startup ORACLE instance started. Total System Global Area 129724416 bytes Fixed Size 1334996 bytes Variable Size 113246508 bytes Database Buffers 8388608 bytes Redo Buffers 6754304 bytes Database mounted. Database opened. ---查看当前数据库文件的形式 SQL> select name from v$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> select name from v$controlfile; NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/PROD4/PROD4/control01.ctl /u01/app/oracle/oradata/PROD4/PROD4/control02.ctl /home/oracle/control03.ctl SQL> select member from v$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> select name from v$tempfile; NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/PROD4/PROD4/temp01.dbf --都是文件系统形式 ---用rman进行拷贝文件(以asm的形式),需要asm实例的支持 ---在grid命令下 ---./asmca --1、确定归档时开着的 SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /home/oracle/arch Oldest online log sequence 24 Next log sequence to archive 26 Current log sequence 26 --2、copy 文件系统文件 格式为asm [oracle@edsir1p8-PROD4 ~]$ echo $ORACLE_SID PROD4 [oracle@edsir1p8-PROD4 ~]$ rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Thu Jun 22 09:59:38 2017 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: PROD4 (DBID=1612213667) RMAN> BACKUP as copy database format ‘+DATA‘; RMAN-03009: failure of backup command on ORA_DISK_1 channel at 06/25/2017 14:04:09 ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode ---归档没有开 SQL> archive log list; Database log mode No Archive Mode Automatic archival Disabled Archive destination /u01/app/oracle/product/11.2.0/db_1/dbs/arch Oldest online log sequence 5 Current log sequence SQL> shutdown immediate SQL> startup mount SQL> alter system set log_archive_dest_1=‘location=/home/oracle/arch‘; ---目录创建好 SQL> alter database archivelog; SQL> archive log list; SQL> alter database open; RMAN> BACKUP as copy database format ‘+DATA‘; ......... Finished backup at 22-JUN-17 --只会复制.dbf ,不会复制temp.dbf的文件 --进到asmcmd里面查看是否copy成功 [oracle@edsir1p8-+ASM ~]$ echo $ORACLE_SID +ASM [oracle@edsir1p8-+ASM ~]$ asmcmd ASMCMD> ls DATA/ DATA3/ ASMCMD> cd DATA ASMCMD> ls ASM/ PROD4/ ASMCMD> cd PROD4 ASMCMD> ls BACKUPSET/ CONTROLFILE/ DATAFILE/ ASMCMD> cd datafile 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> cd controlfile ASMCMD> pwd +data/prod4/controlfile ---参数文件里需要指定他的位置 ASMCMD> ls Backup.260.947325855 --创建一个表,模拟数据库在变化 --prod4操作: SQL> create table t1 as select * from dba_objects; Table created. ---切归档 SQL> alter system switch logfile; System altered. --指定控制文件,控制文件指向各种文件 --改参数文件,以这个文件启动数据库到mount [oracle@edsir1p8-PROD4 ~]$ vi bb.ora *.control_files=‘+data/prod4/controlfile/Backup.260.947325855‘ [oracle@edsir1p8-PROD4 ~]$ export ORACLE_SID=p4 --(随便的名字) ---只要文件对,用什么实例都能连进去 [oracle@edsir1p8-p4 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 22 10:30:27 2017 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to an idle instance SQL> startup mount pfile=‘/home/oralce/p4.ora‘; LRM-00109: could not open parameter file ‘/home/oralce/p4.ora‘ ORA-01078: failure in processing system parameters --原因: [oracle@edsir1p8-p4 ~]$ echo $ORACLE_HOME /u01/app/oracle/product/11.2.0/grid --解决: [root@edsir1p8 ~]# su - oracle [oracle@edsir1p8- ~]$ export ORACLE_SID=p4 [oracle@edsir1p8-p4 ~]$ echo $ORACLE_SID p4 [oracle@edsir1p8-p4 ~]$ sqlplus / as sysdba -bash: sqlplus: command not found [oracle@edsir1p8-p4 ~]$ . oraenv PROD4 ORACLE_SID = [p4] ? The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 is /u01/app/oracle [oracle@edsir1p8-p4 ~]$ . oraenv ORACLE_SID = [p4] ? PROD4 The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 is /u01/app/oracle [oracle@edsir1p8-PROD4 ~]$ export ORACLE_SID=p4 [oracle@edsir1p8-p4 ~]$ echo $ORACLE_SID p4 [oracle@edsir1p8-p4 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 22 11:04:00 2017 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to an idle instance. SQL> startup mount pfile=‘/home/oracle/p4.ora‘; ORACLE instance started. Total System Global Area 129724416 bytes Fixed Size 1334996 bytes Variable Size 83886380 bytes Database Buffers 37748736 bytes Redo Buffers 6754304 bytes ORA-01102: cannot mount database in exclusive mode ---单机只能有一个实例去开启一个文件 ----通过删文件解决 [oracle@edsir1p8-p4 ~]$ echo $ORACLE_HOME /u01/app/oracle/product/11.2.0/db_1 [oracle@edsir1p8-PROD4 dbs]$ pwd /u01/app/oracle/product/11.2.0/db_1/dbs [oracle@edsir1p8-PROD4 dbs]$ rm -fr lkPROD4 --这个会把实例锁起来 SQL> select name from v$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> catalog start with ‘+data‘; --将DATA备份集恢复 ---做文件的路径修改 RMAN> switch database to copy; datafile 1 switched to datafile copy "+DATA/prod4/datafile/system.257.947325691" datafile 2 switched to datafile copy "+DATA/prod4/datafile/sysaux.256.947325777" datafile 3 switched to datafile copy "+DATA/prod4/datafile/undotbs1.258.947325823" datafile 4 switched to datafile copy "+DATA/prod4/datafile/users.261.947325859" datafile 5 switched to datafile copy "+DATA/prod4/datafile/example.259.947325847" --数据库恢复,--会把归档里的内容做一遍 RMAN> recover database; SQL> select name from v$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 The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 is /u01/app/oracle [oracle@edsir1p8-PROD4 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 22 11:20:07 2017 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> shutdown immediate; ---注意关的位置,在open p4之前 [oracle@edsir1p8-PROD4 ~]$ export ORACLE_SID=p4 [oracle@edsir1p8-p4 ~]$ echo $ORACLE_SID p4 [oracle@edsir1p8-p4 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 22 11:21:18 2017 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options SQL> alter database open ; alter database open * ERROR at line 1: ORA-01589: must use RESETLOGS or NORESETLOGS option for database open SQL> alter database open resetlogs; Database altered. SQL> select name from v$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> select name from v$controlfile; NAME -------------------------------------------------------------------------------- +DATA/prod4/controlfile/backup.260.947325855 SQL> select member from v$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> alter database add logfile member ‘+data‘ to group 1; Database altered. SQL> alter database add logfile member ‘+data‘ to group 2; Database altered. SQL> alter database add logfile member ‘+data‘ to group 3; Database altered --2.切换日志 SQL> alter system switch logfile; System altered. SQL> / System altered. SQL> / System altered. --3、删除就的redo SQL> alter database drop logfile member ‘/u01/app/oracle/oradata/PROD4/PROD4/redo01.log‘; alter database drop logfile member ‘/u01/app/oracle/oradata/PROD4/PROD4/redo01.log‘ * ERROR at line 1: ORA-00362: member is required to form a valid logfile in group 1 ORA-01517: log member: ‘/u01/app/oracle/oradata/PROD4/PROD4/redo01.log‘ ---是因为没有切日志 SQL> alter database drop logfile member ‘/u01/app/oracle/oradata/PROD4/PROD4/redo01.log‘; Database altered. SQL> alter database drop logfile member ‘/u01/app/oracle/oradata/PROD4/PROD4/redo02.log‘; alter database drop logfile member ‘/u01/app/oracle/oradata/PROD4/PROD4/redo02.log‘ * ERROR at line 1: ORA-01609: log 2 is the current log for thread 1 - cannot drop members ORA-00312: online log 2 thread 1: ‘/u01/app/oracle/oradata/PROD4/PROD4/redo02.log‘ ORA-00312: online log 2 thread 1: ‘+DATA/prod4/onlinelog/group_2.264.947330771‘ --解决: --当前的redo,不能删,切 SQL> alter system switch logfile; System altered. SQL> alter database drop logfile member ‘/u01/app/oracle/oradata/PROD4/PROD4/redo02.log‘; Database altered. SQL> alter database drop logfile member ‘/u01/app/oracle/oradata/PROD4/PROD4/redo03.log‘; Database altered. --查看redolog SQL> select member from v$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> alter tablespace temp add tempfile ‘+DATA‘ size 20M; Tablespace altered. SQL> alter tablespace temp drop tempfile ‘/u01/app/oracle/oradata/PROD4/PROD4/temp 01.dbf‘; Tablespace altered. --查看tempfile SQL> select name from v$tempfile; NAME -------------------------------------------------------------------------------- +DATA/prod4/tempfile/temp.266.947331451 --查看创建的表是否存在 select count(*) from t1; SQL> create spfile from memory; File created. --关数据库 SQL> shutdown immediate; [oracle@edsir1p8-p4 db_1]$ cd dbs [oracle@edsir1p8-p4 dbs]$ ls hc_DBUA0.dat init.ora orapwEMREP peshm_EMREP_0 spfilePROD4.ora hc_EMREP.dat initPROD4.ora orapwPROD4 peshm_PROD4_0 hc_p4.dat lkEMREP peshm__0 spfileEMREP.ora hc_PROD4.dat lkPROD4 peshm_DBUA0_0 spfilep4.ora --一定注意PROD4的实例关掉 [oracle@edsir1p8-p4 dbs]$ mv spfilePROD4.ora spfilePROD4.ora.bak --p4实例关掉 [oracle@edsir1p8-p4 dbs]$ mv spfilep4.ora spfilePROD4.ora [oracle@edsir1p8-p4 dbs]$ pwd /u01/app/oracle/product/11.2.0/db_1/dbs [oracle@edsir1p8-p4 dbs]$ . oraenv ORACLE_SID = [p4] ? PROD4 The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 is /u01/app/oracle [oracle@edsir1p8-PROD4 dbs]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 22 11:43:47 2017 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to an idle instance. SQL> startup ORACLE instance started. Total System Global Area 129724416 bytes Fixed Size 1334996 bytes Variable Size 100663596 bytes Database Buffers 20971520 bytes Redo Buffers 6754304 bytes Database mounted. Database opened. --重新再查一遍 -----注意实例别用混了 SQL> show parameter control NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ _optimizer_extended_stats_usage_cont integer 224 rol _optimizer_join_order_control integer 3 control_file_record_keep_time integer 7 control_files string +DATA/prod4/controlfile/backup .260.947325855 control_management_pack_access string DIAGNOSTIC+TUNING SQL> select name from v$controlfile; NAME -------------------------------------------------------------------------------- +DATA/prod4/controlfile/backup.260.947325855 注意:在操作之前该关闭的要关闭,否则会报内部错误
本文出自 “yangwang” 博客,请务必保留此出处http://yangwang.blog.51cto.com/10855137/1943787
标签:oracle
原文地址:http://yangwang.blog.51cto.com/10855137/1943787