All technological notes.
Flashback TableFlashback TableFlashback Table:
point-in-time recovery operations.Prerequisite
row movement on a table to be able to flash back the table.
row movement, the Oracle server can move a row in the table.Characteristics:
undo tablespace从 undo tbsp 去回数据tables and their associated objects (indexes, constraints, triggers, and so on) is restored. 恢复相关对象Method to determine the appropriate flashback time:
Flashback Version QueryFlashback Transaction Query
Can recover from accidental modifications without a database administrator’s involvement.
FLASHBACK TABLE or FLASHBACK ANY TABLE system privilege to any user that uses the Flashback Table feature.SELECT, INSERT, DELETE, and ALTER object privileges to the user.Example:
FLASHBACK TABLE hr.departments
TO_TIMESTAMP ('2019-01-25 21:00:00', 'YYYY-MM-DD HH24:MI:SS');
FLASHBACK TABLE command executes as a single transaction
data manipulation language (DML) locks on all tables that are specified in the statement over the period of time the operation is in progress.indexes and dependent objects are maintained.
indexes are maintained.indexes are not re-created.materialized views are also maintained automatically.constraints are violated during flashback execution, the operation is aborted and the tables are left in the same state as they were just before the FLASHBACK TABLE statement invocation. 闪回不能违反约束system tables, remote tables, and fixed tables.DDL operations
Flashback Table to a particular time that is older than the time of the execution of a data definition language (DDL) operation that altered the structure of or shrunk a table that would be involved in the flashback operation.undo and redo datasqlplus / as sysdba
ALTER SESSION SET container=orclpdb;
-- CLEANUP from previous run
DROP USER bar CASCADE;
DROP TABLESPACE bartbs INCLUDING CONTENTS AND DATAFILES;
-- Create tablespace
CREATE TABLESPACE bartbs
DATAFILE '/u01/app/oracle/oradata/ORCL/orclpdb/bartbs1.dbf' SIZE 10M REUSE
SEGMENT SPACE MANAGEMENT MANUAL;
-- Create user
CREATE USER BAR IDENTIFIED BY pass4BAR
DEFAULT TABLESPACE bartbs
QUOTA UNLIMITED ON bartbs;
GRANT CREATE SESSION TO BAR;
-- create table and populate
-- be sure table is at least 2 blocks long
CREATE TABLE BAR.barcopy
TABLESPACE bartbs
AS SELECT * FROM HR.EMPLOYEES;
INSERT INTO BAR.BARCOPY
SELECT * FROM BAR.BARCOPY;
INSERT INTO BAR.BARCOPY
SELECT * FROM BAR.BARCOPY;
#-- Create backup of the bartbs tablespace
rman target /
BACKUP AS COPY TABLESPACE orclpdb:bartbs;
#-- update the table
sqlplus / as sysdba
ALTER SESSION set container=orclpdb;
UPDATE BAR.BARCOPY SET salary = salary+1;
COMMIT;
sqlplus / as sysdba
alter session set container=orclpdb;
-- create tb bar101
create table bar.bar101
as select * from BAR.BARCOPY;
ALTER TABLE BAR.BAR101
add (address_line1 VARCHAR2(200), address_line2 VARCHAR2(200));
-- create tb bar102
create table bar.bar102
as select * from BAR.BARCOPY;
ALTER TABLE BAR.BAR102
add (address_line1i VARCHAR2(200), address_line2 VARCHAR2(200));
-- drop tb bar102
drop table BAR.BAR102;
-- create new tb bar102
create table bar.bar102
as select * from BAR.BARCOPY;
ALTER TABLE BAR.BAR102
add (location_id NUMBER(12));
-- drop tb bar102
drop table bar.bar102;
-- drop tb bar101
drop table bar.bar101;
-- create new tb bar102
create table bar.bar102
as select * from BAR.BARCOPY;
ALTER TABLE BAR.BAR102 add (photo BLOB);
Requirement:
| Restore the requested table to BAR102A. |
SHOW RECYCLEBIN command to view the contents of the recycle bin for orclpdbl.sqlplus sys@orclpdb as sysdba;
SHOW RECYCLEBIN
-- return none
Note: The
SHOW RECYCLEBINcommand shows only those objects that belong to the current user. Because you are logged in as the sys user, theSHOW RECYCLEBINcommand does not show the dropped tables you are interested in restoring.
DBA_RECYCLEBIN view.select original_name, object_name, droptime
from dba_recyclebin
where owner ='BAR';

-- find the correct object with experted column
SELECT location_id
FROM BAR."BIN$GYdu7BtlD3fgYyUAqMCkFg==$0"
WHERE rownum = 1;


FLASHBACK TABLE BAR."BIN$GYdu7BtlD3fgYyUAqMCkFg==$0"
TO BEFORE DROP
RENAME TO BAR102A;
-- Flashback succeeded.
select *
from BAR.BAR102A
where rownum = 1;

rman target /
delete NOPROMPT copy of tablespace orclpdb:bartbs;
exit;
sqlplus / as sysdba
ALTER SESSION set container=orclpdb;
-- CLEANUP from previous run
DROP USER bar CASCADE;
DROP TABLESPACE bartbs INCLUDING CONTENTS AND DATAFILES;
PURGE DBA_RECYCLEBIN;