• 重建控制文件具体解释


    完整图文最新版
     
    创造“重建控制文件脚本”须要在mount或open下进行。

    alter database backup controlfile to trace as '/tmp/ctl..sql';

    运行“重建控制文件脚本”须要在nomount的时候。
     

    -- 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="gs01ehis"
    --
    -- 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_1='LOCATION=/paic/stg/oracle/10g/app102056/oracle/product/10.2.0/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 "GS01EHIS" NORESETLOGS FORCE LOGGING NOARCHIVELOG
        MAXLOGFILES 32
        MAXLOGMEMBERS 3
        MAXDATAFILES 800
        MAXINSTANCES 8
        MAXLOGHISTORY 18696
    LOGFILE
      GROUP 1 '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/redo01.log'  SIZE 100M,
      GROUP 2 '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/redo02.log'  SIZE 100M,
      GROUP 3 '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/redo03.log'  SIZE 100M
    -- STANDBY LOGFILE

    DATAFILE
      '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/system01.dbf',
      '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/undotbs01.dbf',
       '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/system01.dbf',
      '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/undotbs01.dbf',
      '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/sysaux01.dbf',
      '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/users01.dbf',
      '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/auddata01.dbf',
      '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/dbadata01.dbf'
    CHARACTER SET ZHS16GBK
    ;

    - 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 '/paic/stg/oracle/10g/app102056/oracle/product/10.2.0/dbs/arch1_1_807985002.dbf';
    -- ALTER DATABASE REGISTER LOGFILE '/paic/stg/oracle/10g/app102056/oracle/product/10.2.0/dbs/arch1_1_807987054.dbf';
    -- Recovery is required if any of the datafiles are restored backups,
    -- or if the last shutdown was not normal or immediate.
    RECOVER DATABASE

    -- Set Database Guard and/or Supplemental Logging
    ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
    -- Database can now be opened normally.
    ALTER DATABASE OPEN;

    -- Files in read-only tablespaces are now named.
    ALTER DATABASE RENAME FILE 'MISSING00030'
      TO '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/fwy01.dbf';

    -- Online the files in read-only tablespaces.
    ALTER TABLESPACE "FWY01" ONLINE;
    -- Commands to add tempfiles to temporary tablespaces.
    -- Online tempfiles have complete space information.
    -- Other tempfiles may require adjustment.
    ALTER TABLESPACE TEMP ADD TEMPFILE '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/temp01.dbf' REUSE;
    -- 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 "GS01EHIS" RESETLOGS FORCE LOGGING NOARCHIVELOG
        MAXLOGFILES 32
        MAXLOGMEMBERS 3
        MAXDATAFILES 800
        MAXINSTANCES 8
        MAXLOGHISTORY 18696
    LOGFILE
      GROUP 1 '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/redo01.log'  SIZE 100M,
      GROUP 2 '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/redo02.log'  SIZE 100M,
      GROUP 3 '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/redo03.log'  SIZE 100M
    -- STANDBY LOGFILE

    DATAFILE
      '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/system01.dbf',
      '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/undotbs01.dbf',
         '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/system01.dbf',
      '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/undotbs01.dbf',
      '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/sysaux01.dbf',
      '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/users01.dbf',
      '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/auddata01.dbf',
      '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/dbadata01.dbf'
    CHARACTER SET ZHS16GBK
    ;
    -- 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.
    -- re-create incarnation records.
    -- ALTER DATABASE REGISTER LOGFILE '/paic/stg/oracle/10g/app102056/oracle/product/10.2.0/dbs/arch1_1_807985002.dbf';
    -- ALTER DATABASE REGISTER LOGFILE '/paic/stg/oracle/10g/app102056/oracle/product/10.2.0/dbs/arch1_1_807987054.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

    -- Set Database Guard and/or Supplemental Logging
    ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
    -- Database can now be opened zeroing the online logs.
    ALTER DATABASE OPEN RESETLOGS;

    -- Files in read-only tablespaces are now named.
    ALTER DATABASE RENAME FILE 'MISSING00030'
      TO '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/fwy01.dbf';

    -- Online the files in read-only tablespaces.
    ALTER TABLESPACE "FWY01" ONLINE;
    -- Commands to add tempfiles to temporary tablespaces.
    -- Online tempfiles have complete space information.
    -- Other tempfiles may require adjustment.
    ALTER TABLESPACE TEMP ADD TEMPFILE '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/temp01.dbf' REUSE;
    -- End of tempfile additions.

     
    主要分为两部分,resetlogs也有noresetlogs的重建控制文件脚本。假设想单独要某部分,分别运行下面语句就可以。
    alter database backup controlfile to trace as '/tmp/ctl_1.sql' noresetlogs;
    alter database backup controlfile to trace as '/tmp/ctl_1.sql' resetlogs;

    以下分别来解说。红框的几种选项。
    重建控制文件的时候会去数据文件头读db_name。reuse是会參考数据文件头的db_name,而set会将数据文件头的db_name都改成脚本中指定的database "ZXRRIN"

    SET还是REUSE
    假如我选reuse database "ZXRRIN2",而数据文件头是ZXRRIN2,那么会报例如以下错误。
    ORA-01503: CREATE CONTROLFILE failed
    ORA-01161: database name ZXRRIN in file header does not match given name of
    ZXRRIN2
    ORA-01110: data file 1: '/oradata/zxrrin/zxrrin/system01.dbf'
    所以。仅仅有数据文件头的database name与參数文件的db_name一致。才干在重建控制文件时用reuse。

    当然,用set也没关系。仅仅是将数据文件头的db_name重写成同样的。就如update t set i=3 where i=3一样。假设想改变数据文件头的db_name使他们与起库參数的db_name一致,就当然得用set咯。


    database "ZXRRIN"
    database "ZXRRIN"指定的db_name。要跟起库參数文件的db_name一致。重建控制文件才干成功。
    这是必须的。而跟REUSE还是SET等没关系。所以不能用A1起库,然后重建控制文件成A2的db_name哦。


    noresetlogs还是resetlogs
    重建conrolfile时,假如用的是noresetlogs的选项。那么controlfile里面的系统scn号。以及controlfile里面记录的数据文件scn号。来自Online logs中的Current log头。

     所以这个操作的前提是。在线日志完善没有损坏。而且,不会擦除redo log file中的内容与重置redo头的scn号。起库的时候,仅仅能alter database open,而不能alter database open resetlogs。否则会报这个错。

    SQL> alter database open noresetlogs;
    alter database open noresetlogs
    *
    ERROR at line 1:
    ORA-01139: RESETLOGS option only valid after an incomplete database recovery
    所以,在重建控制文件时选择noresetlogs,oracle就会觉得你想告诉他。“我非常可能是不一致关闭的”,既然是不一致关闭。那怎么能alter database open resetlogs呢。所以会报上面的错。
    在运行”重建控制文件脚本“的时候假设不须要在线重做日志的话能够用resetlogs选项。选择resetlogs,会将redo log file中的内容清空。sequence#由1算起。重建过程中,控制文件里datafile Checkpoint来自各数据文件头。而controlfile中记录的系统scn,会被设为0.能够通过select checkpoint_change#  from v$database;看出来。

    NOARCHIVELOG还是ARCHIVELOG
    重建控制文件脚本中,NOARCHIVELOG与ARCHIVELOG字段,选择重建的控制文件是使库不归档或者归档的。

    一个数据库是否开启归档。是在控制文件中面辨析的。


    几者之间的关系
    假设要用set,那么一定要跟resetlogs那一part。由于set会改数据文件头的db_name。那么redo log file中的日志已经没用了,由于应用日志时必须匹配db_name的。
    假如用set配noresetlogs会出现报错:
    ORA-01223: RESETLOGS must be specified to set a new database name

    关于tempfile
    重建的控制文件不包括temp文件。所以重建控制文件脚本中有例如以下语句。
    ALTER TABLESPACE TEMP ADD TEMPFILE '/paic/drsh101/stg/ehis/data/oradata/gs01ehis/temp01.dbf' REUSE;
    我们也能够拷贝出来,等open库后再运行。

    重建控制文件的时候。对应的redo与datafile文件必须已经存在,datafile文件必须是一致的。
    而tempfile是不必要存在的,起库后,要为temp表空间加入tempfile。否则temp表空间里面空空如也。
    ALTER TABLESPACE TEMP ADD TEMPFILE '/oradata/zxrrin/zxrrin/temp01.dbf' size 100m reuse autoextend on;
    加上reuse是非常好的,假设已经存在就覆盖掉,假设不存在就新建上。


    这个命令能够备份控制文件成二进制文件。
    ALTER DATABASE BACKUP CONTROLFILE TO '/tmp/fwy.ctl';














  • 相关阅读:
    HBase原理和架构
    Hive UDF作业
    Hive性能调优
    hive
    Netty4.0学习笔记系列之一:Server与Client的通讯
    JAVA NIO 简介(转)
    设计模式之观察者模式(Observer Pattern)
    设计模式之装饰者模式(Decorator Pattern)
    mysql存储过程写法—动态参数运用
    hashCode() 和equals() 区别和作用
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5099959.html
Copyright © 2020-2023  润新知