1、flashback 全库
SQL> select flashback_on from v$database;
FLASHBACK_ON ------------------------------------ YES ? SQL> show parameter flashback
NAME ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TYPE ? ? ? ? ? ? ? ? ? VALUE ------------------------------------ ---------------------- ------------------------------ db_flashback_retention_target ? ? ? ?integer ? ? ? ? ? ? ? ?1440
(1)flashback 还原点
SQL> create table test as select * from dba_objects;
Table created.
SQL> create restore point rp guarantee flashback database;
Restore point created.
SQL> drop table test purge;
Table dropped.
SQL> shutdown immediate
SQL> startup mount
SQL> flashback database to restore point rp;
Flashback complete.
SQL> alter database open read only;
Database altered.
SQL> select count(*) from test;
? COUNT(*) ---------- ? ? ?72385 ?? ?? SQL> shutdown immediate?? ??
SQL> startup mount?? ??
SQL> alter database open resetlogs;
SQL> select count(*) from test;
? COUNT(*) ---------- ? ? ?72385
(2)flashback scn
SQL> select current_scn from v$database;
CURRENT_SCN ----------- ? ? 2253002
SQL> drop table test purge;
SQL> shutdown immediate
SQL> startup mount?? ?
SQL> flashback database to scn 2253002;
SQL> alter database open resetlogs;
SQL> select count(*) from test;
? COUNT(*) ---------- ? ? ?72385
(3)flashback timestamp
SQL> select sysdate from dual;
SYSDATE ------------------- 2022-10-24 14:32:32
SQL> drop table test purge; SQL> startup mount
SQL> flashback ?database ?to timestamp to_timestamp('2022-10-24 14:32:32','yyyy-mm-dd hh24:mi:ss');
SQL> alter database open resetlogs;
SQL> select count(*) from test;
? COUNT(*) ---------- ? ? ?72385
2、flashback pdb
SQL> show pdbs
? ? CON_ID CON_NAME ? ? ? ? ? ? ? ? ? ? ? OPEN MODE ?RESTRICTED ---------- ------------------------------ ---------- ---------- ? ? ? ? ?2 PDB$SEED ? ? ? ? ? ? ? ? ? ? ? READ ONLY ?NO ? ? ? ? ?3 PDB1 ? ? ? ? ? ? ? ? ? ? ? ? ? READ WRITE NO ? ? ? ? ?4 PDB2 ? ? ? ? ? ? ? ? ? ? ? ? ? READ WRITE NO ? ? ? ? ?5 PDB3 ? ? ? ? ? ? ? ? ? ? ? ? ? READ WRITE NO SQL> alter session set container=pdb2;
Session altered.?? ?
(1)flashback cdb 还原点
SQL> create table pdb2 as select * from dba_objects;
Table created.?? ??
SQL> select count(*) from dba_objects;
? COUNT(*) ---------- ? ? ?72357 ?? ?? SQL> shutdown immediate Pluggable Database closed.
SQL> show pdbs
? ? CON_ID CON_NAME ? ? ? ? ? ? ? ? ? ? ? OPEN MODE ?RESTRICTED ---------- ------------------------------ ---------- ---------- ? ? ? ? ?4 PDB2 ? ? ? ? ? ? ? ? ? ? ? ? ? MOUNTED ?? ??? ?? SQL> flashback pluggable database pdb2 to restore point rp;
Flashback complete.?? ??? ?? ?? ??? ?? SQL> alter pluggable database pdb2 open resetlogs;
SQL> select count(*) from pdb2; select count(*) from pdb2 ? ? ? ? ? ? ? ? ? ? ?* ERROR at line 1: ORA-00942: table or view does not exist
(2)flashback pdb 还原点
SQL> create table pdb2 as select * from dba_objects;
Table created.
SQL> select count(*) from dba_objects;
? COUNT(*) ---------- ? ? ?72357 ?? ?? SQL> create restore point pdb;
Restore point created.
SQL> drop table pdb2 purge;
SQL> shutdown immediate
SQL> flashback pluggable database pdb2 to restore point pdb;
SQL> alter database open; alter database open * ERROR at line 1: ORA-01113: file 16 needs media recovery ORA-01110: data file 16: '/u01/app/oracle/oradata/ORCL/pdb2/users01.dbf'
SQL> alter pluggable database pdb2 open resetlogs;
SQL> select count(*) from pdb2;
? COUNT(*) ---------- ? ? ?72356
(3)flashback scn
SQL> select current_scn from v$database;
CURRENT_SCN ----------- ? ? 2262490
SQL> drop table pdb2 purge;
SQL> shutdown immediate
SQL> flashback pluggable database pdb2 to scn 2262490;
SQL> alter pluggable database pdb2 open resetlogs;
SQL> select count(*) from pdb2;
? COUNT(*) ---------- ? ? ?72356
(4)flashback timestamp
SQL> select sysdate from dual;
SYSDATE ------------------- 2022-10-24 14:48:46
SQL> drop table pdb2 purge;
SQL> shutdown immediate
SQL> flashback pluggable database pdb2 to timestamp to_timestamp('2022-10-24 14:48:46','yyyy-mm-dd hh24:mi:ss');
SQL> alter pluggable database pdb2 open resetlogs;
SQL> select count(*) from pdb2;
? COUNT(*) ---------- ? ? ?72356 ?? ?? ?? ??
3、删除还原点
SQL> alter session set container= pdb2;
Session altered.
SQL> drop restore point pdb;
Restore point dropped.
SQL> conn / as sysdba Connected.
SQL> drop restore point rp;
Restore point dropped.
|