Oracle 重建控制文件

   

前些天在作Oracle數據庫恢復測試時,由於一些異常操做致使控制文件出了問題,數據庫沒法正常使用,這裏記錄一下重建控制文件的操做 html

   

1、使用sysdba用戶登入數據庫 node

   

此時普通用戶已沒法連接數據庫 sql

   

2、啓動數據庫到mount狀態 數據庫

   

此時能夠看出異常來源:因爲控制文件中的實例名與實例自己實例名不一致致使數據庫實例沒法正常啓用 session

   

3、獲取建立控制文件的腳本格式 oracle

   

Oracle中咱們能夠經過 alter database backup controlfile to trace; 命令獲取控制文件的建立方法,但因爲此時實例ORCL上的控制文件已經出現異常,咱們沒法在這個實例上獲取.trc文件;不過咱們可使用這條命令在其餘正常的實例上獲取此文件,並根據實際狀況建立重建控制文件的腳本。一下是具體方法: app

   

獲取文件,重命名並保存到/tmp目錄下,方便查看 ide

 

 1 [oracle@node00 ~]$ sqlplus / as sysdba
 2 
 3    
 4 
 5 SQL*Plus: Release 11.2.0.4.0 Production on 星期四 3月 9 16:45:50 2017
 6 
 7    
 8 
 9 Copyright (c) 1982, 2013, Oracle. All rights reserved.
10 
11    
12 
13    
14 
15 Connected to:
16 
17 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
18 
19 With the Partitioning, OLAP, Data Mining and Real Application Testing options
20 
21    
22 
23 SQL> alter database backup controlfile to trace as '/tmp/control_rebuild.trc'
24 
25 2 ;
26 
27    
28 
29 Database altered.

 

   

查看重建控制文件的格式 測試

[oracle@node00 ~]$ more /tmp/control_rebuild.trc優化

 

-- 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="node00"

--

-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG'

-- LOG_ARCHIVE_MAX_PROCESSES=4

-- STANDBY_FILE_MANAGEMENT=MANUAL

-- STANDBY_ARCHIVE_DEST=?/dbs/arch

-- FAL_CLIENT=''

-- FAL_SERVER=''

--

-- LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST'

-- LOG_ARCHIVE_DEST_1='MANDATORY NOREOPEN NODELAY'

-- LOG_ARCHIVE_DEST_1='ARCH NOAFFIRM EXPEDITE NOVERIFY SYNC'

-- LOG_ARCHIVE_DEST_1='NOREGISTER NOALTERNATE NODEPENDENCY'

-- LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'

-- LOG_ARCHIVE_DEST_1='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'

-- LOG_ARCHIVE_DEST_STATE_1=ENABLE

   

--

-- 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.

--

-- 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 "NODE00" NORESETLOGS ARCHIVELOG

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 292

LOGFILE

GROUP 1 '/u01/app/oracle/oradata/node00/redo01.log' SIZE 50M BLOCKSIZE 512,

GROUP 2 '/u01/app/oracle/oradata/node00/redo02.log' SIZE 50M BLOCKSIZE 512,

GROUP 3 '/u01/app/oracle/oradata/node00/redo03.log' SIZE 50M BLOCKSIZE 512

-- STANDBY LOGFILE

DATAFILE

'/u01/app/oracle/oradata/node00/system01.dbf',

'/u01/app/oracle/oradata/node00/sysaux01.dbf',

'/u01/app/oracle/oradata/node00/undotbs01.dbf',

'/u01/app/oracle/oradata/node00/users01.dbf',

'/u01/app/oracle/oradata/test001.dbf'

CHARACTER SET AL32UTF8

;

   

-- Configure RMAN configuration record 1

VARIABLE RECNO NUMBER;

EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');

-- 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 '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/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/oradata/node00/temp01.dbf'

SIZE 61865984 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;

ALTER TABLESPACE TEMP001 ADD TEMPFILE '/u01/app/oracle/oradata/temp001.dbf'

SIZE 209715200 REUSE AUTOEXTEND ON NEXT 33554432 MAXSIZE 2048M;

-- End of tempfile additions.

--

-- 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 "NODE00" RESETLOGS ARCHIVELOG

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 292

LOGFILE

GROUP 1 '/u01/app/oracle/oradata/node00/redo01.log' SIZE 50M BLOCKSIZE 512,

