All technological notes.
Table point-in-time recovery (TPITR)Table point-in-time recovery (TPITR)
Specify RECOVER command with:
backup based on your specification.auxiliary instance.auxiliary instance.Data Pump export dump file that contains the recovered objects.target database.Scenario to recover tables and table partitions from RMAN backups:
to recover a tablespace that is not self-contained to a particular point in time.
PURGE option
Flashback Drop functionality.SCN is beyond the available undo
Flashback Tabledata definition language (DDL) operation has changed the structure of tables.
Flashback Table to rewind a table to before the point of a structural change, such as a truncate table operation.Prerequisites
target database must be:
read/write modeARCHIVELOG modeLimitations:
sys schemaSYSTEM and SYSAUX tablespacesCONNECT TARGET command.RECOVER TABLE command.auxiliary instance
AUXILIARY DESTINATION or SET NEWNAME clauses.AUXILIARY DESTINATION is the recommended clause, because if you use SET NEWNAME and you forget just one data file name, the recovery would not happen.auxiliary instance.Data Pump export dump file that contains the recovered objects. with the DUMP FILE=name and DATAPUMP DESTINATION=<O0S path>.
export dump file (with the pump FILE clause, default OS-specific name) that is used to store the metadata from the source database.DATAPUMP DESTINATION clause.
dump file.AUXILIARY DESTINATION location.DUMP FILE exists in the location in which the dump file must be created, then the export fails. 不会覆盖, 所以会出错NOTABLEIMPORT clause not to import the recovered objects
Data Pump Import utility.REMAP TABLE and the REMAP TABLESPACE clauses.
REMAP option is not specified and a table already exists, then the table recovery generates an error.REMAP option is specified, then the indexes and constraints are not imported.
REMAP TABLESPACE clauses:
tablespace that is different from the one in which the objects originally existed.ARCHIVELOG mode.show parameter compatible
-- NAME TYPE VALUE
-- ----------------- ------- ------
-- compatible string 19.0.0
-- noncdb_compatible boolean FALSE
show parameter db_recovery_file_dest
-- NAME TYPE VALUE
-- -------------------------- ----------- ----------------------------------
-- db_recovery_file_dest string /u01/app/oracle/fast_recovery_area
-- db_recovery_file_dest_size big integer 10G
ALTER SESSION SET container=cdb$root;
SELECT NAME, LOG_MODE, OPEN_MODE
FROM V$DATABASE;
-- ORCL ARCHIVELOG READ WRITE

rman target /
show CONTROLFILE AUTOBACKUP;
EXIT

tee command to output both to a log file and to standard outputrman target "'/ as sysbackup'" | tee /home/oracle/rman_16.log
mkdir -p /home/oracle/auxilary
sqlplus / as sysdba
ALTER SESSION SET container=orclpdb;
show con_name
-- 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/bartbs.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;
ALTER SESSION SET container=cdb$root;
ALTER SYSTEM SWITCH logfile;
ALTER SESSION SET container=orclpdb;
ALTER SYSTEM checkpoint;
-- confirm user and tbsp have been created
ALTER SESSION SET container=orclpdb;
SELECT TABLE_NAME, TABLESPACE_NAME, STATUS
FROM DBA_TABLES
WHERE OWNER = 'BAR';
-- BARCOPY BARTBS VALID

rman target /
backup incremental level 0 database plus archivelog;

BAR.TEST TABLE
ALTER SESSION SET container=orclpdb;
-- drop existing tb
DROP TABLE BAR.test_table;
-- create tb
CREATE TABLE BAR.test_table
(
NUM number(8),
NAME varchar2(25),
NOW date
);
-- insert data
INSERT INTO BAR.test_table VALUES (1,'First test row',sysdate);
INSERT INTO BAR.test_table VALUES (2,'Second test row',sysdate);
INSERT INTO BAR.test_table VALUES (3,'Third test row',NULL);
commit;
ALTER SESSION SET container=cdb$root;
ALTER SYSTEM SWITCH logfile;
ALTER SESSION SET container=orclpdb;
ALTER SYSTEM checkpoint;
-- get the SCN after commit
-- this scn will be used in TPITR
SELECT NAME, CURRENT_SCN
FROM V$DATABASE;
-- ORCL 7617425
-- confirm data
SELECT *
FROM BAR.TEST_TABLE;
-- First test row 23-May-2024
-- Second test row 23-May-2024
-- Third test row


rman target /
backup incremental level 1 database plus archivelog;
exit

-- Query scn before purging
SELECT NAME, CURRENT_SCN
FROM V$DATABASE;
-- purge test table
drop table BAR.test_table purge;
-- confirm purge of table
SELECT table_name
FROM dba_tables
WHERE owner = 'BAR';
-- BARCOPY
-- Query scn after purging
SELECT NAME, CURRENT_SCN
FROM V$DATABASE;
-- 7617692


RECOVER command confirms that the auxiliary destination is empty.rman target /
HOST "ls /home/oracle/auxilary/*";
-- ls: cannot access /home/oracle/auxilary/*: No such file or directory
-- host command complete
-- RMAN-00571: ===========================================================
-- RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
-- RMAN-00571: ===========================================================
-- RMAN-06135: error executing host command: Additional information: 512

RECOVER TABLE BAR.TEST_TABLE OF PLUGGABLE DATABASE orclpdb
UNTIL SCN 7617425 -- replace the SCN after the commit.
AUXILIARY DESTINATION '/home/oracle/auxilary/';
RMAN performs the following tasks: a. Determines the backup based on the SCN you provide b. Creates an auxiliary instance c. Recovers your tables or table partitions, up to the specified point in time, into this auxiliary instance d. Creates a Data Pump export dump file that contains the recovered objects e. Imports the recovered objects into the target database f. Removes the auxiliary instance

SELECT *
FROM BAR.TEST_TABLE;

delete noprompt obsolete;

sqlplus / as sysdba
ALTER SESSION SET container=orclpdb;
-- CLEANUP from previous run
DROP USER bar CASCADE;
DROP TABLESPACE bartbs INCLUDING CONTENTS AND DATAFILES;
rm -rf /home/oracle/auxilary/*ORCL