zoukankan      html  css  js  c++  java
  • oracle启用归档日志

    一、开启归档

    1、查看归档信息

    复制代码
    SQL> archive log list
    Database log mode           No Archive Mode
    Automatic archival           Disabled
    Archive destination           USE_DB_RECOVERY_FILE_DEST
    Oldest online log sequence     244
    Current log sequence           246
    复制代码

    当前数据库未开启归档

    2、设置归档目录

    oracle默认使用闪回恢复区DB_RECOVERY_FILE_DEST作为归档路径

    复制代码
    SQL> show parameter DB_RECOVERY_FILE_DEST
    
    NAME                     TYPE     VALUE
    ------------------------------------ ----------- ------------------------------
    db_recovery_file_dest             string     /u01/app/oracle/flash_recovery_area
    db_recovery_file_dest_size         big integer 3882M
    复制代码

    闪回恢复区在安装过程中有限制其大小,如果闪回恢复区满了,归档日志会无法写入而导致数据库hang住,解决办法可以增加闪回区大小或者修改归档路径

    3、修改归档路径

    修改log_archive_dest_1参数可修改归档日志路径(pfile/spfile中参数db_recovery_file_dest指定的目录将无效)

    实际上从Oracle 10g开始,可以生成多份一样的日志,保存多个位置,以防不测。多个位置通过设置不同的log_archive_dest_n 参数实现,archive log list输出中的Archive destination路径只显示最新修改的路径。

    复制代码
    SQL> show parameter log_archive_dest_1
    
    NAME                     TYPE     VALUE
    ------------------------------------ ----------- ------------------------------
    log_archive_dest_1             string
    log_archive_dest_10             string
    log_archive_dest_11             string
    log_archive_dest_12             string
    log_archive_dest_13             string
    log_archive_dest_14             string
    log_archive_dest_15             string
    log_archive_dest_16             string
    log_archive_dest_17             string
    log_archive_dest_18             string
    log_archive_dest_19             string
    复制代码

    修改归档路径为/u01/app/oracle/archive_log

    SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/archive_log' scope=spfile;
    
    System altered.

    重启生效

    4、修改归档日志格式

    SQL> alter system set log_archive_format='ARC%S_%R.%T_%D.dbf' scope=spfile;
    
    System altered.

    重启生效

    5、开启归档

    需要在mount状态下开启数据库归档,重启至mount

    复制代码
    SQL> shutdown immediate
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    SQL> startup mount
    ORACLE instance started.
    
    Total System Global Area 1603411968 bytes
    Fixed Size            2213776 bytes
    Variable Size          989857904 bytes
    Database Buffers      603979776 bytes
    Redo Buffers            7360512 bytes
    Database mounted.
    复制代码

    开启数据库归档

    SQL> alter database archivelog;
    
    Database altered.

    查看归档情况

    复制代码
    SQL> archive log list
    Database log mode           Archive Mode
    Automatic archival           Enabled
    Archive destination           /u01/app/oracle/archive_log
    Oldest online log sequence     244
    Next log sequence to archive   246
    Current log sequence           246
    复制代码
    ALTER DATABASE FORCE LOGGING;
    开启强制归档

    打开数据库

    SQL> alter database open;
    
    Database altered.

    6、确认数据库为归档模式

    复制代码
    SQL> select log_mode from v$database;
    
    LOG_MODE
    ------------
    ARCHIVELOG
    
    SQL> select archiver from v$instance;
    
    ARCHIVE
    -------
    STARTED
    复制代码

    7、强制日志切换

    先查看当前归档日志视图和归档日志路径:

    SQL> select name from v$archived_log;
    
    no rows selected
    [oracle@zml-rhel6 archive_log]$ ll
    total 0

    没有归档日志,下面执行强制日志切换

    SQL> alter system switch logfile;
    
    System altered.

    再次查看视图

    SQL> select name from v$archived_log;
    
    NAME
    --------------------------------------------------------------------------------
    /u01/app/oracle/archive_log/ARC0000000246_0963417259.0001_6833bc69.dbf

    有归档日志产生,验证成功

    二、归档日志清理

    1、手动物理删除归档日志

    该方式利用linux的命令find查找N天以前的日志,直接删除

    复制代码
    [oracle@localhost archive_log]$ find . -type f -mtime +2.4 -print |xargs ls -rlt
    -rw-r----- 1 oracle oinstall 16092672 6月   4 20:45 ./ARC0000000606_0977259429.0001_fb0ffee2.dbf
    -rw-r----- 1 oracle oinstall 38390272 6月   4 22:00 ./ARC0000000607_0977259429.0001_fb0ffee2.dbf
    -rw-r----- 1 oracle oinstall 32950272 6月   4 22:02 ./ARC0000000608_0977259429.0001_fb0ffee2.dbf
    复制代码

    该例子中查询到2.4天前日志列表。手工物理删除这些日志文件:

    [oracle@localhost archive_log]$ find . -type f -mtime +2.4 -print |xargs rm -f

    虽然手工删除的了归档日志文件,但是控制文件中依然会有这些日志的记录,下面需要在控制文件中清理这些归档日志。利用rman:

    查看过期日志:

    RMAN> list expired archivelog all;
    
    specification does not match any archived log in the repository

    返回信息显示没有过期日志,这是因为需要先检查归档日志有效性,再进行删除:

    复制代码
    RMAN> crosscheck archivelog all;
    ....
    ....
    ....
    archived log file name=/home/oracle/app/oracle/archive/orclwhs/archive_log/ARC0000002400_0977259429.0001_fb0ffee2.dbf RECID=1795 STAMP=978255518
    validation succeeded for archived log
    archived log file name=/home/oracle/app/oracle/archive/orclwhs/archive_log/ARC0000002401_0977259429.0001_fb0ffee2.dbf RECID=1796 STAMP=978255659
    validation succeeded for archived log
    archived log file name=/home/oracle/app/oracle/archive/orclwhs/archive_log/ARC0000002402_0977259429.0001_fb0ffee2.dbf RECID=1797 STAMP=978256043
    Crosschecked 1797 objects
    复制代码

    再次查看过期归档日志,rm删除的三个文件便被标记为了过期日志:

    复制代码
    RMAN> list expired archivelog all;
    
    List of Archived Log Copies for database with db_unique_name ORCLWHS
    =====================================================================
    
    Key     Thrd Seq     S Low Time 
    ------- ---- ------- - ---------
    1       1    606     X 04-JUN-18
            Name: /home/oracle/app/oracle/archive/orclwhs/archive_log/ARC0000000606_0977259429.0001_fb0ffee2.dbf
    
    2       1    607     X 04-JUN-18
            Name: /home/oracle/app/oracle/archive/orclwhs/archive_log/ARC0000000607_0977259429.0001_fb0ffee2.dbf
    
    3       1    608     X 04-JUN-18
            Name: /home/oracle/app/oracle/archive/orclwhs/archive_log/ARC0000000608_0977259429.0001_fb0ffee2.dbf
    复制代码

    删除过期归档日志:

    复制代码
    RMAN> delete expired archivelog all;
    
    released channel: ORA_DISK_1
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=446 device type=DISK
    List of Archived Log Copies for database with db_unique_name ORCLWHS
    =====================================================================
    
    Key     Thrd Seq     S Low Time 
    ------- ---- ------- - ---------
    1       1    606     X 04-JUN-18
            Name: /home/oracle/app/oracle/archive/orclwhs/archive_log/ARC0000000606_0977259429.0001_fb0ffee2.dbf
    
    2       1    607     X 04-JUN-18
            Name: /home/oracle/app/oracle/archive/orclwhs/archive_log/ARC0000000607_0977259429.0001_fb0ffee2.dbf
    
    3       1    608     X 04-JUN-18
            Name: /home/oracle/app/oracle/archive/orclwhs/archive_log/ARC0000000608_0977259429.0001_fb0ffee2.dbf
    
    
    Do you really want to delete the above objects (enter YES or NO)? yes
    deleted archived log
    archived log file name=/home/oracle/app/oracle/archive/orclwhs/archive_log/ARC0000000606_0977259429.0001_fb0ffee2.dbf RECID=1 STAMP=977949943
    deleted archived log
    archived log file name=/home/oracle/app/oracle/archive/orclwhs/archive_log/ARC0000000607_0977259429.0001_fb0ffee2.dbf RECID=2 STAMP=977954446
    deleted archived log
    archived log file name=/home/oracle/app/oracle/archive/orclwhs/archive_log/ARC0000000608_0977259429.0001_fb0ffee2.dbf RECID=3 STAMP=977954551
    Deleted 3 EXPIRED objects
    复制代码

    再次查询过期归档:

    RMAN> list expired archivelog all;   
    
    specification does not match any archived log in the repository

    2、RMAN归档日志清理

    删除归档日志正确的流程:

    RMAN> crosscheck archivelog all; //验证的DB的归档日志
    RMAN> delete expired archivelog all; //删除所有归档日志
    RMAN> DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7'; //保留7天的归档日志

    定时shell脚本

    复制代码
    #!/bin/bash
    export ORACLE_BASE=/home/oracle/app/oracle
    export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1
    export export ORACLE_SID=orclwhs
    
    ${ORACLE_HOME}/bin/rman nocatalog log=/home/oracle/bin/cleararchivelog/del_arch$(date +%Y-%m-%d).log <<EOF  
    connect target /  
    #crosscheck archivelog all;  
    #delete noprompt expired archivelog all;  
    DELETE noprompt ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-2';  
    exit;  
    EOF
    复制代码

    可参考:https://blog.csdn.net/javaee_ssh/article/details/36906413

  • 相关阅读:
    Python实现MapReduce,wordcount实例,MapReduce实现两表的Join
    structure needs cleaning
    Lifecycle of an ASP.NET MVC 5 Application
    ASP.NET Integration with IIS 7
    Execution order of modules in IIS7
    Assembly Binding redirect: How and Why?
    Cannot See Worker Processes Icon in IIS
    What is the main difference between a key, an IV and a nonce?
    核心玩法的三要素
    ruby各种循环输出数组元素
  • 原文地址:https://www.cnblogs.com/li-sx/p/11020838.html
Copyright © 2011-2022 走看看