GROUP 2 '/u01/app/oracle/oradata/node00/redo02.log' SIZE 50M BLOCKSIZE 512,

GROUP 3 '/u01/app/oracle/oradata/node00/redo03.log' SIZE 50M BLOCKSIZE 512

-- STANDBY LOGFILE

DATAFILE

'/u01/app/oracle/oradata/node00/system01.dbf',

'/u01/app/oracle/oradata/node00/sysaux01.dbf',

'/u01/app/oracle/oradata/node00/undotbs01.dbf',

'/u01/app/oracle/oradata/node00/users01.dbf',

'/u01/app/oracle/oradata/test001.dbf'

CHARACTER SET AL32UTF8

;

   

-- Configure RMAN configuration record 1

VARIABLE RECNO NUMBER;

EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');

-- 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 '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/o1_mf_1_1_%u_.arc';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/NODE00/archivelog/2017_03_09/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/oradata/node00/temp01.dbf'

SIZE 61865984 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;

ALTER TABLESPACE TEMP001 ADD TEMPFILE '/u01/app/oracle/oradata/temp001.dbf'

SIZE 209715200 REUSE AUTOEXTEND ON NEXT 33554432 MAXSIZE 2048M;

-- End of tempfile additions.

--
View Code

 

 

 

因爲咱們這裏不須要重作重作日誌,因此選擇第一種方法。而後根據ORCL實例的重作日誌和表空間路徑,寫出重建控制文件的腳本。

   

   

STARTUP NOMOUNT

CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS ARCHIVELOG

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 292

LOGFILE

GROUP 1 '/u01/app/oracle/oradata/orcl/redo01.log' SIZE 50M ,

GROUP 2 '/u01/app/oracle/oradata/orcl/redo02.log' SIZE 50M ,

GROUP 3 '/u01/app/oracle/oradata/orcl/redo03.log' SIZE 50M

DATAFILE

'/u01/app/oracle/oradata/orcl/system01.dbf',

'/u01/app/oracle/oradata/orcl/sysaux01.dbf',

'/u01/app/oracle/oradata/orcl/undotbs01.dbf',

'/u01/app/oracle/oradata/orcl/users01.dbf',

'/u01/app/oracle/oradata/orcl/test01.dbf',

'/u01/app/oracle/oradata/test001.dbf',

'/u01/app/oracle/oradata/test1.dbf',

'/u01/app/oracle/oradata/test2.dbf',

CHARACTER SET AL32UTF8

;

VARIABLE RECNO NUMBER;

RECOVER DATABASE

ALTER SYSTEM ARCHIVE LOG ALL;

ALTER DATABASE OPEN;

ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf'

SIZE 61865984 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;

 

   

注意:控制文件中不包含臨時表空間

   

4、運行腳本

 

[oracle@node0 orcl]$ sqlplus / as sysdba

   

SQL*Plus: Release 11.2.0.4.0 Production on Thu Mar 9 17:41:24 2017

   

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options 

SQL> shutdown immediate;

ORA-01507: database not mounted

    

ORACLE instance shut down.

SQL> set echo on

SQL> @rebuild

SQL> STARTUP NOMOUNT

ORACLE instance started.

   

Total System Global Area 839282688 bytes

Fixed Size                 2257880 bytes

Variable Size                 507513896 bytes

Database Buffers         327155712 bytes

Redo Buffers                 2355200 bytes

SQL> CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS ARCHIVELOG

2          MAXLOGFILES 16

3          MAXLOGMEMBERS 3

4          MAXDATAFILES 100

5          MAXINSTANCES 8

6          MAXLOGHISTORY 292

7 LOGFILE

8 GROUP 1 '/u01/app/oracle/oradata/orcl/redo01.log' SIZE 50M ,

9 GROUP 2 '/u01/app/oracle/oradata/orcl/redo02.log' SIZE 50M ,

10 GROUP 3 '/u01/app/oracle/oradata/orcl/redo03.log' SIZE 50M

11 DATAFILE

12 '/u01/app/oracle/oradata/orcl/system01.dbf',

13 '/u01/app/oracle/oradata/orcl/sysaux01.dbf',

14 '/u01/app/oracle/oradata/orcl/undotbs01.dbf',

15 '/u01/app/oracle/oradata/orcl/users01.dbf',

