ITPub博客

首页 > 数据库 > Oracle > 控制文件 在线日志 回滚表空间 笔记

控制文件 在线日志 回滚表空间 笔记

原创 Oracle 作者:mahe0207 时间:2014-02-26 21:14:40 0 删除 编辑
控制文件:很小的二进制文件保存数据库物理结构,数据库的物理结构变化时,备份控制文件
  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博客 ” ,链接:https://blog.itpub.net/29437301/viewspace-1093740/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 技术杂烩-20140320
请登录后发表评论 登录
全部评论

注册时间:2014-01-11

  • 博文量
    26
  • 访问量
    101266