Database & Technology 1 _ Clancy Bufton _ Flashback Query - oracle total recall and some of the uses.pdf

1,475 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,475
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
30
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Database & Technology 1 _ Clancy Bufton _ Flashback Query - oracle total recall and some of the uses.pdf

  1. 1. Flashback  Query   Total  Recall    and  some  of  it’s  uses   By   Clancy  Bu*on   Park  Lane  IT  
  2. 2. 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.Bu*on@parklane.com.au  
  3. 3. 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  
  4. 4. 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;  
  5. 5. 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   idenDfies  the  Dme  when  the  data  first  had  the  values  reflected  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  affected  by  an  UPDATE  operaDon.  
  6. 6. 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;  
  7. 7. 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  
  8. 8. 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;  
  9. 9. Flashback  Archive  •  DicDonary  views   –  dba_flashback_archive   FLASHBACK_ARCHIV FLASHBACK_ARCHIVE OWNER_NAME   E_NAME   #   RETENTION_IN_DAYS   CREATE_TIME   LAST_PURGE_TIME   STATUS   28/JUL/11   28/JUL/11   02:57:57.00000 02:57:57.000000000   SYS   FLBA1   1   10   0000  PM   PM   –  dba_flashback_archive_tables   TABLE_NAME   OWNER_NAME   FLASHBACK_ARCHIVE_NAME   ARCHIVE_TABLE_NAME   STATUS   EMP   SCOTT   FLBA1   SYS_FBA_HIST_73257   ENABLED  
  10. 10. Flashback  Archive  -­‐  Internal  Tables  •  Enabling  flashback  archive  on  a  table  automaDcally  creates  three  new  tables  in  the   schema  •  The  table  name  is  formed  by  SYS_FBA_<purpose>_<FBDA_object_iden3fier>  •  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  
  11. 11. SYS_FBA_DDL_COLMAP_73257  CREATE  TABLE  "SCOTT"."SYS_FBA_DDL_COLMAP_73257"      (          "STARTSCN"        NUMBER,          "ENDSCN"            NUMBER,          "XID"        RAW(8),          "OPERATION"                              VARCHAR2(1  BYTE),          "COLUMN_NAME"                          VARCHAR2(255  BYTE),          "TYPE"                                        VARCHAR2(255  BYTE),          "HISTORICAL_COLUMN_NAME"    VARCHAR2(255  BYTE)      )      SEGMENT  CREATION  IMMEDIATE  NOCOMPRESS  LOGGING  TABLESPACE   "FLASH_ARCHIVES"  ;  
  12. 12. SYS_FBA_TCRV_73257  CREATE  TABLE  "SCOTT"."SYS_FBA_TCRV_73257"      (          "RID"              VARCHAR2(4000  BYTE),          "STARTSCN"    NUMBER,          "ENDSCN"        NUMBER,          "XID"    RAW(8),          "OP"      VARCHAR2(1  BYTE)      )      SEGMENT  CREATION  IMMEDIATE  NOCOMPRESS  LOGGING  TABLESPACE  "FLASH_ARCHIVES"  ;      CREATE  INDEX  "SCOTT"."SYS_FBA_TCRV_IDX_73257"  ON  "SCOTT"."SYS_FBA_TCRV_73257"      (          "RID"      )      COMPUTE  STATISTICS  TABLESPACE  "FLASH_ARCHIVES"  ;  
  13. 13. SYS_FBA_HIST_73257  CREATE  TABLE  "SCOTT"."SYS_FBA_HIST_73257"      (          "RID"                VARCHAR2(4000  BYTE),          "STARTSCN“      NUMBER,          "ENDSCN"          NUMBER,          "XID“      RAW(8),          "OPERATION“      VARCHAR2(1  BYTE),          "EMPNO"              NUMBER(4,0),          "ENAME"              VARCHAR2(10  BYTE),          "JOB"                VARCHAR2(9  BYTE),          "MGR"                NUMBER(4,0),          "HIREDATE“    DATE,          "SAL"            NUMBER(7,2),          "COMM"          NUMBER(7,2),          "DEPTNO"      NUMBER(2,0)      )      COMPRESS  FOR  OLTP        TABLESPACE  "FLASH_ARCHIVES"  PARTITION  BY  RANGE      (          "ENDSCN"      )      (          PARTITION  "HIGH_PART"  VALUES  LESS  THAN  (MAXVALUE)    TABLESPACE  "FLASH_ARCHIVES"  COMPRESS  FOR  OLTP      )  ;  
  14. 14. Historical  Indexes  •  Indexes  on  base  table  aren’t  mirrored  on  history   tables  •  Indexes  can  be  created  on  history  tables  •  E.g.  local  prefixed  index  created  for  start  and  end   scn        CREATE  INDEX  "SCOTT"."EMP_SCN_INDEX"  ON  "SCOTT"."SYS_FBA_HIST_73257"        (        "ENDSCN",          "STARTSCN"        )  local;    
  15. 15. 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    
  16. 16. Flash  Back  Data  Archiver  (FBDA)  •  Is  a  new  background  process  •  Maintains  the  Flashback  archives    •  FBDA  archives  the  historical  rows  of  tracked  tables  into   flashback  data  archives.    •  FBDA  is  also  responsible  for  automaDcally  managing  the   flashback  data  archive  for  space,  organizaDon,  and   retenDon  and  keeps  track  of  how  far  the  archiving  of   tracked  transacDons  has  occurred.  
  17. 17. 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  buffers  from  cache,  or  from  disk  if  they  have   aged  out.  
  18. 18. DDL  Support  •  All  DDL  is  supported  in  11.2  •  For  complex  schema  changes  dbms_flashback  •  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  
  19. 19. DBMS_FLASHBACK_ARCHIVE  •  begin      dbms_flashback_archive.disassociate_sa(SCOTT,EMP);    end;    /  •  begin      dbms_flashback_archive.reassociate_sa(SCOTT,EMP);    end;    /  
  20. 20. 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  
  21. 21. 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  
  22. 22. Cau:on  •  Seung  a  very  long  UNDO_RETENTION  in  place  of  using  flashback  archives    •  Asynchronous  FBDA   –   changes  may  not  be  visible  to  a  flashback  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    

×