如何查看Oracle11g控制檔案裡面的內容

來源:互聯網
上載者:User

如何查看Oracle11g控制檔案裡面的內容

控制檔案(Control File)是Oracle的物理檔案之一,它記錄了資料庫的名字、資料檔案的位置等資訊。控制檔案的重要性在於,一旦控制檔案損壞,資料庫將會宕機。控制檔案是一個很小的二進位檔案,使用者不能編輯控制檔案,控制檔案的修改由Oracle自動完成。那麼,我們能夠查看控制檔案裡面的具體資訊嗎?答案是可以的,我們可以通過轉儲檔案來獲得控制檔案的詳細資料。

1.產生控制檔案的轉儲檔案

SQL> select * from v$version;


BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production

SQL> alter database backup controlfile to trace ;

Database altered.

SQL>

2.尋找產生的轉儲檔案
我們知道,使用者產生的TRACE檔案儲存體在udump目錄下。在Oracle10g中,udump路徑是$ORACLE_HOME/admin/SID/udump,而Oracle11g則大不一樣。我們可以通過查看user_dump_dest參數來定位udump目錄的具體位置。

SQL> show parameter user_dump_dest

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
user_dump_dest string /u01/app/oracle/diag/rdbms/bkjia/HOEGH/trace
SQL>
然後,我們使用ls命令找到最近產生的TRACE檔案,就是圖示的bkjia_ora_304.trc檔案。

[oracle@bkjia trace]$ ls -ltr

total 1332
此處省略三百字
-rw-r----- 1 oracle oinstall 932 May 9 21:26 bkjia_mmon_4805.trm
-rw-r----- 1 oracle oinstall 9750 May 9 21:26 bkjia_mmon_4805.trc
-rw-r----- 1 oracle oinstall 4562 May 9 21:28 bkjia_dbrm_4789.trm
-rw-r----- 1 oracle oinstall 80534 May 9 21:28 bkjia_dbrm_4789.trc
-rw-r----- 1 oracle oinstall 97 May 9 21:29 bkjia_ora_304.trm
-rw-r----- 1 oracle oinstall 12786 May 9 21:29 bkjia_ora_304.trc
3.查看控制檔案具體資訊
現在,我們就可以通過more命令來查看控制檔案的具體資訊了。

[oracle@bkjia trace]$ more bkjia_ora_304.trc

Trace file /u01/app/oracle/diag/rdbms/bkjia/HOEGH/trace/bkjia_ora_304.trc
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1
System name: Linux
Node name: bkjia.example.com
Release: 2.6.18-164.el5PAE
Version: #1 SMP Thu Sep 3 02:28:20 EDT 2009
Machine: i686
VM name: VMWare Version: 6
Instance name: bkjia
Redo thread mounted by this instance: 1
Oracle process number: 26
Unix process pid: 304, image: oracle@bkjia.example.com (TNS V1-V3)

*** 2016-05-09 21:29:07.246
-- 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="bkjia"
--
-- 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=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
'

-- 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 "bkjia" NORESETLOGS NOARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u01/app/oracle/oradata/bkjia/redo01.log' SIZE 50M BLOCKSIZE 512,

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

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

-- STANDBY LOGFILE
DATAFILE
  '/u01/app/oracle/oradata/bkjia/system01.dbf',

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

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

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

  '/u01/app/oracle/oradata/bkjia/example01.dbf',

  '/u01/app/oracle/oradata/bkjia/test01.dbf'

CHARACTER SET AL32UTF8
;
-- 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/product/11.2.0/dbhome_1/dbs/
arch1_1_762197622.dbf';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
arch1_1_860888149.dbf';

-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE
-- 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/bkjia/temp01.dbf'

    SIZE 30408704 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
-- 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 "bkjia" RESETLOGS NOARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u01/app/oracle/oradata/bkjia/redo01.log' SIZE 50M BLOCKSIZE 512,

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

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

-- STANDBY LOGFILE
DATAFILE
  '/u01/app/oracle/oradata/bkjia/system01.dbf',

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

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

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

  '/u01/app/oracle/oradata/bkjia/example01.dbf',

  '/u01/app/oracle/oradata/bkjia/test01.dbf'

CHARACTER SET AL32UTF8
;
-- 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/product/11.2.0/dbhome_1/dbs/
arch1_1_762197622.dbf';

-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
arch1_1_860888149.dbf';

-- 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/bkjia/temp01.dbf

我們可以看到轉儲檔案裡包含了資料庫的名字、資料檔案的位置等資訊,並且按照是否需要resetlogs分別給出了建立控制檔案的sql語句。控制檔案非常重要,我們可以把它備份下來以防萬一。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.