阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

如何查看Oracle11g控制文件里面的内容

174次阅读
没有评论

共计 7348 个字符,预计需要花费 19 分钟才能阅读完成。

控制文件(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/linuxidc/HOEGH/trace
SQL>
然后,我们使用 ls 命令找到最近生成的 TRACE 文件,就是图示的 linuxidc_ora_304.trc 文件。

[oracle@linuxidc trace]$ ls -ltr

total 1332
此处省略三百字
-rw-r—– 1 oracle oinstall 932 May 9 21:26 linuxidc_mmon_4805.trm
-rw-r—– 1 oracle oinstall 9750 May 9 21:26 linuxidc_mmon_4805.trc
-rw-r—– 1 oracle oinstall 4562 May 9 21:28 linuxidc_dbrm_4789.trm
-rw-r—– 1 oracle oinstall 80534 May 9 21:28 linuxidc_dbrm_4789.trc
-rw-r—– 1 oracle oinstall 97 May 9 21:29 linuxidc_ora_304.trm
-rw-r—– 1 oracle oinstall 12786 May 9 21:29 linuxidc_ora_304.trc
3. 查看控制文件具体信息
现在,我们就可以通过 more 命令来查看控制文件的具体信息了。

[oracle@linuxidc trace]$ more linuxidc_ora_304.trc

Trace file /u01/app/oracle/diag/rdbms/linuxidc/HOEGH/trace/linuxidc_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: linuxidc.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: linuxidc
Redo thread mounted by this instance: 1
Oracle process number: 26
Unix process pid: 304, image: oracle@linuxidc.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=”linuxidc”

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

  GROUP 2 ‘/u01/app/oracle/oradata/linuxidc/redo02.log’ SIZE 50M BLOCKSIZE 512,

  GROUP 3 ‘/u01/app/oracle/oradata/linuxidc/redo03.log’ SIZE 50M BLOCKSIZE 512

— STANDBY LOGFILE
DATAFILE
  ‘/u01/app/oracle/oradata/linuxidc/system01.dbf’,

  ‘/u01/app/oracle/oradata/linuxidc/sysaux01.dbf’,

  ‘/u01/app/oracle/oradata/linuxidc/undotbs01.dbf’,

  ‘/u01/app/oracle/oradata/linuxidc/users01.dbf’,

  ‘/u01/app/oracle/oradata/linuxidc/example01.dbf’,

  ‘/u01/app/oracle/oradata/linuxidc/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/linuxidc/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 “linuxidc” RESETLOGS NOARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 ‘/u01/app/oracle/oradata/linuxidc/redo01.log’ SIZE 50M BLOCKSIZE 512,

  GROUP 2 ‘/u01/app/oracle/oradata/linuxidc/redo02.log’ SIZE 50M BLOCKSIZE 512,

  GROUP 3 ‘/u01/app/oracle/oradata/linuxidc/redo03.log’ SIZE 50M BLOCKSIZE 512

— STANDBY LOGFILE
DATAFILE
  ‘/u01/app/oracle/oradata/linuxidc/system01.dbf’,

  ‘/u01/app/oracle/oradata/linuxidc/sysaux01.dbf’,

  ‘/u01/app/oracle/oradata/linuxidc/undotbs01.dbf’,

  ‘/u01/app/oracle/oradata/linuxidc/users01.dbf’,

  ‘/u01/app/oracle/oradata/linuxidc/example01.dbf’,

  ‘/u01/app/oracle/oradata/linuxidc/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/linuxidc/temp01.dbf

我们可以看到转储文件里包含了数据库的名字、数据文件的位置等信息,并且按照是否需要 resetlogs 分别给出了创建控制文件的 sql 语句。控制文件非常重要,我们可以把它备份下来以防万一。

更多 Oracle 相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-05/131309.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计7348字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中