ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 用脚本重建控制文件

用脚本重建控制文件

原创 Linux操作系统 作者:ilsyx 时间:2012-06-17 00:17:14 0 删除 编辑

一 描述

本文参考官档资料"How to Recreate the Controlfile [ID 1012929.6]"做如下控制文件重建实验.虽然实验平台为Linux,在windows平台操作过程也一样.引用一下原文 :)

Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE

WARNING:

--------

You should only need to recreate your control file under very special

circumstances:

 - All current copies of the control file have been lost or are corrupted.

 - You need to change a "hard" database parameter that was set when the database was first created, such as MAXDATAFILES, MAXLOGFILES,MAXLOGHISTORY, etc.

 - You are restoring a backup in which the control file is corrupted or missing.

 - Oracle Customer Support advises you to do so.

 - If you are moving your database to another machine which is running the same operating system but the location of the datafiles,

logfiles is not the same.

二 操作环境

OS info

$lsb_release -a
LSB Version:    :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: EnterpriseEnterpriseServer
Description:    Enterprise Linux Enterprise Linux Server release 5.6 (Carthage)
Release:        5.6
Codename:       Carthage
$uname -a
Linux stu00 2.6.18-238.el5 #1 SMP Tue Jan 4 15:24:05 EST 2011 i686 i686 i386 GNU/Linux
$

DB info

$sqlplus / as sysdba <>
> set lines 150
> COL PRODUCT FORMAT A55
> COL VERSION FORMAT A15
> COL STATUS FORMAT A15
> SELECT * FROM PRODUCT_COMPONENT_VERSION;
> archive log list;
> EOF

SQL*Plus: Release 10.2.0.4.0 - Production on Fri Jun 15 16:13:39 2012

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, OLAP, Data Mining and Real Application Testing options

SQL> SQL> SQL> SQL> SQL> SQL>
PRODUCT                                                 VERSION         STATUS
------------------------------------------------------- --------------- ---------------
NLSRTL                                                  10.2.0.4.0      Production
Oracle Database 10g Enterprise Edition                  10.2.0.4.0      Prod
PL/SQL                                                  10.2.0.4.0      Production
TNS for Linux:                                          10.2.0.4.0      Production

SQL> Database log mode         Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     1
Next log sequence to archive   4
Current log sequence           4
SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
$

other

三 过程设计

Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONEI. CREATING A NEW CONTROL FILE FROM THE EXISTING CONTROL FILE

Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONEII. CREATING A NEW CONTROL FILE WITHOUT AN EXISTING CONTROL FILE
 (II前提数据库仅有数据文件的冷一致性备份其他参数文件,控制文件不在.此实验再做改变,重新创建参数文件,
重新命名数据库,重新创建控制文件.)

四 详细步骤操作

I 从已存在的controlfile创建出新建控制文件脚本

1.因为使用的是10g,所以以sysdba身份在sqlplus中运行备份控制文件到trace语句即可:
SQL> alter database backup controlfile to trace;

2.到USER_DUMP_DEST参数目录下打开最新修改时间的trace文件.例如
SQL> col value for a80
SQL> r
  1* select value from v$parameter where name ='user_dump_dest'

VALUE
--------------------------------------------------------------------------------
/u01/app/oracle/product/10.2.0/db_1/admin/testb/udump

SQL> !
$ls -lrt /u01/app/oracle/product/10.2.0/db_1/admin/testb/udump|tail -1
-rw-rw---- 1 oracle oracle   10180 Jun 15 16:30 testb_ora_3926.trc
$

3.显示相应trace文件内容:
$cat /u01/app/oracle/product/10.2.0/db_1/admin/testb/udump/testb_ora_3926.trc
--文件头信息
/u01/app/oracle/product/10.2.0/db_1/admin/testb/udump/testb_ora_3926.trc
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1
System name:    Linux
Node name:      stu00
Release:        2.6.18-238.el5
Version:        #1 SMP Tue Jan 4 15:24:05 EST 2011
Machine:        i686
Instance name: testb
Redo thread mounted by this instance: 1
Oracle process number: 23
Unix process pid: 3926, image: oracle@stu00 (TNS V1-V3)

