1) Creamos un tablespace especial para esta funcion.
SQL> create tablespace tbs1 datafile '+DATA2' size 10M;
Tablespace created.
2) Creamos el flashback archive asociandolo al tablespace que hemos designado para esta tarea.
SQL> create flashback archive fla1 tablespace tbs1 retention 5 MONTH;
Flashback archive created.
3) Esta funcionalidad puede ser utilizada en tablas nuevas o tablas que ya existan en nuestra base de datos.
SQL> alter table juanudo.test flashback archive fla1;
Table altered.
4) Iniciamos una serie de operaciones para mostrat la funcionalidad.
SQL> select count(*) from juanudo.test;
COUNT(*)
----------
14
SQL> insert into juanudo.test select * from juanudo.test;
14 rows created.
SQL> commit;
Commit complete.
SQL> select count(*) from juanudo.test;
COUNT(*)
----------
28
SQL> truncate table juanudo.test;
Table truncated.
SQL> select count(*) from juanudo.test;
COUNT(*)
----------
0
SQL> select to_char(sysdate,'DD-MM-YY HH24:MI:SS') from dual;
TO_CHAR(SYSDATE,'
-----------------
15-04-14 08:12:48
SQL> select count(*) from juanudo.test as of timestamp to_timestamp(sysdate-1,'DD-MM-YY HH24:MI:SS');
COUNT(*)
----------
14
SQL> select count(*) from juanudo.test as of timestamp to_timestamp('15-04-14 08:12:48','DD-MM-YY HH24:MI:SS');
COUNT(*)
----------
0
SQL> select count(*) from juanudo.test as of timestamp to_timestamp('15-04-14 08:11:00','DD-MM-YY HH24:MI:SS');
COUNT(*)
----------
14
SQL> select count(*) from juanudo.test as of timestamp to_timestamp('15-04-14 08:11:38','DD-MM-YY HH24:MI:SS');
COUNT(*)
----------
28
SQL> insert into juanudo.test select * from juanudo.test as of timestamp to_timestamp('15-04-14 08:11:30','DD-MM-YY HH24:MI:SS');
14 rows created.
SQL> commit;
SQL> select * from dba_flashback_archive_tables
TABLE_NAME OWNER_NAME FLASHBACK_ARCHI ARCHIVE_TABLE_NAME STATUS
--------------- ------------------------------ --------------- ----------------------------------------------------- -------------
TEST JUANUDO FLA1 SYS_FBA_HIST_82471 ENABLED
El objecto FBAD no puede ser modificado directamente
SQL> delete from JUANUDO.SYS_FBA_HIST_82471;
delete from JUANUDO.SYS_FBA_HIST_82471
*
ERROR at line 1:
ORA-55622: DML, ALTER and CREATE UNIQUE INDEX operations are not allowed on table "JUANUDO"."SYS_FBA_HIST_82471"
SQL> alter table JUANUDO.SYS_FBA_HIST_82471 add x char;
alter table JUANUDO.SYS_FBA_HIST_82471 add x char
*
ERROR at line 1:
ORA-55622: DML, ALTER and CREATE UNIQUE INDEX operations are not allowed on table "JUANUDO"."SYS_FBA_HIST_82471"
Es necesario desasociar el control de la base de datos sobre el objecto para poder modificarlo
SQL> EXEC DBMS_FLASHBACK_ARCHIVE.DISASSOCIATE_FBA('juanudo','test');
PL/SQL procedure successfully completed.
SQL> alter table JUANUDO.SYS_FBA_HIST_82471 add x char;
Table altered.
Si el FBDA sufre alguna modificacion resultando el objecto diferente a la estructura de la tabla original la base de datos no permite asociar el objevto.
SQL> EXEC DBMS_FLASHBACK_ARCHIVE.REASSOCIATE_FBA('juanudo','test');
BEGIN DBMS_FLASHBACK_ARCHIVE.REASSOCIATE_FBA('juanudo','test'); END;
*
ERROR at line 1:
ORA-55636: Flashback Data Archive enabled table "JUANUDO"."TEST" has different definition from its history table
ORA-06512: at "SYS.DBMS_FLASHBACK_ARCHIVE", line 17
ORA-06512: at line 1
SQL> EXEC DBMS_FLASHBACK_ARCHIVE.DISASSOCIATE_FBA('juanudo','test');
PL/SQL procedure successfully completed.
Hay que igualar ambos objectos
SQL> alter table JUANUDO.SYS_FBA_HIST_82471 drop column x;
Table altered.
SQL> EXEC DBMS_FLASHBACK_ARCHIVE.REASSOCIATE_FBA('juanudo','test');
PL/SQL procedure successfully completed.
No hay comentarios:
Publicar un comentario