Recover oracle database tables to a specific point in time

  A table is a software application where data misuse are cleared, and now want to recover between emptying, such as at 14:13 on August 2013, before the date should be how to operate?

  It can trigger a series of a series of knowledge through this problem.

  1, if you can use open flashback flash back to the table.

  

How to view my database have not turned flashback

  flashback database requires that the database must be in archive mode , and must be used after resetlogs Flashback open the database
  view database archiving and flashback mode is enabled
  SQL> the SELECT log_mode, open_mode, flashback_on from v $ Database;

  LOG_MODE open_mode FLASHBACK_ON
  ------ ------------- ----------------- -------------------- ----
  ARCHIVELOG the READ WRITE NO         

  

  FLASHBACK_ON to NO, it means Flashback features not enabled

 

 

oracle database archiving mode

Oracle Database has an online redo log, the log is a record modifications made to the database, such as insert, delete, update data, these operations will be recorded in the online redo log.

Mode Introduction

Oracle Database has an online redo log, the log is a record modifications made to the database, such as insert, delete, update data, these operations will be recorded in the online redo log. General database must have at least two online redo log groups . When a pack is filled online redo log when the log switch occurs, then 2 - Log Log be currently used, when filled redo log. 2, the switch will happen log , to write online redo log group 1, so repeatedly.
If the database is a non-filing mode, online log will be discarded at the time of switching. In archive mode, the switch occurs when a log, the log will be switched archiving. For example, currently using online redo log 1, when filled with 1's, log switch occurs, start writing online redo log 2, then the contents of the online redo log 1 will be further copied to a specified directory. This directory is called the archive directory, copy the file called archived redo log.
When using the archive database can be run disaster recovery.
1. archive log mode and non-archive log difference mode
Non-filing mode can only do cold backup and recovery can only do a full backup . Last full backup to the data during the system error can not be restored.
Archive mode can do hot backup , and can do incremental backups , you can do a partial recovery.
With ARCHIVE LOG LIST mode you can view the current status of an archive mode or non-archive mode.

How to view the current oracle in archive mode or non-archive mode

1、

selectname, log_mode, open_mode from v $ Database;

NAME LOG_MODE open_mode
--------- ------------ ---------------- -
CKDB ARCHIVELOG  the READ  WRITE

if filing mode, LOG_MODE = ARCHIVELOG
if the non-filing mode, LOG_MODE = NOARCHIVELOG

 

2、

Input: archive log list Enter, you can see whether the archive mode

SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 31
Current log sequence 33

How oracle database is open archives

If you do not open oracle database archiving mode, for misuse it would be disastrous, and impossible to restore. Here's how to verify whether the oracle archive models and methods how to turn filing mode is turned on.

  1. Open archive mode

    1> First, open the cmd command window: sqlplus / as sysdba login database

    2> After a successful login to the database, enter the command: select log_mode from v $ database used to check filing mode

    3> After the query can see log_ mode is noarchivelog explain archive mode is not archiving mode

    4> with shutdown immediate shutdown normal or close the database

    5> Wait database normally closed

    6> After the database is closed, starting the database with startup mount, load an instance of the database but Close

    7> use the command: alter database archivelog; open the log file, the database returns the message has been changed after the successful execution of the command

    8> use the command: alter database open; open the database to complete the overall operation

    9> alter system archive log start; (enable automatic archiving)

    10> exit (exit)

    11> Verify the archive logs. Repeating the first step, execute the command: select log_mode v $ database, see the execution result archivelog

  Do a full backup, because the non-archive log backup log mode generated for archiving model has been unusable. This step is very important non-!

  2. Change archive mode to the non-archive mode:

    1)SQL>SHUTDOWN NORMAL/IMMEDIATE;
    2)SQL>STARTUP MOUNT;
    3)SQL>ALTER DATABASE NOARCHIVELOG;
    4)SQL>ALTER DATABASE OPEN;
  3. Enable automatic archiving: LOG_ARCHIVE_START = TRUE
    Archive mode, log files are not allowed to be covered group (overwritten), when the log file is full, if no manual filing, then the system will hang until the archive is complete.
    At this time I can only read but not write.
    During operation shut down and restart the process archive log
    SQL>ARCHIVE LOG STOP
    SQL>ARCHIVE LOG START
  4. Manual Archiving: LOG_ARCHIVE_START = FALSE
    Archive the current log file
    SQL>ALTER SYSTEM ARCHIVE LOG CURRENT;
    Archive number is 052 log files
    SQL>ALTER SYSTEM ARCHIVE LOG SEQUENCE 052;
    All archived log files
    SQL>ALTER SYSTEM ARCHIVE LOG ALL;
    Change archive log target
    SQL>ALTER SYSTEM ARCHIVE LOG CURRENT TO '&PATH';
  5. Conversion archive mode and a non-filing mode
    The reverse process of step 4.
  6. Configure multiple archive processes
    Q: When do I need to use multiple archiving process?
    A: If the archiving process will consume a lot of time, you can start multiple archiving process, this is a dynamic parameters, can be modified dynamically using ALTER SYSTEM.
    SQL>ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=10;
    Oracle9i can specify up to 10 filing process
    Dynamic performance views with the archiving process-related
    v$bgprocess,v$archive_processes
  7. Configure archiving target, multi-target archiving, remote archive destination, archive log format
    Archive goal LOG_ARCHIVE_DEST_n
    Local Archiving objectives:
    SQL>LOG_ARCHIVE_DEST_1 = "LOCATION=D:ORACLEARCHIVEDLOG";
    Remote archive destination:
    SQL>LOG_ARCHIVE_DEST_2 = "SERVICE=STANDBY_DB1";
    Forced archiving target, if an error occurs, retry after 600 seconds:
    SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_4 = "LOCATION=E:ORACLEARCHIVEDLOG MANDATORY REOPEN=600";
    Optional archiving target, if wrong, abandon the archive:
    SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_3 = "LOCATION=E:ORACLEARCHIVEDLOG OPTIONAL";
    Archiving target state: closed and open archive destination archive destination
    Close archiving target 1
    SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_1 = DEFER
    Open the archive target 2
    SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2 = ENABLE
    Archive log format
    LOG_ARCHIVE_FORMAT
  8. Get the archive log information
    V$ARCHIVED_LOG
    V$ARCHIVE_DEST
    V $ LOG_HISTORY
    V$DATABASE
    V$ARCHIVE_PROCESSES
    ARCHIVE LOG LIST;