--归档相关参数
*** ACTION NAME:() 2012-06-15 16:30:05.588
*** MODULE NAME:(sqlplus@stu00 (TNS V1-V3)) 2012-06-15 16:30:05.588
*** SERVICE NAME:(SYS$USERS) 2012-06-15 16:30:05.588
*** SESSION ID:(145.45) 2012-06-15 16:30:05.588
*** 2012-06-15 16:30:05.588
-- The following are current System-scope REDO Log Archival related
-- parameters and can be included in the database initialization file.
--
-- LOG_ARCHIVE_DEST=''
-- LOG_ARCHIVE_DUPLEX_DEST=''
--
-- LOG_ARCHIVE_FORMAT=%t_%s_%r.dbf
--
-- DB_UNIQUE_NAME="testb"
--
-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG'
-- LOG_ARCHIVE_MAX_PROCESSES=2
-- STANDBY_FILE_MANAGEMENT=MANUAL
-- STANDBY_ARCHIVE_DEST=?/dbs/arch
-- FAL_CLIENT=''
-- FAL_SERVER=''
--
-- LOG_ARCHIVE_DEST_10='LOCATION=USE_DB_RECOVERY_FILE_DEST'
-- LOG_ARCHIVE_DEST_10='OPTIONAL REOPEN=300 NODELAY'
-- LOG_ARCHIVE_DEST_10='ARCH NOAFFIRM NOEXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_10='REGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_10='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_10='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_10=ENABLE
--
--controlfile 重建脚本内容(两部分)
--
-- Below are two sets of SQL statements, each of which creates a new
-- control file and uses it to open the database. The first set opens
-- the database with the NORESETLOGS option and should be used only if
-- the current versions of all online logs are available. The second
-- set opens the database with the RESETLOGS option and should be used
-- if online logs are unavailable.
-- The appropriate set of statements can be copied from the trace into
-- a script. file, edited as necessary, and executed when there is a
-- need to re-create the control file.
--
--case 1 以noresetlogs的形式open数据库,此种情况适合所有redolog组都是有效的情况
--     Set #1. NORESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- Additional logs may be required for media recovery of offline
-- Use this only if the current versions of all online logs are
-- available.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "TESTB" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 20
    MAXLOGMEMBERS 3
    MAXDATAFILES 900
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo01a.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo1.log'
  ) SIZE 50M,
  GROUP 2 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo02b.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo02.log'
  ) SIZE 50M,
  GROUP 3 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo03.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo03b.log'
  ) SIZE 50M,
  GROUP 5 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo5.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo05b.log'
  ) SIZE 60M
-- STANDBY LOGFILE
DATAFILE
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/system01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/undotbstemp.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/sysaux01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/users01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/example01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/testb01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/testb02'
CHARACTER SET WE8ISO8859P1
;
-- Configure RMAN configuration record 1
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');
-- Configure RMAN configuration record 2
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE','DISK TO ''/home/oracle/ba                 ckup/%F''');
-- Configure RMAN configuration record 3
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('DEVICE TYPE','DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 2');
-- Configure RMAN configuration record 4
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CHANNEL','DEVICE TYPE DISK FORMAT   ''/home/oracle/backup/%U''');
-- Configure RMAN configuration record 5
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('RETENTION POLICY','TO REDUNDANCY 1');
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/backup_testb/TESTB/archivelog/2012_06_15/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/backup_testb/TESTB/archivelog/2012_06_15/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/backup_testb/TESTB/archivelog/2012_06_15/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/backup_testb/TESTB/archivelog/2012_06_15/o1_mf_1_1_%u_.arc';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE
-- All logs need archiving and a log switch is needed.
ALTER SYSTEM ARCHIVE LOG ALL;
-- Database can now be opened normally.
ALTER DATABASE OPEN;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/temp01.dbf'
     SIZE 31457280  REUSE AUTOEXTEND OFF;
