10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.
-
Upload
charles-allison -
Category
Documents
-
view
224 -
download
4
Transcript of 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.
![Page 1: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/1.jpg)
10Copyright © 2004, Oracle. All rights reserved.
Recovering from User Errors
![Page 2: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/2.jpg)
10-2 Copyright © 2004, Oracle. All rights reserved.
Objectives
After completing this lesson, you should be able to:
• Perform Flashback table operation
• Manage the recycle bin
• Recover from user errors using Flashback versions query
• Perform transaction level recovery using Flashback Transaction query
![Page 3: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/3.jpg)
10-3 Copyright © 2004, Oracle. All rights reserved.
Flashback Time Navigation
• Flashback Query– Query all data at a specified point in time
• Flashback Versions Query– See all versions of a row between two times– See the transactions that changed the row
• Flashback Transaction Query– See all changes
made by a transaction
Tx3
Tx1
Tx2
Time
Flashback
![Page 4: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/4.jpg)
10-4 Copyright © 2004, Oracle. All rights reserved.
Flashback Drop Overview
DROP TABLE employees; FLASHBACK TABLEemployeesTO BEFORE DROP;
Mistake wasmade
![Page 5: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/5.jpg)
10-5 Copyright © 2004, Oracle. All rights reserved.
Recycle Bin
DROP TABLE employees;
BIN$zbjra9wy==$0EMPLOYEES_PK
EMPLOYEES
Recyclebin
DBA_FREE_SPACE
BIN$zbjrBdpw==$0
USER_OBJECTS
BIN$zbjrBdpw==$0 EMPLOYEESBIN$zbjra9wy==$0 EMPLOYEES_PK
12
3
4
![Page 6: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/6.jpg)
10-6 Copyright © 2004, Oracle. All rights reserved.
Querying the Recycle Bin
SELECT owner, original_name, object_name, type, ts_name, droptime, related, spaceFROM dba_recyclebinWHERE can_undrop = 'YES';
SELECT original_name, object_name, type, ts_name, droptime, related, spaceFROM user_recyclebinWHERE can_undrop = 'YES';
SQL> SHOW RECYCLEBIN
![Page 7: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/7.jpg)
10-8 Copyright © 2004, Oracle. All rights reserved.
Flashback Dropped Tables Using EM
![Page 8: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/8.jpg)
10-9 Copyright © 2004, Oracle. All rights reserved.
Restoring Objects from the Recycle Bin
• Use the FLASHBACK TABLE … command to restore dropped tables and dependent objects.
• If multiple recycle bin entries have the same original name:– Use unique system-generated names to restore a
particular version.– When using original names, restored table is LIFO.
• Rename the original name if that name is currently used.
FLASHBACK TABLE <table_name>TO BEFORE DROP [RENAME TO <new_name>]
![Page 9: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/9.jpg)
10-10 Copyright © 2004, Oracle. All rights reserved.
Recycle Bin Automatic Space Reclamation
BIN$zbjrBdpw==$0 BIN$zbjra9wy==$0
BIN$zbjra9wy==$0
BIN$zbjrBdpw==$0
1
2
3
Recycle bin
DBA_FREE_SPACE - RECYCLEBIN
Autoextend
![Page 10: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/10.jpg)
10-12 Copyright © 2004, Oracle. All rights reserved.
Recycle Bin Manual Space Reclamation
PURGE {TABLE <table_name>|INDEX <index_name>}
PURGE TABLESPACE <ts_name> [USER <user_name>]
PURGE [USER_|DBA_]RECYCLEBIN
![Page 11: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/11.jpg)
10-14 Copyright © 2004, Oracle. All rights reserved.
Bypassing the Recycle Bin
DROP TABLESPACE <ts_name> [INCLUDING CONTENTS] ;
DROP USER <user_name> [CASCADE] ;
DROP TABLE <table_name> [PURGE] ;
![Page 12: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/12.jpg)
10-15 Copyright © 2004, Oracle. All rights reserved.
Querying Dropped Tables
SELECT ... FROM BIN$zbjrBdpw==$0 [AS OF ...]WHERE ...
Recyclebin
USER_INDEXES
YES
INDEX_NAMEDROPPED
NO SALES_PK
USER_TABLES
BIN$zbjrBdpw==$0 EMPLOYEES
BIN$zbjra9wy==$0 EMPLOYEES_PK
TABLE_NAMEDROPPED
YES
NO SALES
![Page 13: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/13.jpg)
10-16 Copyright © 2004, Oracle. All rights reserved.
Flashback Drop Considerations
• Protected tables:– Are non-SYSTEM tablespace tables– Are stored in locally managed tablespaces– Do not use fine-grained auditing or virtual private
database
• The following dependencies are not protected:– Bitmap-join indexes– Materialized view logs– Referential integrity constraints– Indexes dropped before tables
• Purged tables cannot be flashed back
![Page 14: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/14.jpg)
10-17 Copyright © 2004, Oracle. All rights reserved.
Flashback Versions Query Overview
t1 t2
Tx1 Tx2
SELECT versions_xid, salary FROM employees
VERSIONS BETWEEN TIMESTAMP t1 and t2
WHERE last_name = 'Fox';
Tx0
Tx0 Tx1 Tx2
Employees Employees
Fox
Employees
![Page 15: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/15.jpg)
10-18 Copyright © 2004, Oracle. All rights reserved.
Flashback Versions Query Using EM
![Page 16: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/16.jpg)
10-19 Copyright © 2004, Oracle. All rights reserved.
Flashback Versions Query Syntax
Pseudocolumn Description
VERSIONS_STARTTIME
VERSIONS_STARTSCNVersion validity range lower bound
VERSIONS_ENDTIME
VERSIONS_ENDSCNVersion validity range upper bound
VERSIONS_XID Transaction that created the version
VERSIONS_OPERATION Operation that produced the version
SELECT [Pseudocolumns]…FROM … VERSIONS BETWEEN {SCN|TIMESTAMP {expr|MINVALUE} AND
{expr|MAXVALUE}} [AS OF {SCN|TIMESTAMP expr}]WHERE [Pseudocolumns…]…
![Page 17: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/17.jpg)
10-20 Copyright © 2004, Oracle. All rights reserved.
Flashback Versions Query Example
SELECT versions_xid AS XID,
versions_startscn AS START_SCN,
versions_endscn AS END_SCN,
versions_operation AS OPERATION, first_name
FROM employees
VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE
AS OF SCN 5525300
WHERE employee_id = 111;
XID START_SCN END_SCN O First_NAME---------------- ---------- ---------- -
-----------8C0025003A000000 5525293 I Tom8C0024003A000000 5525291 D Mike8C0022003A000000 5525277 5525291 I Mike
![Page 18: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/18.jpg)
10-21 Copyright © 2004, Oracle. All rights reserved.
Flashback Versions Query Considerations
• The VERSIONS clause cannot be used to query:– External tables– Temporary tables– Fixed tables– Views
• The VERSIONS clause cannot span DDL commands.
• Segment shrink operations are filtered out.
![Page 19: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/19.jpg)
10-22 Copyright © 2004, Oracle. All rights reserved.
Flashback Transaction Query Overview
UndoSQL
FLASHBACK_TRANSACTION_QUERY
DBA
USER
ErroneousDML
![Page 20: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/20.jpg)
10-23 Copyright © 2004, Oracle. All rights reserved.
Querying FLASHBACK_TRANSACTION_QUERY
SELECT operation, undo_sql, table_nameFROM FLASHBACK_TRANSACTION_QUERY;
SELECT operation, undo_sql, table_nameFROM FLASHBACK_TRANSACTION_QUERYWHERE xid = HEXTORAW('8C0024003A000000')ORDER BY undo_change#;
SELECT operation, undo_sql, table_nameFROM FLASHBACK_TRANSACTION_QUERYWHERE start_timestamp >= TO_TIMESTAMP('2003-10-21 11:00:00','YYYY-MM-DD HH:MI:SS')AND commit_timestamp <= TO_TIMESTAMP('2003-10-21 11:30:00','YYYY-MM-DD HH:MI:SS');
![Page 21: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/21.jpg)
10-24 Copyright © 2004, Oracle. All rights reserved.
Using Flashback Versions Queryand Flashback Transaction Query
SELECT operation, undo_sql
FROM FLASHBACK_TRANSACTION_QUERY
WHERE xid = HEXTORAW('8C0024003A000000');
SELECT versions_xid , first_name
FROM hr.employees
VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE
WHERE employee_id = 111;
![Page 22: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/22.jpg)
10-25 Copyright © 2004, Oracle. All rights reserved.
Flashback Transaction Query Using EM
![Page 23: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/23.jpg)
10-26 Copyright © 2004, Oracle. All rights reserved.
Flashback Transaction Query Considerations
• DDLs are seen as dictionary updates.
• Dropped objects appear as object numbers.
• Dropped users appear as user identifiers.
• Minimal supplemental logging may be needed:
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
![Page 24: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/24.jpg)
10-27 Copyright © 2004, Oracle. All rights reserved.
Flashback Table Overview
• Recover tables to a specific point in time
• Flashback Table is an in-place operation
• Database stays online
UserErroneous
DMLsFlashed back
tables
![Page 25: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/25.jpg)
10-28 Copyright © 2004, Oracle. All rights reserved.
Using EM to Flashback Tables
![Page 26: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/26.jpg)
10-29 Copyright © 2004, Oracle. All rights reserved.
Flashback Table Example
FLASHBACK TABLE employeesTO TIMESTAMP (SYSDATE-1);
ALTER TABLE employees ENABLE ROW MOVEMENT;
ALTER TABLE departments ENABLE ROW MOVEMENT;
FLASHBACK TABLE employees, departmentsTO SCN 5525293 ENABLE TRIGGERS;
ALTER TABLE employees ENABLE ROW MOVEMENT;
![Page 27: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/27.jpg)
10-30 Copyright © 2004, Oracle. All rights reserved.
Rolling Back a Flashback Table Operation
10:25 10:42 11:29 11:30 11:35
SCN:5525354
FLASHBACK TABLE jobs TO TIMESTAMP to_timestamp('10:42','hh24:mi');
11:30
HR.JOBS
FLASHBACK TABLE jobs TO SCN 5525354;
11:35
![Page 28: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/28.jpg)
10-31 Copyright © 2004, Oracle. All rights reserved.
Flashback Table Considerations
• The FLASHBACK TABLE command executes as a single transaction, acquiring exclusive DML locks.
• Statistics are not flashed back.
• Current indexes and dependent objects are maintained.
• Flashback Table operations:– Cannot be performed on system tables– Cannot span DDL operations– Are written to the alert log file
![Page 29: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/29.jpg)
10-32 Copyright © 2004, Oracle. All rights reserved.
Guaranteed Undo Retention
SQL> CREATE UNDO TABLESPACE undotbs1 2 DATAFILE 'undotbs01.dbf' 3 SIZE 100M AUTOEXTEND ON 4 RETENTION GUARANTEE ;
SQL> SELECT tablespace_name, RETENTION 2 FROM dba_tablespaces;
TABLESPACE_NAME RETENTION--------------- ---------UNDOTBS1 GUARANTEE... ...
SQL> ALTER TABLESPACE undotbs1 2> RETENTION NOGUARANTEE;
![Page 30: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/30.jpg)
10-33 Copyright © 2004, Oracle. All rights reserved.
SCN and Time Mapping Enhancements
• The mapping granularity is three seconds.
• The mapping is retained for Max(five days, UNDO_RETENTION)
• Access the mapping by using the following SQL functions:– SCN_TO_TIMESTAMP– TIMESTAMP_TO_SCN
SELECT current_scn, SCN_TO_TIMESTAMP(current_scn)FROM v$database;
CURRENT_SCN SCN_TO_TIMESTAMP(CURRENT_SCN)----------- -------------------------------3274940 23-SEP-03 02.56.03.000000000 AM
![Page 31: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/31.jpg)
10-34 Copyright © 2004, Oracle. All rights reserved.
Summary
In this lesson, you should have learned how to:
• Perform Flashback table operation
• Manage the recycle bin
• Recover from user errors using Flashback versions query
• Perform transaction level recovery using FB Transaction query
![Page 32: 10 Copyright © 2004, Oracle. All rights reserved. Recovering from User Errors.](https://reader035.fdocuments.net/reader035/viewer/2022062515/56649f505503460f94c738cb/html5/thumbnails/32.jpg)
10-35 Copyright © 2004, Oracle. All rights reserved.
Practice 10 Overview: Recovering from User Errors
This practice covers the following topics:
• Using Flashback to recover a dropped table
• Managing the recycle bin space
• Performing a Flashback Version Query