oracle 11g ocp notes (19)--flashback technology

Oracle's Flashback functionality is supported by one of three database structures: Undo Data, Flash Recovery Area, and Recycle Bin.
    Undo data in the undo tablespace supports not only transaction rollback, but also most Flashback Table operations. Flashback Data Archives allows querying of previous versions of table rows, it provides an area in one or more tablespaces outside of the undo tablespace, and supports retention periods longer than the undo tablespace. Flashback logs are stored in the Flash Recovery Area, making it easy to roll back the entire database to a point in time in the past without performing traditional restore and recovery operations. The recycle bin in each tablespace contains one or more versions of dropped tables and indexes, which the user can easily restore if there is sufficient space in the tablespace.

 

1. Various flashback technologies:

    flashback database

    flashback table, query, transaction

    flashback delete

    Flashback Data Archive

2. Flashback Database

 

  Oracle's Flashback Database feature uses the Flashback database command to return the database to a past time or SCN, providing a quick alternative to performing incomplete database recovery.

     If the file is damaged, flashback database cannot be used


    When Flashback Database is enabled, the pre-image data will be saved in the flashback buffer, and then use the Recovery Write (RVWR) background process to save the pre-image information in the flashback buffer in the flashback recovery area. in the Flashback Database log. The logs in the Flash Recovery Area are reused cyclically, and how far back in time the database is backed up depends on the amount of space in the Flash Recovery Area and the configured guaranteed restore points. ? ? ? ? ? ?

    To enable the Flashback Database feature, the database must be set to archive mode and archived to the fast recovery area must be configured.

2. Configure Flashback Database

      1) Make sure the database is in archive mode

       2)配置闪回恢复区
      alter system set db_recovery_file_dest='/u01/app/oracle/fast_recovery_area';
      alter system set db_recovery_file_dest_size=40G;

       3) Configure retention time

             alter system set db_flashback_retention_target=2880;

        4) Cleanly shut down the database and start to mount state.

        5) alter database flashback on; then open the database.

3. Whether monitoring is enabled

      select flashback_on from database;--whether to enable.

     or RVWR process (linux)

 

    select retention_target, flashback_size, oldest_flashback_time from v$flashback_database_log --- The space and recoverable time of the flashback log.

    select end_time,flashback_data,db_data,redo_data from v$flashback_database_stat;---the amount of data generated.

              select  * from v$sgastat where name=‘flashback generation buff’

4. Use flashback database (rman salplus dbcontrol can be used)

         ①Close the database

         ②boot to mount

         ③ Flashback to the database to a certain point in time, SCN or sequence#

        ④Resetlog mode to open the database.

          

         ③代码: flashback database to timestamp to_timestamp (‘asasaasas’)

                    You can first alter database open read only; see if it is normal, and then restore it if it is not correct.

3. Flashback delete

1, to achieve flashback oracle drop command is actually to modify the name of the table. drop table XXX purge is the intended deletion.

2. Use flashback to delete: flashback table emp1 to before drop ;

                               flashback table "BIN$49nL2H4iEtngRAgAJzxnug==$0" to before drop rename to emp2 ;--rename (if already there)

3. Manage the recycle bin show receybin; 

                         purge recyclebin 

                          select * from  dba_recyclebin;

 

4. Flashback query

                 All flashbacks are undo-dependent.

     1) Basic flashback query: select * from table_name as of timestamp to_timestamp(xxxxxx);

2) Flashback table   

       First enable the table movement function, alter table xxx enable movement;

       flashback table   tablename1 ,tablename2等  to timestamp to_timestamp(xxxxxx);

      There are many reasons why the flashback may not be successful.

 

3) Flashback version

  The pseudocolumns are as follows:

Pseudo column

describe

VERSIONS_STARTSCN

VERSIONS_STARTTIME

The SCN or TIMESTAMP at which the row version was created . This pseudo-column identifies the time when the row version's value was originally owned.

Use this value for Flashback Table or Flashback Query to determine the target time in the past.

If this pseudocolumn is NULL , the row version is created before start . (use start and end to determine a time range)