-- End of tempfile additions.
--
--case 2 当redolog组被破坏后,使用resetlogs打开数据库.
--     Set #2. RESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "TESTB" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 20
    MAXLOGMEMBERS 3
    MAXDATAFILES 900
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo01a.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo1.log'
  ) SIZE 50M,
  GROUP 2 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo02b.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo02.log'
  ) SIZE 50M,
  GROUP 3 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo03.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo03b.log'
  ) SIZE 50M,
  GROUP 5 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo5.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo05b.log'
  ) SIZE 60M
-- STANDBY LOGFILE
DATAFILE
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/system01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/undotbstemp.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/sysaux01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/users01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/example01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/testb01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/testb02'
CHARACTER SET WE8ISO8859P1
;
-- Configure RMAN configuration record 1
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');
-- Configure RMAN configuration record 2
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE','DISK TO ''/home/oracle/ba                 ckup/%F''');
-- Configure RMAN configuration record 3
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('DEVICE TYPE','DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 2');
-- Configure RMAN configuration record 4
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CHANNEL','DEVICE TYPE DISK FORMAT   ''/home/oracle/backup/%U''');
-- Configure RMAN configuration record 5
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('RETENTION POLICY','TO REDUNDANCY 1');
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/backup_testb/TESTB/archivelog/2012_06_15/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/backup_testb/TESTB/archivelog/2012_06_15/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/backup_testb/TESTB/archivelog/2012_06_15/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/backup_testb/TESTB/archivelog/2012_06_15/o1_mf_1_1_%u_.arc';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE USING BACKUP CONTROLFILE
-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/temp01.dbf'
     SIZE 31457280  REUSE AUTOEXTEND OFF;
-- End of tempfile additions.
--
$

4.在原数据库的基础上,直接运行"Set #1. NORESETLOGS case"部分的脚本new_control.sql(将"Set #1. NORESETLOGS case"的内容另存为脚本new_control.sql),重建控制文件.
$cat new_control.sql
--     Set #1. NORESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- Additional logs may be required for media recovery of offline
-- Use this only if the current versions of all online logs are
-- available.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "TESTB" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 20
    MAXLOGMEMBERS 3
    MAXDATAFILES 900
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo01a.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo1.log'
  ) SIZE 50M,
  GROUP 2 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo02b.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo02.log'
  ) SIZE 50M,
  GROUP 3 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo03.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo03b.log'
  ) SIZE 50M,
  GROUP 5 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo5.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/redo05b.log'
  ) SIZE 60M
-- STANDBY LOGFILE
DATAFILE
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/system01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/undotbstemp.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/sysaux01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/users01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/example01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/testb01.dbf',
  '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/testb02'
CHARACTER SET WE8ISO8859P1
;
-- Configure RMAN configuration record 1
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');
-- Configure RMAN configuration record 2
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE','DISK TO ''/home/oracle/backup/%F''');
-- Configure RMAN configuration record 3
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('DEVICE TYPE','DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 2');
-- Configure RMAN configuration record 4
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CHANNEL','DEVICE TYPE DISK FORMAT   ''/home/oracle/backup/%U''');
-- Configure RMAN configuration record 5
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('RETENTION POLICY','TO REDUNDANCY 1');
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/backup_testb/TESTB/archivelog/2012_06_15/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/backup_testb/TESTB/archivelog/2012_06_15/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/backup_testb/TESTB/archivelog/2012_06_15/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/backup_testb/TESTB/archivelog/2012_06_15/o1_mf_1_1_%u_.arc';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE
-- All logs need archiving and a log switch is needed.
ALTER SYSTEM ARCHIVE LOG ALL;
-- Database can now be opened normally.
ALTER DATABASE OPEN;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/product/10.2.0/db_1/oradata/testb/temp01.dbf'
     SIZE 31457280  REUSE AUTOEXTEND OFF;
-- End of tempfile additions.

$sqlplus / as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on Fri Jun 15 23:52:12 2012

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> @new_control.sql
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1267068 bytes
Variable Size             125831812 bytes
Database Buffers          155189248 bytes
Redo Buffers                2924544 bytes

