zoukankan      html  css  js  c++  java
  • 数据库Flashback学习

    最近更新时间:2018/12/18


    适用场景

    数据库升级、快速构建测试环境、DG中重建主库

    前置条件

    1. ARCHIVELOG 模式

    数据库为 mount 状态下开启,最好指定archive log 保存路径。

    alter system set log_archive_dest_1='location=/u01/arch';

    ALTER DATABASE ARCHIVELOG;

    SQL> archive log list;
    Database log mode              Archive Mode
    Automatic archival             Enabled
    Archive destination            /u01/arch
    Oldest online log sequence     0
    Next log sequence to archive   0
    Current log sequence           54

    2. 使用时Database要为mount状态,Control File为当前在用的,不是通过备份恢复或者其他方式创建的,因为通过备份恢复或其他方式创建的控制文件不含 flashback log相关信息;

    3. 所有在线表空间不存在禁用flashback的情况(ALTER TABLESPACE ... FLASHBACK OFF)


    Flashback Database 需要用到 Flashback logs;

    参数说明

    1. 设置 Fast Recovery Area,FRA为ORACLE提供集中管理备份恢复文件路径

    1.1 DB_RECOVERY_FILE_DEST 设置默认FRA路径

    1.2 DB_RECOVERY_FILE_DEST_SIZE 设置配额(BYTES)

    2. DB_FLASHBACK_RETENTION_TARGET 设置保留策略,只是期望值,具体与闪回区保留数据有关

    3. 通过Flashback闪回数据库后,使用 ALTER DATABASE OPEN RESETLOGS 打开数据库

    参考:

    http://docs.oracle.com/cd/E11882_01/backup.112/e10642/flashdb.htm#BRADV71000

    https://docs.oracle.com/cd/B19306_01/backup.102/b14192/rpfbdb003.htm

    alter system set db_recovery_file_dest='/u02/fast_recovery_area' scope=both;

    alter system set db_recovery_file_dest_size=4G scope=both;

    SQL> show parameter db_recovery

    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    db_recovery_file_dest                string      /u01/fast_recovery_area
    db_recovery_file_dest_size           big integer 500M


    开启方式

    STARTUP MOUNT;

    ALTER DATABASE FLASHBACK ON;

    SQL> select FLASHBACK_ON from v$database;

    FLASHBACK_ON

    ------------------

    YES


    闪回数据库测试

    SQL> select * from dg_test;

    …. 省略….

    26 rows selected.

    SQL> select current_scn from v$database;

    CURRENT_SCN
    -----------
         3655665

    SQL> truncate table dg_test;

    Table truncated.

    SQL> shutdown immediate;
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    SQL> quit
    Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    [oracle@db1 ~]$ sqlplus / as sysdba

    SQL*Plus: Release 11.2.0.4.0 Production on Wed Dec 19 18:17:47 2018

    Copyright (c) 1982, 2013, Oracle.  All rights reserved.

    Connected to an idle instance.

    SQL> startup mount;
    ORACLE instance started.

    Total System Global Area 2471931904 bytes
    Fixed Size                  2255752 bytes
    Variable Size             603980920 bytes
    Database Buffers         1845493760 bytes
    Redo Buffers               20201472 bytes
    Database mounted.
    SQL> flashback database to scn 3655665;

    Flashback complete.

    SQL> alter database open read only;

    Database altered.

    SQL> select count(1) from dg_test;

      COUNT(1)
    ----------
             26


    确认数据为我们需要的,则以 resetlogs 方式打开数据库

    SQL> shutdown immediate;
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    SQL> startup mount;

    SQL> alter database open resetlogs;

    Database altered.


    此处测试环境为 DataGuard ,主库做了 resetlogs 后,产生了新的 redo日志分支,备库同样需要flashback to scn 3655665,否则备库应用日志已超过主库日志时间,没法继续同步。

    会提示以下日志:

    Completed: alter database recover managed standby database using current logfile disconnect from session
    Recovery Slave PR00 previously exited with exception 19909
    Wed Dec 19 18:28:07 2018
    MRP0: Background Media Recovery process shutdown (orcl)

    解决办法: 备库闪回到主库 resetlogs 时间之前

    SQL> shutdown immediate;
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    SQL> startup mount;

    SQL> flashback database to scn 3655665;

    Flashback complete.

    SQL> select open_mode from v$database;

    OPEN_MODE
    --------------------
    MOUNTED

    SQL> alter database open;

    Database altered.

    SQL> select open_mode from v$database;

    OPEN_MODE
    --------------------
    READ ONLY

    SQL> alter database recover managed standby database using current logfile disconnect from session;

    Database altered.

    SQL> select open_mode from v$database;

    OPEN_MODE
    --------------------
    READ ONLY WITH APPLY

    https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:9525013800346105272


    常用查询

    闪回区空间使用情况

    select * from v$flash_recovery_area_usage;

    最大闪回时长查询

    SELECT OLDEST_FLASHBACK_SCN, OLDEST_FLASHBACK_TIME FROM V$FLASHBACK_DATABASE_LOG;


    问题

    FRA空间不足

    Completed: alter database open
    Wed Dec 19 17:21:09 2018
    Errors in file /u01/app/diag/rdbms/db2/orcl/trace/orcl_m000_6773.trc:
    ORA-19815: WARNING: db_recovery_file_dest_size of 524288000 bytes is 100.00% used, and has 0 remaining bytes available.
    ************************************************************************
    You have following choices to free up space from recovery area:
    1. Consider changing RMAN RETENTION POLICY. If you are using Data Guard,
        then consider changing RMAN ARCHIVELOG DELETION POLICY.
    2. Back up files to tertiary device such as tape using RMAN
        BACKUP RECOVERY AREA command.
    3. Add disk space and increase db_recovery_file_dest_size parameter to
        reflect the new space.
    4. Delete unnecessary files using RMAN DELETE command. If an operating
        system command was used to delete files, then use RMAN CROSSCHECK and
        DELETE EXPIRED commands.
    ************************************************************************

    解决: 增加空间

    SQL>  ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE = 4G scope=both;

    FRA空间不足只是影响数据库能闪回的时间点,不会影响数据库正常使用。

  • 相关阅读:
    myeclipse 配置svn
    windows下 将tomcat做成服务,并于oracle后启动
    局部内部类为什么只能访问final局部变量,对于成员变量却可以随便访问?
    使用cmd查看windows端口占用情况,并关闭应用
    生成javadoc文档
    JNI以及JNA使用
    自定义标签-java
    dwr框架应用
    Hadoop生态圈简介
    tomcat之日志记录
  • 原文地址:https://www.cnblogs.com/bugbeta/p/10145041.html
Copyright © 2011-2022 走看看