HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Oracle - restore a single table

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
tableoraclesinglerestore

Problem

In a large database, an activity was performed to upload the data.
Due to some mistake, a month's data was entered again, which was left in the temp holding table.
So, to cover this up, we took dump of 2 tables from the back-up restored on another machine.
Renamed the tables where error occurred and restored from the backup.
But when the tables were restored the constraints failed to load as the same name is already in use.
Used the oracle exp/imp commands to export and import the data.

I'm not a DBA, but need help on this issue.

Solution

You could use Flashback to return the table data back to its original state.

Is Flashback enabled?

Database needs to be in archive mode:

select log_mode from v$database;


Should return "ARCHIVEMODE"

Check if flashback is enabled:

select flashback_on from v$database;


Should return "YES"

If "NO", you can enable flashback by runing:

alter database flashback on;


Check undo retention:

show parameter undo


Default is 900 seconds (15-minutes). So you can Flashback a table to 15-minutes ago using this command:

Alter table t enable row movement ;

FLASHBACK TABLE t TO TIMESTAMP TO_TIMESTAMP ('2015-aug-11 12:00:00', 'YYYY-MON-DD HH24:MI:SS');


Other Flashback commands:

  • Flashback database = > enables you to take the entire database to a past point in time (using flashback logs, db_flashback_retention_target).



  • Flashback drop => lets you retrieve accidentally dropped tables and indexes (using the recycle bin).



  • Flashback table => lets you recover a table to a time in the past (using undo data).



  • Flashback query => lets you query and restore data rows to a point in time (using undo data).



For Flashback table using SCN see this link:
https://oracle-base.com/articles/10g/flashback-10g#flashback_table

Code Snippets

select log_mode from v$database;
select flashback_on from v$database;
alter database flashback on;
show parameter undo
Alter table t enable row movement ;

FLASHBACK TABLE t TO TIMESTAMP TO_TIMESTAMP ('2015-aug-11 12:00:00', 'YYYY-MON-DD HH24:MI:SS');

Context

StackExchange Database Administrators Q#109346, answer score: 6

Revisions (0)

No revisions yet.