Control file created.


PL/SQL procedure successfully completed.


PL/SQL procedure successfully completed.


PL/SQL procedure successfully completed.


PL/SQL procedure successfully completed.


PL/SQL procedure successfully completed.

Media recovery complete.

System altered.


Database altered.


Tablespace altered.

SQL>

5. 因为控制文件是新创建的,以前的rman备份信息内容都已经清空.建议此时做一个全库备份.

II 目前只有数据库的冷备,而控制文件又丢失,需要自己手写参数文件,手写份控制文件重建脚本.

控制文件创建语法如下:

CREATE CONTROLFILE [REUSE] 
   DATABASE name  
   [LOGFILE filespec [, filespec] ...]   
    RESETLOGS | NORESETLOGS    
   [MAXLOGFILES integer]     
   [DATAFILE filespec [, filespec] ...]      
   [MAXDATAFILES integer]       
   [MAXINSTANCES integer]        
   [ARCHIVELOG | NOARCHIVELOG]         
   [SHARED | EXCLUSIVE]

更详细的创建控制文件语法内容参考 http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_5003.htm#i2061000

1.按照过程设计的步骤,在$ORACLE_HOME/dbs目录下创建一个新pfile出来,文件名为inittestbcb.ora. (原库pfile名字为inittestb., 新pfile名字为 testb cold backup 缩写)
列出inittestbcb.ora参数文件内容

$cat inittestbcb.ora
*.compatible='10.2.0.1.0'
*.control_files='/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/control01.ctl','/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/control02.ctl','/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/control03.ctl'
*.db_block_size=8192
*.db_name='testbcb'
*.undo_management='AUTO'
*.undo_tablespace='UNDOTEMP'
$


(注意相应的目录需要创建出来)

参数文件最小化参考文档:http://www.msgde.net/category/oracle_pfile_simple_10g.html

2.列出冷备数据文件(控制文件已经丢失,或者由于我们的实验目的而不存在了)
$ls /u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/
example01.dbf  redo02b.log  redo03b.log  redo05b.log  redo5.log     system01.dbf  testb01.dbf  undotbstemp.dbf
redo01a.log    redo02.log   redo03.log   redo1.log    sysaux01.dbf  temp01.dbf    testb02      users01.dbf
$

3.编写重建控制文件脚本 (new_control.sql)
$cat new_control.sql
CREATE CONTROLFILE REUSE SET DATABASE "TESTBCB" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 20
    MAXLOGMEMBERS 3
    MAXDATAFILES 900
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/redo01a.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/redo1.log'
  ) SIZE 50M,
  GROUP 2 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/redo02b.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/redo02.log'
  ) SIZE 50M,
  GROUP 3 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/redo03.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/redo03b.log'
  ) SIZE 50M,
  GROUP 5 (
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/redo5.log',
    '/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/redo05b.log'
  ) SIZE 60M
DATAFILE
'/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/example01.dbf',
'/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/sysaux01.dbf',
'/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/system01.dbf',
'/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/testb01.dbf',
'/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/testb02',
'/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/undotbstemp.dbf',
'/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/users01.dbf';

(加粗部分为要重要变动:重命令数据库需要set,同时resetlogs.数据文件中不需要temp临时文件)

4.启动数据库到nomount状态
$export ORACLE_SID=testbcb
$sqlplus / as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on Sat Jun 16 01:57:09 2012

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup nomount;
ORACLE instance started.

Total System Global Area  113246208 bytes
Fixed Size                  1266080 bytes
Variable Size              58723936 bytes
Database Buffers           50331648 bytes
Redo Buffers                2924544 bytes
SQL>

5.运行创建控制文件脚本.
SQL> @new_control.sql

Control file created.

SQL>

6.打开数据库(控制文件创建成功后数据库自动到mount状态)

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>

7.收尾 :)
将前6步需要补充的添上.如: pfile中内容很单一,数据库临时表空间没有包含在重建控制文件脚本中,各后台trace目录位置信息,归档位置,/etc/oratab中的数据库相关信息,compatible参数设置... ...
SQL> create spfile from pfile;

