By Randy Richeson, Senior Principal Oracle University Instructor
Students often ask if a table can be recovered to a point in time and whether GoldenGate can capture this recovery. Oracle 12c enables you to recover one or more tables or table partitions to a specified point in time without affecting the remaining database objects. This new RMAN functionality reduces the recovery scope and possibly the recovery time and disk space requirements when compared with Database point-in-time-recovery, tablespace point-in-time recovery, and various flashback features which were introduced prior to 12c.
When combined with GoldenGate 12c configured to capture both DML and DDL from a source database, the table recovery can be replicated to a target database effectively recovering 2 tables with 1 RMAN command. The following demo shows how table recovery can be used to recover a table that is part of a replication stream.
This GoldenGate integrated extract is configured to process DML and DDL for the source WEST schema tables.
GGSCI (eddnr2p0) 2> view param extwest
extract extwest
useridalias gguamer
statoptions resetreportstats
report at 00:01
reportrollover at 00:01
reportcount every 60 seconds, rate
reportcount every 1000 records
exttrail ./dirdat/ew
ddl include mapped objname west.*;
ddloptions addtrandata, report
table west.*;
There are 1063 rows in the source AMER database WEST.ACCOUNT table.
AMER_WEST_SQL>select name from v$database;
NAME
---------
AMER
AMER_WEST_SQL>select count(*) from account;
COUNT(*)
----------
1063
AMER_WEST_SQL>select * from account where account_number > 6000;
ACCOUNT_NUMBER ACCOUNT_BALANCE
-------------- ---------------
7000 7000
8000 8000
9000 9000
This GoldenGate integrated replicat is configured to apply DML and DDL to the target EURO database EAST.ACCOUNT table.
GGSCI (eddnr2p0) 2> view param reast
replicat reast
assumetargetdefs
discardfile ./dirrpt/reast.dsc, purge
useridalias ggueuro
ddl include mapped
map west.*, target east.*;
The target EAST.ACCOUNT table has 1063 rows matching the source WEST.ACCOUNT table.
EURO_DATABASE_SQL>select name from v$database;
NAME
---------
EURO
EURO_DATABASE_SQL>select count(*) from account;
COUNT(*)
----------
1063
EURO_DATABASE_SQL>select * from account where account_number > 6000;
ACCOUNT_NUMBER ACCOUNT_BALANCE
-------------- ---------------
7000 7000
8000 8000
9000 9000
A whole RMAN backup is made of the source 'AMER' control file and datafiles.
[oracle@eddnr2p0 gg_amer]$rman target /
Recovery Manager: Release 12.1.0.1.0 - Production on Fri Oct 3 17:50:04 2014
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
connected to target database: AMER (DBID=1282626787)
RMAN> backup database;
Starting backup at 03-OCT-14
…….
Finished Control File and SPFILE Autobackup at 03-OCT-14
The current scn is queried so that it can be used in this recovery.
RMAN> select timestamp_to_scn(current_timestamp) from v$database;
TIMESTAMP_TO_SCN(CURRENT_TIMESTAMP)
-----------------------------------
2527804
Four transactions occur with negative account balances that logically corrupt the source WEST.ACCOUNT table.
AMER_WEST_SQL> update account set account_balance = -7000 where account_number = 7000;
1 row updated.
AMER_WEST_SQL> commit;
Commit complete.
AMER_WEST_SQL> update account set account_balance = -8000 where account_number = 8000;
1 row updated.
AMER_WEST_SQL> commit;
Commit complete.
AMER_WEST_SQL> update account set account_balance = -9000 where account_number = 9000;
1 row updated.
AMER_WEST_SQL> commit;
Commit complete.
AMER_WEST_SQL> insert into account values (9100,-9100);
1 row created.
AMER_WEST_SQL> commit;
Commit complete.
AMER_WEST_SQL> select count(*) from account;
COUNT(*)
----------
1064
AMER_WEST_SQL> select * from account where account_number > 6000;
ACCOUNT_NUMBER ACCOUNT_BALANCE
-------------- ---------------
7000 -7000
8000 -8000
9000 -9000
9100 -9100
The extract captures the changes from the source WEST.ACCOUNT table and the replicat applies them to the target EAST.ACCOUNT table resulting in negative balances in both tables.
EURO_EAST_SQL> select * from account where account_number > 6000;
ACCOUNT_NUMBER ACCOUNT_BALANCE
-------------- ---------------
7000 -7000
8000 -8000
9000 -9000
9100 -9100
The new 12c recover table command recovers the source table to the time before the updates that corrupted the data using the specified scn and the backups that were previously created. In this example, 'UNTIL SCN' is used. As an alternative, 'UNTIL_TIME' or 'UNTIL_SEQUENCE' can be used. RMAN determines the backup based on the scn and then creates an auxiliary instance to recover the table. RMAN then creates a Data Pump export dump file that contains the recovered table and imports the recovered table into the database. The recovered table is renamed to WEST.ACCOUNT_R so that the recovered data can be compared against the original data in the WEST.ACCOUNT table. During the recovery, the source AMER and target EURO databases remain open.
RMAN> recover table west.account until scn 2527804 auxiliary destination '/u01/app/oracle/backup' remap table 'WEST'.'ACCOUNT':'ACCOUNT_R';
Starting recover at 03-OCT-14
….
Finished recover at 03-OCT-14
After the table recovery, the rows are counted and the data compared between the original and newly recovered table in the source database.
RMAN> select count(*) from west.account;
COUNT(*)
----------
1064
RMAN> select count(*) from west.account_r;
COUNT(*)
----------
1063
RMAN> select * from west.account where account_number > 6000;
ACCOUNT_NUMBER ACCOUNT_BALANCE
-------------- ---------------
7000 -7000
8000 -8000
9000 -9000
9100 -9100
RMAN> select * from west.account_r where account_number > 6000;
ACCOUNT_NUMBER ACCOUNT_BALANCE
-------------- ---------------
7000 7000
8000 8000
9000 9000
The pump extract and integrated replicat RBA's advance as the recovery changes are captured from the source database and applied to the target database.
GGSCI (eddnr2p0) 3> info *west
EXTRACT EXTWEST Last Started 2014-10-03 16:52 Status RUNNING
Checkpoint Lag 00:00:06 (updated 00:00:08 ago)
Process ID 21186
Log Read Checkpoint Oracle Integrated Redo Logs
2014-10-03 18:17:47
SCN 0.2533283 (2533283)
EXTRACT PWEST Last Started 2014-10-03 12:26 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:04 ago)
Process ID 14346
Log Read Checkpoint File ./dirdat/ew000009
2014-10-03 18:13:33.000000 RBA 289288
GGSCI (eddnr2p0) 1> info reast
REPLICAT REAST Last Started 2014-10-03 16:51 Status RUNNING
INTEGRATED
Checkpoint Lag 00:00:00 (updated 00:00:08 ago)
Process ID 21155
Log Read Checkpoint File ./dirdat/pe000005
2014-10-03 18:03:43.896883 RBA 171400
The target EAST.ACCOUNT table remains at the original row count while the EAST.ACCOUNT_R is created with the recovered rows.
EURO_EAST_SQL> select count(*) from account;
COUNT(*)
----------
1064
EURO_EAST_SQL> select * from account where account_number > 6000;
ACCOUNT_NUMBER ACCOUNT_BALANCE
-------------- ---------------
7000 -7000
8000 -8000
9000 -9000
9100 -9100
EURO_EAST_SQL> select count(*) from account_r;
COUNT(*)
----------
1063
EURO_EAST_SQL> select * from account_r where account_number > 6000;
ACCOUNT_NUMBER ACCOUNT_BALANCE
-------------- ---------------
7000 7000
8000 8000
9000 9000
Supplemental logging on the new WEST.ACCOUNT_R table needs to be enabled for subsequent changes to be applied by the replicat to the target database.
GGSCI (eddnr2p0) 2> dblogin useridalias gguamer
Successfully logged into database.
GGSCI (eddnr2p0) 3> info trandata west.account*
Logging of supplemental redo log data is enabled for table WEST.ACCOUNT.
Columns supplementally logged for table WEST.ACCOUNT: ACCOUNT_NUMBER.
Logging of supplemental redo log data is disabled for table WEST.ACCOUNT_R.
Logging of supplemental redo log data is enabled for table WEST.ACCOUNT_TRANS.
Columns supplementally logged for table WEST.ACCOUNT_TRANS: TRANS_NUMBER, ACCOUNT_NUMBER, ACCOUNT_TRANS_TS.
After the corrupted WEST.ACCOUNT table is dropped, the extract captures and the replicat applies the drop operation.
AMER_WEST_SQL> drop table account;
Table dropped.
EURO_EAST_SQL> select * from account;
select * from account
*
ERROR at line 1:
ORA-00942: table or view does not exist
After the recovered WEST.ACCOUNT_R is renamed, the extract captures the rename operation and the replicat applies it.
AMER_WEST_SQL> alter table account_r rename to account;
Table altered.
The RMAN table recovery and resulting rename operation results in the WEST.ACCOUNT table having no unique key, which may be added since primary keys are recommended. Supplement logging is enabled to allow for the delivery of updates and deletes by the replicat.
GGSCI (eddnr2p0) 5> info trandata west.account
Logging of supplemental redo log data is disabled for table WEST.ACCOUNT.
GGSCI (eddnr2p0) 6> add trandata west.account
2014-10-03 18:26:47 WARNING OGG-06439 No unique key is defined for table ACCOUNT. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo data enabled for table WEST.ACCOUNT.
TRANDATA for scheduling columns has been added on table 'WEST.ACCOUNT'.
Rows are counted to verify that the account table has the correct count with the recovered data.
EURO_EAST_SQL> select count(*) from account;
COUNT(*)
----------
1063
EURO_EAST_SQL> select count(*) from account where account_number > 6000;
COUNT(*)
----------
3
EURO_EAST_SQL> select * from account where account_number > 6000;
ACCOUNT_NUMBER ACCOUNT_BALANCE
-------------- ---------------
7000 7000
8000 8000
9000 9000
AMER_WEST_SQL> select * from account where account_number > 6000;
ACCOUNT_NUMBER ACCOUNT_BALANCE
-------------- ---------------
7000 7000
8000 8000
9000 9000
RMAN 12c table recovery, combined with GoldenGate 12c configured to capture DML and DDL from a source database, provides a powerful combination that allows a DBA to quickly recover two tables with 1 RMAN command.
Book a seat now in an upcoming Oracle Database 12c: New Features for Administrators class to learn much more about using Oracle 12c new features including Multitenant features, Enterprise Manager 12c, Heat Map and Automatic Data Optimization, In-Database Archiving and Temporal, Auditing, privileges, Data Redaction, RMAN, Real Time Database Monitoring, Schema and Data Change Management, SQL Tuning Enhancements, Emergency Monitoring, ADR, In Memory Caching, SQL Tuning enhancements, Resource Manger, Partitioning, and JSON.
Explore Oracle University Database classes here, or send me an email at randy.richeson[at]oracle.com if you have other questions.
About the Author:
![]() | Randy Richeson joined Oracle University as a Senior Principal Instructor in March 2005. He is an Oracle Certified Professional (10g - 12c) and GoldenGate Certified Implementation Specialist (10g - 11g). He has taught Oracle Database technology since 1997 and other technical curriculums including GoldenGate Software, GoldenGate Management Pack, GoldenGate Director, GoldenGate Veridata, JD Edwards, PeopleSoft, and the Oracle Application Server since 1997. |