16 '/u01/app/oracle/oradata/orcl/test01.dbf',

17 '/u01/app/oracle/oradata/test001.dbf',

18 '/u01/app/oracle/oradata/test1.dbf',

19 '/u01/app/oracle/oradata/test2.dbf',

20 CHARACTER SET AL32UTF8

21 ;

CHARACTER SET AL32UTF8

*

ERROR at line 20:

ORA-02236: invalid file name

出錯了,貌似是這裏不能設置字符集(數據庫版本是11.2.0.4),刪除這條命令後就沒有影響了。(知道具體緣由的請賜教)

[oracle@node0 orcl]$ sqlplus / as sysdba

   

SQL*Plus: Release 11.2.0.4.0 Production on Thu Mar 9 18:29:43 2017

   

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

   

   

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

   

SQL> @rebuild

SQL> SHUTDOWN ABORT;

ORACLE instance shut down.

SQL> STARTUP NOMOUNT;

ORACLE instance started.

   

Total System Global Area 839282688 bytes

Fixed Size                 2257880 bytes

Variable Size                 507513896 bytes

Database Buffers         327155712 bytes

Redo Buffers                 2355200 bytes

SQL> CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS ARCHIVELOG

2          MAXLOGFILES 16

3          MAXLOGMEMBERS 3

4          MAXDATAFILES 100

5          MAXINSTANCES 8

6          MAXLOGHISTORY 292

7 LOGFILE

8 GROUP 1 '/u01/app/oracle/oradata/orcl/redo01.log' SIZE 50M ,

9 GROUP 2 '/u01/app/oracle/oradata/orcl/redo02.log' SIZE 50M ,

10 GROUP 3 '/u01/app/oracle/oradata/orcl/redo03.log' SIZE 50M

11 DATAFILE

12 '/u01/app/oracle/oradata/orcl/system01.dbf',

13 '/u01/app/oracle/oradata/orcl/sysaux01.dbf',

14 '/u01/app/oracle/oradata/orcl/undotbs01.dbf',

15 '/u01/app/oracle/oradata/orcl/users01.dbf',

16 '/u01/app/oracle/oradata/orcl/test01.dbf',

17 '/u01/app/oracle/oradata/test001.dbf',

18 '/u01/app/oracle/oradata/test1.dbf',

19 '/u01/app/oracle/oradata/test2.dbf';

Control file created.

   

SQL> VARIABLE RECNO NUMBER;

SQL> RECOVER DATABASE

ORA-00283: recovery session canceled due to errors

ORA-00264: no recovery required

   

   

SQL> ALTER SYSTEM ARCHIVE LOG ALL;

   

System altered.

   

SQL> ALTER DATABASE OPEN;

   

Database altered.

   

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf'

2          SIZE 61865984 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;

   

Tablespace altered.

   

SQL> conn test001/shuyi123

Connected.  

至此,數據庫恢復正常。

-------------------------------------------------------------------------------

最後優化一下腳本

SET ECHO ON

SHUTDOWN ABORT;

STARTUP NOMOUNT;

CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS ARCHIVELOG

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 292

LOGFILE

GROUP 1 '/u01/app/oracle/oradata/orcl/redo01.log' SIZE 50M ,

GROUP 2 '/u01/app/oracle/oradata/orcl/redo02.log' SIZE 50M ,

GROUP 3 '/u01/app/oracle/oradata/orcl/redo03.log' SIZE 50M

DATAFILE

'/u01/app/oracle/oradata/orcl/system01.dbf',

'/u01/app/oracle/oradata/orcl/sysaux01.dbf',

'/u01/app/oracle/oradata/orcl/undotbs01.dbf',

'/u01/app/oracle/oradata/orcl/users01.dbf',

'/u01/app/oracle/oradata/orcl/test01.dbf',

'/u01/app/oracle/oradata/test001.dbf',

'/u01/app/oracle/oradata/test1.dbf',

'/u01/app/oracle/oradata/test2.dbf';

VARIABLE RECNO NUMBER;

ALTER SYSTEM ARCHIVE LOG ALL;

ALTER DATABASE OPEN;

ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf'

SIZE 61865984 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;

--------------------------------------------------------------------------------------------------------------------------------

參考文檔:http://www.eygle.com/archives/2004/10/backup_and_recreate_controlfile.html

相關文章
相關標籤/搜索