Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Daniel T. Liu
Senior Technical Consultant
First American Real Estate Solutions
Date: Tuesday, February 8, 2005 @ 2:15 PM - 3:15 PM Venue: Room 103, Oracle Conference Center, Redwood Shores, CA
Agenda
Introduction
Oracle Database 10g Challenges for Backup and Recovery Types of Database Errors Backup and Recovery Solutions
Agenda
Extended Flashback Features Enhanced RMAN Features Summary Q&A
Human Errors
Accidentally drop, or truncate a table Accidentally delete, update rows in a table Accidentally delete a data file or drop a tablespace
Disasters
War, terrorism Earthquake, flood, fire or hurricane No power for a long period of time Server crash, malfunction of hardware
NoCOUG 2005, Daniel T. Liu 7
Physical Methods
O/S Backup and Restore RMAN Backup and Restore
Flashback Database
Traditional recovery method uses backups and redo log files; Flashback Database is implemented using a new type of log file called Flashback Database logs. The Oracle database server periodically logs before images of data blocks in the Flashback Database logs. The data block images are used to quickly back out changes to the database during Flashback Database.
NoCOUG 2005, Daniel T. Liu 10
Flashback Database
Flashback Database reduces the time required to recover the database to a point in time. The time to restore a database is proportional to the number of changes that need to be backed out, not the size of the database. Flashback Database is faster than traditional point-in-time recovery.
NoCOUG 2005, Daniel T. Liu 11
Flashback Database
DATABASE
LGWR
RVWR
12
Flashback Database
The list below shows all the background processes for grid instance.
$ ps -ef oracle oracle oracle oracle oracle oracle oracle oracle oracle oracle oracle | grep grid 25124 1 25116 1 25169 1 25112 1 25110 1 25108 1 25114 1 25118 1 25120 1 25122 1 25106 1 0 0 0 0 0 0 0 0 0 0 0 16:32:05 16:32:04 16:32:22 16:32:04 16:32:04 16:32:04 16:32:04 16:32:04 16:32:04 16:32:04 16:32:04 ? ? ? ? ? ? ? ? ? ? ? 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 ora_s000_grid ora_reco_grid ora_rvwr_grid ora_ckpt_grid ora_lgwr_grid ora_dbw0_grid ora_smon_grid ora_cjq0_grid ora_rbal_grid ora_d000_grid ora_pmon_grid
13
Open the database in MOUNT EXCLUSIVE mode and turn on the flashback feature: SQL> STARTUP MOUNT EXCLUSIVE; SQL> ALTER DATABASE FLASHBACK ON; Set the Flashback Database retention target:
DB_FLASHBACK_RETENTION_TARGET
NoCOUG 2005, Daniel T. Liu 14
Determine if Flashback Database is enabled SQL> select flashback_on 2 from v$database; FLASHBACK_ON -----------YES
NoCOUG 2005, Daniel T. Liu 15
16
Flashback Database
Example 1: Flashback a Database using RMAN
RMAN> FLASHBACK DATABASE 2> TO TIME = TO_DATE 3> (06/25/03 12:00:00,MM/DD/YY HH:MI:SS);
Flashback Drop
Prior to Oracle 10g, a DROP command permanently removed objects from the database. SQL> DROP TABLE CUSTOMERS; In Oracle 10g, a DROP command places the object in the recycle bin. The extents allocated to the segment are not reallocated until you purge the object. You can restore the object from the recycle bin at any time.
NoCOUG 2005, Daniel T. Liu 19
Recycle Bin
A recycle bin contains all the dropped database objects until,
You permanently drop them with the PURGE command. Recover the dropped objects with the FLASHBACK TABLE command. There is no room in the tablespace for new rows or updates to existing rows. The tablespace needs to be extended.
NoCOUG 2005, Daniel T. Liu 20
Recycle Bin
You can view the dropped objects in the recycle bin from two dictionary views:
USER_RECYCLEBIN: list all dropped user objects DBA_RECYCLEBIN: list all dropped systemwide objects
21
23
24
27
removes
the
table
Table purged.
28
Flashback Table
Flashback Table allows you to recover a table or tables to a specific point in time without restoring a backup. When you use the Flashback Table feature to restore a table to a specific point in time, all associated objects, such as, indexes, constraints, and triggers will be restored.
31
Flashback Table
Flashback Table operations are not valid for the following object types:
Tables that are part of a cluster Materialized views Advanced Queuing tables Static data dictionary tables System tables Partitions of a table Remote tables (via database link)
NoCOUG 2005, Daniel T. Liu 32
UNDO_RETENTION Parameter
Data used to recover a table is stored in the undo tablespace. You can use the parameter UNDO_RETENTION to set the amount of time you want undo information retained in the database. The default value for UNDO_RETENTION is 900 seconds (15 minutes).
33
Guaranteed Retention
When an active transaction uses all the undo tablespace, the system will start reusing undo space that would have been retained unless you have specified RETENTION GUARANTEE for the tablespace. To create an undo tablespace with the RETENTION GUARANTEE option, issue the following command:
SQL> CREATE UNDO TABLEAPCE undo_tbs DATAFIEL /u02/oradata/grid/undo_tbs01.dbf SIZE 1 G RETENTION GUARANTEE;
NoCOUG 2005, Daniel T. Liu 34
35
This statement brings a table billing back to a certain SCN number; SQL> FLASHBACK TABLE billing TO SCN 76230;
NoCOUG 2005, Daniel T. Liu 36
37
Example 1
To verify the retention value for the tablespace, you can issue the following statement:
SQL> select tablespace_name, retention 2 From dba_tablespaces; TABLESPACE_NAME RETENTION ------------------------------ ----------SYSTEM NOT APPLY UNDOTBS1 NOGUARANTEE SYSAUX NOT APPLY TEMP NOT APPLY
NoCOUG 2005, Daniel T. Liu 41
Example 2
SQL> create table emp (name varchar2(10), salary number(8,2)); Table created. SQL> insert into emp values ('DANIEL',2000); 1 row created.
Example 2
SQL> update emp set salary = 3000 where name = 'DANIEL'; 1 row updated. SQL> commit;
Commit complete.
43
Example 2
SQL> select * from emp; NAME SALARY ---------- ---------DANIEL 3000
SQL> select * from emp versions between scn minvalue and maxvalue; NAME SALARY ---------- ---------DANIEL 3000 DANIEL 2000
NoCOUG 2005, Daniel T. Liu 44
Type -------------RAW(8) NUMBER DATE NUMBER DATE VARCHAR2(30) NUMBER VARCHAR2(32) VARCHAR2(256) VARCHAR2(32) VARCHAR2(19) VARCHAR2(4000)
46
Example
SQL> select versions_xid, name, salary 2 from emp 3 versions between scn minvalue and maxvalue; VERSIONS_XID NAME SALARY ---------------- ---------- ---------0003000E00000FE2 DANIEL 3000 DANIEL 2000 SQL> select * 2 from flashback_transaction_query 3 where xid = '0003000E00000FE2';
47
Example
SQL> select xid, start_scn, start_timestamp, 2 table_name, undo_sql 3 from flashback_transaction_query 4 where xid = '0009001F000000B2; XID START_SCN START_TIMESTAMP TABLE_NAME UNDO_SQL ---------------- -----------------------------------------------------------------------------------------------------------------0009001F000000B2 714980 Feb 21 2004 23:30:31 EMP update "ORACLE"."EMP" set "SALARY" = 2000' where ROWID = 'AAAMWJAAEAAAAFsAAA';
NoCOUG 2005, Daniel T. Liu 48
Summary - Flashback
Flashback Database Flashback Drop Flashback Table Flashback Versions Query Flashback Transaction Query
49
data file #1
data file #2
RMAN
Control fle
52
53
58
64
Step 2
Data File
65
66
67
68
69
70
71
74
75
76
78
79
80
81
RMAN Database Dropping and Deregistration The above two statements drop the database and delete the database files. However, they do not unregister the database from the RMAN catalog. The following statement will remove the database information from the RMAN catalog:
RMAN> unregister database grid;
NoCOUG 2005, Daniel T. Liu 83
Summary
Oracle Database 10g Grid Computing Challenges For Backup and Recovery Different Types of Database Errors Solutions for Backup and Recovery Oracle 10g Extended Flashback Features Oracle 10g Enhanced RMAN Features
NoCOUG 2005, Daniel T. Liu 85
References
Oracle Database 10g New Features, Ault, Liu and Tumma; Rampant Techpress; Recovery Manager Reference, 10g Release; Backup and Recovery Advanced Users Guide, 10g Release;
I would also like to acknowledge the assistance of Larry Bailey of FARES, Tammy Bednar, Larry Carpenter, Roger Peterson, Schwinn Ulrike of Oracle Corporation.
87