控制檔案 線上日誌 回滾表空間 筆記

mahe0207發表於2014-02-26
控制檔案:很小的二進位制檔案儲存資料庫物理結構,資料庫的物理結構變化時,備份控制檔案
  1)Adding, dropping, or renaming datafiles
  2)Adding or dropping a tablespace, or altering the read/write state of the tablespace
  3)Adding or dropping redo log files or groups

控制檔案增加副本,重新命名,移動位置時
  1.關閉資料庫
  2.使用系統命令複製控制檔案到新的位置
  3.修改資料庫初始化引數CONTROL_FILES
  4.啟動資料庫

建立控制檔案命令
  create controlfile
  set database prod
  logfile group 1 ('/u01/oracle/prod/redo01_01.log', '/u01/oracle/prod/redo01_02.log'),
                group 2 ('/u01/oracle/prod/redo02_01.log', '/u01/oracle/prod/redo02_02.log'),
                group 3 ('/u01/oracle/prod/redo03_01.log', '/u01/oracle/prod/redo03_02.log') 
   resetlogs
   datafile '/u01/oracle/prod/system01.dbf' size 3m, '/u01/oracle/prod/rbs01.dbs' size 5m,
                   '/u01/oracle/prod/users01.dbs' size 5m, '/u01/oracle/prod/temp01.dbs' size 5m
   maxlogfiles 50
   maxlogmembers 3
   maxloghistory 400
   maxdatafiles 200
   maxinstances 6
   archivelog; 

重建控制檔案
   1.查詢日誌檔案,資料檔案,控制檔案路徑
          select member from v$logfile;
          select name from v$datafile; 
          select value from v$parameter where name = 'control_files';

   2.關閉資料庫
   3.備份所有資料檔案和redo檔案
   4.startup mount
   5.建立控制檔案
   6.備份新的控制檔案到一個離線儲存裝置上
   7.修改初始化引數CONTROL_FILES
   8.恢復資料庫(可選)
          1)NORESETLOGS 資料庫完全恢復
          2)RESETLOGS 必須使用USING BACKUP CONTROL FILE,如果丟失歸檔日誌或資料檔案,還需要恢復這些檔案
   9.開啟資料庫
          1)alter database open;
          2)alter database open resetlogs;

備份控制檔案    
   alter database backup controlfile to '/oracle/backup/control.bkp';
   alter database backup controlfile to trace;

相關檢視    v$database  v$controlfile  v$controlfile_record_section   v$parameter(control_files)


REDO檔案狀態
  current  當前LGWR正在使用的redo log file
  inactive  已寫入歸檔,例項恢復時不需要的redo log file
  active  還沒有寫入歸檔,例項恢復時需要的redo log file

ARCHIVE_LAG_TARGET:動態引數
   1.RAC中 各例項值須一樣,否則會發生未知錯誤
   2.The ARCHIVE_LAG_TARGET parameter must be set to the same value in all instances of an Oracle Real Application Clusters environment. Failing to do so results in         unpredictable behavior.

建立日誌組    
  alter database add logfile ('/oracle/dbs/log1c.rdo','/oracle/dbs/log2c.rdo') size 500k;

   alter database add logfile group 10 ('/oracle/dbs/log1c.rdo','/oracle/dbs/log2c.rdo') size 500k;
建立日誌成員    
  alter database add logfile member '/oracle/dbs/log2c.rdo' to ('/oracle/dbs/log2a.rdo','/oracle/dbs/log2b.rdo');


日誌成員檔案移動位置或重新命名    
   1.shutdown immedaite
   2.sqlplus 中使用系統命令 linux中host,unix中!
         mv /diska/logs/log1a.rdo /diskc/logs/log1c.rdo
         mv /diska/logs/log2a.rdo /diskc/logs/log2c.rdo
   3.startup mount
   4.alter database rename file '/diska/logs/log1a.rdo', '/diska/logs/log2a.rdo' to '/diskc/logs/log1c.rdo', '/diskc/logs/log2c.rdo';
   5.alter database open;
    
刪除日誌組
   刪除前需要注意:
          1)drop完日誌組後,沒有真的刪除,還須在作業系統上進行檔案刪除
          2)一個例項需要至少兩個日誌組,每個組至少1個
          3)只能刪除inactive日誌組,如果刪除current,請先切換日誌alter system switch logfile
          4)刪除前確認一個日誌組已歸檔
    刪除current會提示
          ORA-01623: log 1 is current log for instance ora10g (thread 1) - cannot drop
          ORA-00312: online log 1 thread 1: '/oracle/ora10gR2/oradata/ora10g/redo01.log'
    刪除active不會提示,直接刪除
          alter database drop logfile group 3;