Check oracle is turned flashback to view delete records

  

  Check oracle flashback function is turned on,
  --FLASHBACK_ON to NO, it means Flashback features not enabled

   select log_mode,open_mode,flashback_on from v$database;


  View deleting records oracle

   select * from user_recyclebin;

  

 

 

 After a difficult process described above, the following operate Flashback:

  (One)

  If you turn on flashback can use the Flashback Table.
  select log_mode, flashback_on from v $ database ;
  if the result is below the opening flashback
  LOG_MODE FLASHBACK_ON
  ------------ ------------------
  ARCHIVELOG YES


  Can execute the command
  alter table table enable row movement; - turn table row moving
  flashback table to_timestamp timestamp table to ( '20,130,813 14:00:00', 'YYYYMMDD HH24: mi The: SS');
  - flash back at 14:00 on August 13 2013


  If you do not open, logical backup can use imp command to import data.
  If useless logical backup, open archive mode, the physical backup can be shut down, data loss, it can be employed not fully restored
  by rman login
  rman target /
  execute command
  RUN {the shutdown immediate;
  Startup Mount;
  SET an until Time = "TO_DATE ( '20,130,813 14:00:00', 'YYYYMMDD HH24: mi The: SS') ";
  Restore Database;
  Recover Database;
  ALTER Open Database RESETLOGS;}
  remember! Before doing anything more than make a backup, or a problem with regret.
  And I suggest you contact your database administrator to deal with this problem.

 

  (two)

  

If only one table, then it is quite simple.

 

Below is an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
SQL>  CREATE  TABLE  test_fb_table (
   2    ID    int ,
   3    VAL  VARCHAR2(10)
   4  );
Table  created.
SQL>  INSERT  INTO  test_fb_table   VALUES  (1,  'TEST' );
1 row created.
SQL>  commit ;
Commit  complete.
 
假如 数据被错误的删除/更新
需要检索某个时间点上,表原有的数据。
SQL>  SELECT  TO_CHAR(sysdate,  'yyyy-mm-dd hh24:mi:ss' FROM  dual;
TO_CHAR(SYSDATE, 'YYYY-MM-DDHH24:MI:SS'
--------------------------------------
2010-11-07 13:01:37
 
这里删除掉数据。
SQL>  delete  from  test_fb_table;
1 row deleted.
SQL>  commit ;
Commit  complete.
 
确认数据已经被删除。
SQL>  select  from  test_fb_table;
no  rows  selected

 

1
2
3
4
5
6
7
这里检索出,指定时间点上,指定表的数据情况。
SQL>  select  from  test_fb_table
   2     AS  OF  TIMESTAMP  TO_TIMESTAMP( '2010-11-07 13:01:37' ,
   3       'yyyy-mm-dd hh24:mi:ss' );
         ID VAL
---------- --------------------
          1 TEST

 

 

 

For you, that is, you need to

 

Temporary table CREATE TABLE AS

select * from your table that deleted data   

AS OF TIMESTAMP TO_TIMESTAMP('2013-08-13 14:00:00',  'yyyy-mm-dd hh24:mi:ss');

 

 

In this way, had put on that point in time, that table data copied to a temporary table inside.

after that

INSERT INTO that your deleted data table SELECT * FROM temporary table;

 

 

Note: You need to determine what, that deleted data table above, there is no trigger or something.

Yes, you may need to temporarily disable the swap, insert data recovery over again.

  (C) (no dba privileges)

  If you have a database backup and log backup, in order to solve your problem, to restore data to a point in time.

Otherwise it is impossible to achieve.

If you have a backup, you can let the DBA to help restore a new database, and then copy the data you out of this table to the original database.

  (D) (dba no permission)

Need to use the flash back to the table flashback table, you can not do, find it dba

 

Guess you like

Origin www.cnblogs.com/cainiaoputeng/p/11119972.html