VERSIONS_ENDSCN

VERSIONS_ENDTIME

SCN or TIMESTAMP with outdated row version

If NULL , it indicates that the row version is the current version at the time of the query, or the row corresponding to the delete operation.

VERSIONS_XID

Identifies the transaction that created the row version

VERSIONS_OPERATION

The operation performed by the transaction ( I-INSERT , D-DELETE , U-UPDATE ). A version is a row that was inserted, deleted, or updated. That is, the rows after insert and update operations and before delete operations.

For user updates of index keys, Flashback Versions query will perform 2 operations for one UPDATE , namely DELETE and INSERT .

 

-Indicates that from 2003.09.09-2003.10.25 , salary has always been 10243

VERSIONS_START_TIME     VERSIONS_END_TIME     SALARY

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

09-SEP-200325-NOV-200310243                             

--Typical application of flashback version query

SELECT versions_startscn, versions_starttime, versions_endscn, versions_endtime, versions_xid, versions_operation, last_name, salary

  FROM employees

  VERSIONS BETWEENTIMESTAMP

  TO_TIMESTAMP('2008-12-18 14:00:00','YYYY-MM-DD HH24:MI:SS')

  AND TO_TIMESTAMP('2008-12-18 17:00:00','YYYY-MM-DD HH24:MI:SS')

  WHERE first_name ='John';

 

 

 

4) Flashback things

 

To be added

 

 

5)v$undostat

5. Flashback data archiving

     

1) The process of flashback data archive:

  1. Create a flashback data archive.
  2. Specify the default Flashback Data Archive.
  3. Enable Flashback Data Archive.
  4. View flashback data archive data.

 

 

1. Create test data:
create tablespace arch_tbs datafile '/u01/app/oracle/oradata/PROD/arch_tbs.dbf' size 100m autoextend on

maxsize 1G;

2.创建测试用户并授权:
create user archive_admin identified by archive_admin default tablespace arch_tbs;

grant dba,flashback archive administer to archive_admin;

3. Create a flashback archive (when setting the default flashback archive, you need to use the sys user)
conn archive_admin/archive_admin

create flashback archive fda1 tablespace arch_tbs quota 10m retention 1 year;

alter flashback archive fdb1 set default;
--sys user

create flashback archive default fda1 tablespace arch_tbs quota 10m retention 1 year; --Or
directly set the default flashback archive (under the sys user)

4. Set the flashback archive of the
table alter table test_user1.emp flashback archive;

5. Verify
conn test_user1/test

desc dba_flashback_archive_tables;

select table_name,archive_table_name from dba_flashback_archive_tables;

- View the history tracking table related to the current setup flashback archive

select owner,table_name,tablespace_name from dba_tables where table_name='SYS_FBA_HIST_88707'; --Determine
the name, owner, and location of the history table

Insert, update and delete operations on the emp table, and then view the content of the history tracking table:

 

 

 

 

 

Optionally change the retention time:
ALTER FLASHBACK ARCHIVE fla1 MODIFY RETENTION 2 YEAR;

Optionally clear data:
ALTER FLASHBACK ARCHIVE fla1 PURGE BEFORE TIMESTAMP (SYSTIMESTAMP - INTERVAL '1' day);

Optionally delete flashback data archives:
DROP FLASHBACK ARCHIVE fla1;

View Flashback Data Archive :

View Name (DBA/USER) Description
*_FLASHBACK_ARCHIVE Displays information about Flashback Data Archive
*_FLASHBACK_ARCHIVE_TS Displays Flashback Data Archive tablespaces
*_FLASHBACK_ARCHIVE_TABLES Displays information about Flashback Archive-enabled tables

Tracked tables and Flashback Data archive metadata can be viewed using the Dynamic Data Dictionary view. To access USER_FLASHBACK_* views, you must have ownership of the table. need to check

DBA_FLASHBACK_* views, you need SYSDBA authority.

DDL limitations for Flashback Data Archive:

Executing any of the following DDL statements on a table with Flashback Data Archive enabled produces an ORA-55610 error:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325169770&siteId=291194637