1.应用场景
2.oracle实现该技术的原理理论,及限制3.实操及与scn时间相关的函数查询 一、flashback_scn导出1) OGG同步,对表的数据进行同步,第一次可以完全导出,中途如果由于某些原因导致数据中断时间过长,可以根据OGG日志得到目标端最后应用同步成功的SCN,选择这个SCN前一点点在源端导出即可无需全部导出:2)使用expdp进行数据迁移,在子表导入,报ORA-39083、ORA-02298,父表中不存在子表相关的记录,因此外建约束无法创建解决方法:停应用重新导出导入、指定flashback_scn导出导入、使用如下SQL删除子表中不符合的行,进行删除,手工创建约束。ORA-39083 And ORA-2298 Encountered During DataPump Import (Doc ID 462645.1) ORA-39083: select <FK_column_name> from <child_table>minusselect <PK_column_name> from <parent_table>;如下链接,说明在导出的过程中,如果对表进行dml操作且成功,导出程序读取数据时将按照实际情况进行导出,因此数据与最初执行导出存在不一致。Expdp Message "FLASHBACK automatically enabled" Does Not Guarantee Export Consistency (Doc ID 377218.1)二、原理理论
通过Undo构建历史时间节点的blocks,达到在某个时间节点数据一致性的现象。undo保留时间无法保留过长的数据,Undo空间不足信息被覆盖。三、实操
数据库当前SCN查询SQL> select dbms_flashback.get_system_change_number scn,current_scn from v$database; SCN CURRENT_SCN---------- ----------- 1276822 1276822SQL>select to_char(scn_to_timestamp(current_scn),'yyyy-mm-dd hh24:mi:ss') as "date" from v$databasedate-------------------2019-04-21 19:00:28select to_char(scn_to_timestamp(1276822),'yyyy-mm-dd hh24:mi:ss') from dual;
TO_CHAR(SCN_TO_TIME
-------------------2019-04-21 19:04:01 SQL> create table a(id int);SQL> insert into a values(1);SQL> commit;SQL> select dbms_flashback.get_system_change_number scn,current_scn from v$database; SCN CURRENT_SCN---------- ----------- 1276903 1276903SQL> insert into a values(2);SQL> commit;Starting "SYS"."SYS_EXPORT_TABLE_01": '/******** AS SYSDBA' directory=dump dumpfile=test1.dmp tables=a Estimate in progress using BLOCKS method...Processing object type TABLE_EXPORT/TABLE/TABLE_DATATotal estimation using BLOCKS method: 0 KBORA-39166: Object A was not found.ORA-31655: no data or metadata objects selected for jobDataPump Export (EXPDP) Fails With Error ORA-39165: Schema SYS Was Not Found (Doc ID 553402.1)
SQL> create table system.a as select * from a;SQL> select dbms_flashback.get_system_change_number scn,current_scn from v$database; SCN CURRENT_SCN---------- ----------- 1303531 1303531 delete system.a where id=2; commit;SQL> select dbms_flashback.get_system_change_number scn,current_scn from v$database; SCN CURRENT_SCN---------- ----------- 1303545 1303545[oracle@enmo ~]$ expdp system/oracle directory=dump dumpfile=test1.dmp tables=a. . exported "SYSTEM"."A" 4.921 KB 1 rows [oracle@enmo ~]$ expdp system/oracle directory=dump dumpfile=test3.dmp tables=a FLASHBACK_SCN=1303531. . exported "SYSTEM"."A" 4.929 KB 2 rows