File created.

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/product/10.2.0/db_1/oradata/testbcb/temp01.dbf'
     SIZE 5M  REUSE AUTOEXTEND ON;  2

Tablespace altered.

SQL>
.... ... 各设置这里不一一设置了,想到什么补什么上来 :)

8.使用spfile重启数据库,然后做一个全备出来.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  113246208 bytes
Fixed Size                  1266080 bytes
Variable Size              58723936 bytes
Database Buffers           50331648 bytes
Redo Buffers                2924544 bytes
Database mounted.
Database opened.
SQL>

使用rman备份数据库
$rman target /

Recovery Manager: Release 10.2.0.4.0 - Production on Sat Jun 16 03:11:47 2012

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

ORACLE error from target database:
ORA-04031: unable to allocate 4112 bytes of shared memory ("shared pool","DBMS_RCVMAN","PL/SQL MPCODE","BAMIMA: Bam Buffer")
ORA-06508: PL/SQL: could not find program unit being called: "SYS.DBMS_RCVMAN"

error executing package DBMS_RCVMAN in TARGET database
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: initialization of internal recovery manager package failed
RMAN-06429: TARGET database is not compatible with this version of RMAN
$

查看官档 RMAN-06429的错误原因:The relevant message in this case is RMAN-06438 because package DBMS_RCVMAN   in target database is invalid.
解决,数据库重新编译相应包
@?/rdbms/admin/dbmsrman.sql
@?/rdbms/admin/prvtrmns.plb
错误没有解决. 再向上看错误.
ORA-04031 sharepool内存不足了. 关库,改参数:

SQL> shutdown immediate;

Package body created.

SQL>

Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> SQL> SQL>
SQL>
SQL>
SQL> startup nomount;
ORACLE instance started.

Total System Global Area 113246208 bytes
Fixed Size 1266080 bytes
Variable Size 58723936 bytes
Database Buffers 50331648 bytes
Redo Buffers 2924544 bytes
SQL> show parameter sga

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
lock_sga boolean FALSE
pre_page_sga boolean FALSE
sga_max_size big integer 108M
sga_target big integer 0
SQL> alter system set sga_max_size=800M scope=spfile;

System altered.

SQL> shutdown abort
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area 838860800 bytes
Fixed Size 1270268 bytes
Variable Size 784338436 bytes
Database Buffers 50331648 bytes
Redo Buffers 2920448 bytes
Database mounted.
Database opened.
SQL> alter system set sga_target =500M;

System altered.

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
$rman target /

Recovery Manager: Release 10.2.0.4.0 - Production on Sat Jun 16 07:29:17 2012

Copyright (c) 1982, 2007, Oracle. All rights reserved.

connected to target database: TESTBCB (DBID=298517861)

RMAN>


9.rman备份数据库(略)


五 个人总结

I 对知识点涉及到recover database与recover database using backup controlfile的区别,alter database open与alter database open resetlogs的区别.

II 内容相对操作很多,在仅有数据文件冷一致性备份的前提下,创建一个全新的pfile,创建全新的控制文件,还将数据库重命名.

这样两个简单实验,折腾出这么多的参考文档.每一次操作都不能小视.

做事一定要做到底,如果仅是把库打开为目的,没有后面的rman备库实验,那数据库参数还是在那放着,要是真到了生产运营数据库上,也够人憋一会的了.

六 资料参考引用

How to Recreate the Controlfile [ID 1012929.6]

Oracle® Database SQL Reference 10g Release 2 (10.2) Part Number B14200-02  --CREATE CONTROLFILE

http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_5003.htm#i2061000

Oracle10g 用pfile 启动最少的参数配置

http://www.msgde.net/category/oracle_pfile_simple_10g.html


RMAN-06429 TARGET Database is not Compatible with this Version of RMAN [ID 245698.1]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11780477/viewspace-733064/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-06-12

  • 博文量
    194
  • 访问量
    578728