刪除日誌成員    

   alter database drop logfile member '/u01/oradata/ocm/redo03_03.rdo';


強制日誌切換   
   alter system switch logfile;

      1.不等待歸檔完成就switch logfile    
      2.非歸檔模式下使用不歸檔當前重做日誌。
      3.對單例項database和RAC模式下當前例項執行日誌切換  
   alter system archive log current;
      1.只能執行在資料庫開啟並且歸檔模式下,會對中所有例項執行日誌切換。
      2.等待歸檔完成才switch logfile。所用的時間會比alter system switch logfile 的長。
      3.常見於RMAN指令碼,熱備後執行此命令後可以將所有的歸檔都備份出來了,保證了資料的完整。
      4.rac下慎用,因為會歸檔所有例項  
    alter system archive log current noswitch;
      1.執行此命令時,若有其他的會話連結,報ORA-01093: ALTER DATABASE CLOSE 僅允許在沒有連線會話時使用
      2. This setting is used primarily with standby databases to prevent data divergence when the primary database shuts down.
      3.You can use the NOSWITCH clause only when your instance has the database mounted but not open.  If the database is open, then this operation closes the database automatically.
      疑惑: 1.執行ALTER SYSTEM ARCHIVE LOG CURRENT NOSWITCH; 報錯ora-01109:database not open
                  2.執行前兩種命令,3個日誌組,其中2、3為active,1為current。切換日誌時,若執行select group#,status from v$log;
                  會出現3為current,1、2為active;若等一段時間,執行上述SQL,則3個日誌組全部歸檔
        
校驗日誌檔案的資料塊
   DB_BLOCK_CHECKSUM 對block進行物理性檢查
   db_block_checking與db_block_checksum  區別
     
清除日誌檔案    
   alter database clear logfile group 3;
        在只用兩個日誌組 或 current日誌組corrupt 時,不能用drop redo log,使用這個命令可以克服上述問題   
   alter database clear unarchived logfile group 3;             
        1.清空corrupt的日誌組避免歸檔它們,即使它們未歸檔也可以使用
        2.如果清空一個未歸檔的日誌,應該對資料庫作一下全備
        3.清空current日誌組時,只能在資料庫mount狀態下
   alter database clear unarchived logfile group 3 unrecoverable datafile;               
       1.如果要清除一個日誌,且這個日誌是離線表空間online需要,那麼需要使用UNRECOVERABLE DATAFILE子句

相關檢視:V$LOG,V$LOGFILE,V$LOG_HISTORY

  

UNDO
   undo記錄用於 回滾事務,恢復資料庫,提供讀一致性,通過閃回查詢分析稍早時的資料,用閃回特性恢復邏輯錯誤    
   資料庫沒有設定undo表空間,會使用system表空間存放undo資料,並會在alert log檔案中發出警告
    
   UNDO_MANAGEMENT=AUTO 用於設定UNDO自動管理 (default is MANUAL.)
   UNDO_TABLESPACE=undotbs_01 用於當有多個undo表空間時,設定資料庫啟動時使用的undo表空間
   UNDO_RETENTION 設定undo最小保留期
    
   常見錯誤 ORA-01555: snapshot too old 查詢操作需要的undo資訊已經被覆蓋掉了
    
   alter tablespace undotbs1 retention guarantee;
   alter tablespace undotbs1 retention noguarantee;

   guarantee: 保證undo_retention引數所設定的時間有效,這個是10g的新功能。

   如果同時執行了很多事務,將undo表空間耗完了,那麼那個事務會失敗,會報ORA-30036 錯誤
   ORA-30036: unable to extend segment by string in undo tablespace "string"
   Cause: the specified undo tablespace has no more space available.
   Action: Add more space to the undo tablespace before retrying the operation. An alternative is to wait until active transactions to commit.
    
   Automatic Tuning of Undo Retention    
   V$UNDOSTAT.TUNED_UNDORETENTION
   DBA_HIST_UNDOSTAT
    
   設定Undo保留策略 DBMS_ADVISOR
建立Undo表空間  
  
create undo tablespace undotbs_02 datafile '/u01/oracle/rbdb1/undo0201.dbf' size 2m reuse autoextend on;
   alter tablespace undotbs_01 add datafile '/u01/oracle/rbdb1/undo0102.dbf' autoextend on next 1m maxsize unlimited;

切換Undo表空間 
   alter system set undo_tablespace = undotbs_02;
        
建立使用者使用配額  UNDO_POOL

    
Undo相關檢視:v$undostat  v$rollstat  v$transaction  dba_undo_extents  dba_hist_undostat


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29437301/viewspace-1093740/,如需轉載,請註明出處,否則將追究法律責任。

相關文章