Database & Technology 1 _ Clancy Bufton _ Flashback Query - oracle total recall and some of the uses.pdf
Flashback Query Total Recall and some of it’s uses By Clancy Bu*on Park Lane IT
Introduc:on • Clancy Bu*on – Oracle DBA at Park Lane IT • 7 years experience as an Oracle Database Administrator working for clients in government and uDliDes • Clancy.Bufirstname.lastname@example.org
Flashback Query • Available since version 9.2 – Implemented on Oracles UNDO based read consistency • Select statement has two new clauses • AS of – Returns the enDre table as it existed at a point in Dme • Versions Between – returns all commiOed versions of rows that existed between two points in Dme
Flashback Query Examples • select * from scott.emp as of timestamp sysdate -‐ interval 60 minute; • select * from scott.emp versions between timestamp sysdate -‐ interval 60 minute and sysdate -‐ interval 5 minute;
Flashback Query • Versions Pseudo Columns Used with versions between – VERSIONS_STARTSCN and VERSIONS_STARTTIME • StarDng System Change Number (SCN) or TIMESTAMP when the row version was created. This pseudocolumn idenDﬁes the Dme when the data ﬁrst had the values reﬂected in the row version. Use this pseudocolumn to idenDfy the past target Dme for Oracle Flashback Table or Oracle Flashback Query. If this pseudocolumn is NULL, then the row version was created before start. – VERSIONS_ENDSCN and VERSIONS_ENDTIME • SCN or TIMESTAMP when the row version expired. If the pseudocolumn is NULL, then either the row version was current at the Dme of the query or the row corresponds to a DELETE operaDon. – VERSIONS_XID • For each version of each row, returns the transacDon ID (a RAW number) of the transacDon that created the row version. – VERSIONS_OPERATION • OperaDon performed by the transacDon: I for inserDon, D for deleDon, or U for update. The version is that of the row that was inserted, deleted, or updated; that is, the row a*er an INSERT operaDon, the row before a DELETE operaDon, or the row aﬀected by an UPDATE operaDon.
Versions Pseudo Column Query Example • Can be used in the select list, the where clause and order by clause • Select versions_startscn ,versions_endscn ,versions_operation ,emp.* from scott.emp versions between timestamp sysdate -‐ interval 20 hour and sysdate -‐ interval 5 minute emp where versions_operation=U order by versions_startscn;
Total Recall • Total Recall is new in version 11 • Introduces Flashback Archives to the database • Built on ParDDoning and Advanced Compression technology • Introduces a new background process FBDA
Flashback Archive • New privilege FLASHBACK ARCHIVE ADMINISTER • New DDL statement – create flashback archive flba1 tablespace flash_archives retention 10 day; • Creates archive tables in a normal tablespace automaDcally • Enabled per table – alter table scott.emp flashback archive flba1;
Flashback Archive -‐ Internal Tables • Enabling ﬂashback archive on a table automaDcally creates three new tables in the schema • The table name is formed by SYS_FBA_<purpose>_<FBDA_object_iden3ﬁer> • SYS_FBA_DDL_COLMAP_<object_id> – Records current and past columns that existed on the base table (supports DDL on the base table) • SYS_FBA_HIST_<object_id> – Contains the actual historical values • SYS_FBA_TCRV_<object_id> – Maps start and end SCN to rowids in the base table to idenDfy the current version of the row
Historical Indexes • Indexes on base table aren’t mirrored on history tables • Indexes can be created on history tables • E.g. local preﬁxed index created for start and end scn CREATE INDEX "SCOTT"."EMP_SCN_INDEX" ON "SCOTT"."SYS_FBA_HIST_73257" ( "ENDSCN", "STARTSCN" ) local;
Par::oning and Compression • PARTITION BY RANGE clause on SCN column of SYS_FBA_HIST tables – Oracle ParDDoning opDon • COMPRESS FOR OLTP clause on SYS_FBA_HIST tables – Oracle Advanced Compression opDon
Flash Back Data Archiver (FBDA) • Is a new background process • Maintains the Flashback archives • FBDA archives the historical rows of tracked tables into ﬂashback data archives. • FBDA is also responsible for automaDcally managing the ﬂashback data archive for space, organizaDon, and retenDon and keeps track of how far the archiving of tracked transacDons has occurred.
Flash Back Data Archiver (FBDA) • Dynamic based on DML workload • AutomaDcally spawns parallel slaves • Run asynchronously by default every 5 minutes • Runs more frequently depending on workload • Reads UNDO buﬀers from cache, or from disk if they have aged out.
DDL Support • All DDL is supported in 11.2 • For complex schema changes dbms_ﬂashback • disassociate_sa and reassociate_sa • Manual changes can be made a*er disassociaDon to base table and history table • ReassociaDon can only occur if base table and history table schema is the same
DBMS_FLASHBACK_ARCHIVE • begin dbms_ﬂashback_archive.disassociate_sa(SCOTT,EMP); end; / • begin dbms_ﬂashback_archive.reassociate_sa(SCOTT,EMP); end; /
DML Support • FBDA supports parallel DML • DML cannot be performed on history table by a user • Except when it is disassociated from the base table
Uses for Total Recall • AudiDng – Provides a tamper proof historical record of all changes • Row based recovery – Can be used to recover individual rows by updaDng back to a previous value • Change data capture – Fine grained change capture for data warehouse extracts
Cau:on • Seung a very long UNDO_RETENTION in place of using ﬂashback archives • Asynchronous FBDA – changes may not be visible to a ﬂashback archive query for several minutes a*er commit • Global indexes on history tables – When FBDA automaDcally maintains the parDDons the enDre index will be invalidated and need to be rebuilt. • Don’t use in 11.1 – Versions between semi funcDonal – No DDL support – Many bugs – FBDA no parallel DML