Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
bienvenido
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Lo siento, no hablo español :-(
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
But I will do my best to help
Pero haré todo lo posible para ayudar
Flashback - great for DBAs, great for Developers
Connor McDonald
Database Advocate
una gran herramienta para DBA y desarrolladores
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
5
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
6
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Me
youtube bit.ly/youtube-connor
blog bit.ly/blog-connor
twitter bit.ly/twitter-connor
400+ posts mainly on database & development
250 technical videos, new uploads every week
Más de 400 publicaciones principalmente en bases de datos y desarrollo
250 videos técnicos, nuevas cargas cada semana
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
etc...
facebook bit.ly/facebook-connor
linkedin bit.ly/linkedin-connor
instagram bit.ly/instagram-connor
slideshare bit.ly/slideshare-connor
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback
11
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
several technologies
12
varias tecnologías diferentes
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback query
flashback table
flashback drop
flashback database
flashback transaction
flashback data archive
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback
query
14
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
controversy
15
controversia
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
you have always...
16
siempre has ...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
.. been using flashback query
17
.. estado usando una consulta flashback
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
revision
18
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> update EMP
2 set SAL = SAL * 1.10
3 /
14 rows updated.
SQL> rollback;
Rollback complete.
how ?
19
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
we remember stuff
20
recordamos cosas
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> update EMP
2 set SAL = SAL * 1.10
3 /
undo header
smith $1,0001
block 2754
jones $9002
brown $1,5003
wells $2,0004
wilson $1,0005
block 2754, row 1,
sal $1000
block 2754, row 2,
sal $900
block 2754, row 3,
sal $1500
block 2754, row 4,
sal $2000
uba 5
5
$1,100
$990
$1,650
$2,200
uba 5.1uba 5.2
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> rollback;
23
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> rollback;
undo header
smith $1,0001
block 2754
jones $9002
brown $1,5003
wells $2,0004
wilson $1,0005
block 2754, row 1,
sal $1000
block 2754, row 2,
sal $900
block 2754, row 3,
sal $1500
block 2754, row 4,
sal $2000
uba 5
5
$1,100
$990
$1,650
$2,200
uba 5.1uba 5.2
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
we can use this for queries!
(Oracle version 4)
26
podemos usar esto para consultas!
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
read consistency
27
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
select * from emp
where hiredate > '01/01/2004'
update emp set …
where empno = 1234;
Block 3217
"I need block 3217…
… as it was at 9:00"
9:00
9:03
9:05
session 1 session 2
...and time = scn
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
system change number
29
número de cambio del sistema
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
Session 1
Request
Block 3217,
SCN 4567192
Block 3217,
SCN 4567234
"ABC" Block 3217,
SCN 4567003,
change ABC => XYZ
undo segment block(s)
No good..too new
take a copy of the block
Locate
apply undo
Block 3217,
SCN 4567234
"ABC"
Block 3217,
SCN 4567234
"ABC"
Block 3217,
SCN 4567003
"XYZ"
Block 3217,
SCN 4567003
"XYZ"
Session 2
update emp
set ename = "ABC"
where empno = 1234;
commit;
Done !
30
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
every query = locked at a SCN
31
cada consulta = bloqueada en un SCN
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
32
go back even further....
volver aún más lejos ...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback query = choose SCN
33
consulta de flashback = elegir SCN
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
v9
34
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select * from DEPT;
DEPTNO DNAME LOC
---------- -------------- -------------
10 UNKNOWN NEW YORK
20 UNKNOWN DALLAS
30 UNKNOWN CHICAGO
40 UNKNOWN BOSTON
35
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select * from DEPT AS OF SCN 995401;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
36
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
a little less geeky
37
un poco menos geek
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select * from DEPT
2 AS OF TIMESTAMP systimestamp -
3 interval '20:00' minute to second;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
38
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select TIMESTAMP_TO_SCN(systimestamp) from DUAL;
TIMESTAMP_TO_SCN(SYSTIMESTAMP)
------------------------------
998332
42
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select SCN_TO_TIMESTAMP(998314) from DUAL;
SCN_TO_TIMESTAMP(998314)
-----------------------------------------------
25-AUG-19 09.12.48.000000000 PM
43
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
3 seconds
44
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select scn_to_timestamp(2409511-rownum)
2 from dual
3 connect by level <= 50;
SCN_TO_TIMESTAMP(2409511-ROWNUM)
---------------------------------------------
28-AUG-19 05.47.47.000000000 PM
28-AUG-19 05.47.47.000000000 PM
28-AUG-19 05.47.44.000000000 PM
28-AUG-19 05.47.41.000000000 PM
28-AUG-19 05.47.37.000000000 PM
28-AUG-19 05.47.34.000000000 PM
28-AUG-19 05.47.31.000000000 PM
28-AUG-19 05.47.28.000000000 PM
28-AUG-19 05.47.25.000000000 PM
45
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
use in "normal" queries
46
utilizar en consultas "normales"
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select e.empno, e.ename, d.dname
2 from emp e,
3 dept AS OF TIMESTAMP '23-AUG-19 11.51.02 PM' d
3 where d.deptno = e.deptno;
EMPNO ENAME DNAME
---------- ---------- --------------
7782 CLARK "PREVIOUS NAME"
7839 KING "PREVIOUS NAME"
7934 MILLER "PREVIOUS NAME"
7566 JONES RESEARCH
7902 FORD RESEARCH
7876 ADAMS RESEARCH
7369 SMITH RESEARCH
7788 SCOTT RESEARCH
47
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"What's in it for me?"
48
"Qué hay para mi ahí dentro?"
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
1) unit testing
49
código de prueba de la unidad
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select case
2 when d1.deptno is null then 'DELETE'
3 when d2.deptno is null then 'INSERT'
4 end action,
5 d1.deptno, d2.deptno, d1.dname, d1.loc
6 from DEPT d1 full outer join
7 DEPT AS OF TIMESTAMP '23-AUG-19 11.51.02 PM' d2
8 on d1.deptno = d2.deptno;
ACTION DEPTNO DEPTNO DNAME LOC
------ ---------- ---------- -------------- ----------
10 10 ACCOUNTING NEW YORK
20 20 RESEARCH DALLAS
30 30 SALES CHICAGO
DELETE 40
INSERT 50 MARKETING PERTH
50
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
2) not just your data
51
no solo tus datos
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> drop procedure debug_msg;
Procedure dropped.
SQL> connect / as sysdba
Connected.
SQL> select text
2 from dba_source
3 as of timestamp systimestamp - interval '5' minute
4 where name='DEBUG_MSG' order by line;
TEXT
---------------------------------------------------------------------
procedure debug_msg(m varchar2) is
begin
dbms_output.put_line(m);
dbms_application_info.set_client_info(m);
end;
5 rows selected.
52
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
3) functional diagnosis
53
diagnóstico funcional
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select * from DEPT;
DEPTNO DNAME LOC
---------- -------------- -------------
10 UNKNOWN NEW YORK
SQL> select * from DEPT
2 as of TIMESTAMP SYSTIMESTAMP -
3 INTERVAL '20:00' MINUTE TO SECOND;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
1 change ?
10 changes ?
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback row versions
55
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> SELECT deptno, dname
2 FROM dept
3 VERSIONS BETWEEN
4 TIMESTAMP SYSTIMESTAMP –
5 INTERVAL '20:00' MINUTE TO SECOND
6 AND SYSTIMESTAMP
7 WHERE deptno = 10;
DEPTNO DNAME
---------- --------------
10 ACCOUNTING
10 MONEY GRABBERS
10 FINANCE
10 BEAN COUNTERS
10 UNKNOWN
1 row
5 versions
56
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
versions_starttime
versions_startscn
versions_endtime
versions_endscn
versions_xid
versions_operation
57
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> SELECT deptno, dname,
2 VERSIONS_STARTTIME
3 ,VERSIONS_XID
4 ,VERSIONS_OPERATION
5 FROM dept
6 VERSIONS BETWEEN
7 TIMESTAMP SYSTIMESTAMP - INTERVAL '20:00' MINUTE TO SECOND
8 AND SYSTIMESTAMP
9 WHERE deptno = 10;
DEPTNO DNAME VERSIONS_STARTTIME VERSIONS_XID V
---------- -------------- ------------------------ ---------------- -
10 UNKNOWN 03-AUG-19 11.53.45 PM 0200100060040000 U
10 MONEY GRABBERS 03-AUG-19 11.53.36 PM 0600050065040000 U
10 FINANCE 03-AUG-19 11.53.24 PM 09000D001D050000 U
10 BEAN COUNTERS 03-AUG-19 11.53.12 PM 01001A00EA030000 U
10 ACCOUNTING
58
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
get everything ...
59
consigue todo ...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> SELECT deptno, dname,
2 VERSIONS_STARTTIME
3 ,VERSIONS_XID
4 ,VERSIONS_OPERATION
5 FROM dept VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE;
DEPTNO DNAME VERSIONS_STARTTIME VERSIONS_XID V
---------- -------------- ------------------------ ---------------- -
50 UNKNOWN 03-AUG-19 11.08.15 PM 04000700EA030000 U
30 UNKNOWN 03-AUG-19 11.08.15 PM 04000700EA030000 U
20 NERDS 03-AUG-19 11.07.57 PM 090016001D050000 U
20 R&D 03-AUG-19 11.07.48 PM 05000B0074040000 U
...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
grant flashback to ...
61
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
session level
62
nivel de sesión
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
dbms_flashback.enable_at_time(systimestamp-1);
63
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> exec dbms_flashback.enable_at_time(
systimestamp-5/86400)
PL/SQL procedure successfully completed.
SQL> insert into T values (1);
ERROR at line 1:
ORA-08182:
operation not supported while in Flashback mode
64
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> exec dbms_flashback.disable;
PL/SQL procedure successfully completed.
SQL> exec dbms_flashback.enable_at_time(
systimestamp-30/86400)
PL/SQL procedure successfully completed.
SQL> exec dbms_flashback.enable_at_time(
systimestamp-60/86400)
ERROR at line 1:
ORA-08184: attempting to re-enable Flashback while in Flashback
65
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
how far can you go back ?
66
hasta dónde puedes volver?
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
undo_retention
68
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> show parameter undo_retention
NAME TYPE VALUE
------------------------------ ----------- --------
undo_retention integer 900
69
~
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> desc v$undostat
Name Null? Type
----------------------------- -------- ----------------
BEGIN_TIME DATE
END_TIME DATE
...
...
TUNED_UNDORETENTION NUMBER
CON_ID NUMBER
70
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
to go much much further
flashback data archive
ir mucho más lejos
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"no" spanning DDL
72
better each version
"no" que abarca DDL
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
rewind the data, not time
73
charactersets,
NLS etc
rebobinar los datos, no el tiempo
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback
transaction
74
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> SELECT deptno, dname,
2 VERSIONS_STARTTIME
3 ,VERSIONS_XID
4 ,VERSIONS_OPERATION
5 FROM dept VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE;
DEPTNO DNAME VERSIONS_STARTTIME VERSIONS_XID V
---------- -------------- ------------------------ ---------------- -
50 UNKNOWN 03-AUG-19 11.08.15 PM 04000700EA030000 U
30 UNKNOWN 03-AUG-19 11.08.15 PM 04000700EA030000 U
20 NERDS 03-AUG-19 11.07.57 PM 090016001D050000 U
20 R&D 03-AUG-19 11.07.48 PM 05000B0074040000 U
...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
XID ?
76
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> desc V$TRANSACTION
Name Null? Type
----------------------------- -------- -------
XIDUSN NUMBER
XIDSLOT NUMBER
XIDSQN NUMBER
...
77
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select XIDUSN, XIDSLOT, XIDSQN
2 from v$transaction
XIDUSN XIDSLOT XIDSQN
---------- ---------- ----------
1 31 674
SQL> select versions_xid from ...
VERSIONS_XID
-------------------
01 001F 00A202 0000
78
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> desc FLASHBACK_TRANSACTION_QUERY
Name Null? Type
----------------------- -------- --------------
XID RAW(8)
START_SCN NUMBER
START_TIMESTAMP DATE
COMMIT_SCN NUMBER
COMMIT_TIMESTAMP DATE
LOGON_USER VARCHAR2(30)
UNDO_CHANGE# NUMBER
OPERATION VARCHAR2(32)
TABLE_NAME VARCHAR2(256)
TABLE_OWNER VARCHAR2(32)
ROW_ID VARCHAR2(19)
UNDO_SQL VARCHAR2(4000)
79
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select DNAME from dept
2 where deptno = 10;
DNAME
-------
FINANCE
SQL> select xid, undo_sql
2 from flashback_transaction_query
3 where xid = hextoraw('09000d001d050000');
XID UNDO_SQL
---------------- ------------------------------------
09000D001D050000 update "SCOTT"."DEPT"
set "DNAME" = 'BEAN COUNTERS'
where ROWID = 'AAAQ+hAAEAAAAAOAAA';
80
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
be careful
81
ten cuidado
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select text from dba_views
2 where view_name
3 = 'FLASHBACK_TRANSACTION_QUERY';
TEXT
------------------------------------------------
select
xid, start_scn, start_timestamp,
decode(commit_scn,
0, commit_scn,
281474976710655, NULL, commit_scn)
commit_scn, commit_timestamp,
logon_user, undo_change#, operation,
table_name, table_owner,
row_id, undo_sql
from SYS.X$KTUQQRY
82
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
do not query without predicates ...
83
no consultar sin predicados ...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
do not forget hextoraw
84
no te olvides de hextoraw
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select xid, undo_sql
2 from flashback_transaction_query
3 where xid = hextoraw('09000d001d050000');
-----------------------------------------------------
| Id | Operation | Name |
-----------------------------------------------------
| 0 | SELECT STATEMENT | |
|* 1 | FIXED TABLE FIXED INDEX| X$KTUQQRY (ind:1) |
-----------------------------------------------------
86
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select xid, undo_sql
2 from flashback_transaction_query
3 where xid = '09000d001d050000';
--------------------------------------
| Id | Operation | Name |
--------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | FIXED TABLE FULL| X$KTUQQRY |
--------------------------------------
87
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
UNDO_SQL
88
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
undo a committed transaction
89
deshacer una transacción comprometida
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"What's in it for me?"
90
"Qué hay para mi ahí dentro?"
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
three words
91
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
delete
agggh...
commit
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
93
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback transaction
94
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> BEGIN
2 DBMS_FLASHBACK.TRANSACTION_BACKOUT(
3 numtxns=>1,
4 xids=>sys.xid_array('09000D001D050000')
5 );
6 END;
7 /
BEGIN
*
ERROR at line 1:
ORA-55510: Mining could not start
ORA-06512: at "SYS.DBMS_FLASHBACK", line 37
ORA-06512: at "SYS.DBMS_FLASHBACK", line 70
ORA-06512: at line 2
'09000D001D050000'
95
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
96
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> ALTER DATABASE ADD
2 SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;
Database altered.
97
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> delete from DEPT
2 where DEPTNO = 10;
1 row deleted.
SQL> commit;
Commit complete.
SQL> SELECT VERSIONS_XID
2 FROM dept
3 VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE;
VERSIONS_XID
----------------
080017006C040000
98
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> BEGIN
2 DBMS_FLASHBACK.TRANSACTION_BACKOUT(
3 numtxns=>1,
4 xids=>sys.xid_array('080017006C040000')
5 );
6 END;
7 /
SQL> select * from DEPT;
DEPTNO DNAME LOC
---------- -------------- ----------
20 RESEARCH DALLAS
30 SALES CHICAGO
50 MARKETING PERTH
40 HR US
99
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
KEEP CALM
AND
DON'T PANIC
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> SELECT COMPENSATING_XID
2 FROM DBA_FLASHBACK_TXN_STATE
3 WHERE xid = '080017006C040000';
COMPENSATING_XID
----------------
03001C0072040000
101
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> SELECT xid_report
2 FROM DBA_FLASHBACK_TXN_REPORT
3 WHERE compensating_xid = '03001C0072040000';
XID_REPORT
--------------------------------------------------------
<COMP_XID_REPORT XID="03001C0072040000">
<TRANSACTION XID="080017006C040000">
<UNDO_SQL>
<USQL exec="yes">
insert into "SCOTT"."DEPT"("DEPTNO","DNAME","LOC")
values ('10','ACCOUNTING','NEW YORK')
</USQL>
</UNDO_SQL>
</TRANSACTION>
<EXECUTED_UNDO_SQL>
<EXEC_USQL>
insert into "SCOTT"."DEPT"("DEPTNO","DNAME","LOC")
values ('10','ACCOUNTING','NEW YORK')
</EXEC_USQL>
</EXECUTED_UNDO_SQL>
</COMP_XID_REPORT> 102
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> commit;
Commit complete.
SQL> select * from dept;
DEPTNO DNAME LOC
---------- -------------- ----------
20 RESEARCH DALLAS
30 SALES CHICAGO
50 MARKETING PERTH
40 HR US
10 ACCOUNTING NEW YORK
103
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
some typical restrictions
104
ddl, old lobs, xml
algunas restricciones típicas
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback
drop
105
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
delete
agggh...
commit
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback transaction
107
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
three words
two
108
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
drop
agggh...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> desc EMP
ERROR:
ORA-04043: object EMP does not exist
110
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
111
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"undrop"
113
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
not cool enough
114
no lo suficientemente genial
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback table to before drop
115
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> desc USER_RECYCLEBIN
Name Null? Type
----------------------------- -------- --------------------
OBJECT_NAME NOT NULL VARCHAR2(30)
ORIGINAL_NAME VARCHAR2(32)
OPERATION VARCHAR2(9)
TYPE VARCHAR2(25)
TS_NAME VARCHAR2(30)
CREATETIME VARCHAR2(19)
DROPTIME VARCHAR2(19)
DROPSCN NUMBER
PARTITION_NAME VARCHAR2(32)
CAN_UNDROP VARCHAR2(3)
CAN_PURGE VARCHAR2(3)
RELATED NOT NULL NUMBER
BASE_OBJECT NOT NULL NUMBER
PURGE_OBJECT NOT NULL NUMBER
SPACE NUMBER
117
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select OBJECT_NAME, ORIGINAL_NAME,
2 CAN_UNDROP, CAN_PURGE
3 from USER_RECYCLEBIN;
OBJECT_NAME ORIGINAL_NAME CAN CAN
-------------------------------- ------------------- --- ---
BIN$CmYCdNcITL6hp9l266nskA==$0 PK_EMP NO YES
BIN$b/W75+c/Q/CeFMBIK7cXfw==$0 EMP YES YES
118
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> show RECYCLEBIN
119
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
indexes / constraints / triggers
... all renamed
todos renombrados
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> flashback table EMP to before drop;
Flashback complete.
121
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> flashback table EMP to before drop
2 rename to OLD_EMP;
Flashback complete.
122
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
indexes / constraints / triggers
... not renamed back
no renombrado de nuevo
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
how long ?
124
cuánto tiempo ?
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
1 second...
...10 years
125
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> PURGE RECYCLEBIN;
SQL> PURGE TABLE emp;
SQL> PURGE TABLE "BIN$xyWe0+q+SniItJ0pn/u54A==$0";
SQL> PURGE TABLESPACE user1;
SQL> PURGE INDEX "BIN$FTX34MN88J7==$0";
SQL> PURGE TABLESPACE user1 USER fred;
126
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
no untruncate
127
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback
table
128
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback table
130
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> FLASHBACK TABLE DEPT
2 TO TIMESTAMP TO_TIMESTAMP('2019-08-23 12:05:00')
131
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"undrop"
132
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"What's in it for me?"
133
"Qué hay para mi ahí dentro?"
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
repeatable tests without cleanup scripts
134
pruebas repetibles sin scripts de limpieza
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
deletes modified rows since SCN
inserts fresh rows as of SCN
... busy
elimina registros modificadas desde SCN
inserta registros nuevas a partir de SCN
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> FLASHBACK TABLE DEPT
2 TO TIMESTAMP TO_TIMESTAMP('2019-08-23 12:05:00')
3 ENABLE TRIGGERS;
136
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
rowid's change
... enable row movement
137
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
indexes existence unaffected
138
indexa la existencia no afectada
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
single transaction
139
... multiple tables allowed
transacción única
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
tables locked
140
mesas cerradas
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
R.I must still be valid
141
R.I todavía debe ser válido
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
statistics unchanged
142
estadísticas sin cambios
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
most DDL is a flashback boundary
143
la mayoría de DDL es un límite de flashback
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> flashback table DEPT to scn ...;
ORA-01466: unable to read data - table definition has changed
144
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
each version gets better
145
cada versión mejora
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> alter table DEPT add column XXX date;
SQL> flashback table DEPT to scn ...;
SQL> desc DEPT
Name Null? Type
-------------------------- -------- --------------
DEPTNO NUMBER(2)
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
XXX DATE
146
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> flashback table DEPT to scn ...;
ORA-08183: Flashback cannot be enabled in the middle
of a transaction
147
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback
database
148
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback database
151
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
AUTHORISED
DATABASE
ADMINSTRATORS
ONLY !
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> alter database flashback on;
Database altered.
153
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
154
data
changes
"new" blocks
to disk
changes
to disk
"old" blocks
to disk
redo fbdadbwr
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> FLASHBACK DATABASE TO '2:05PM'
155
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> create restore point OK_SO_FAR;
...
SQL> flashback database to restore point OK_SO_FAR;
156
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
what is the resource cost ?
157
Cuál es el costo de los recursos?
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> desc V$FLASHBACK_DATABASE_STAT
Name Null? Type
----------------------------- -------- ---------
BEGIN_TIME DATE
END_TIME DATE
FLASHBACK_DATA NUMBER
DB_DATA NUMBER
REDO_DATA NUMBER
ESTIMATED_FLASHBACK_SIZE NUMBER
158
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
a good compromise
162
un buen compromiso
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
guaranteed restore points
163
puntos de restauración garantizados
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback logging "optional"
164
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"What's in it for me?"
166
"Qué hay para mi ahí dentro?"
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
1) safer deployment
167
despliegue más seguro
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
scenario: "My New Application"
168
escenario: "Mi nueva aplicación"
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
9:00
9:40
9:45 SQL> FLASHBACK DATABASE...
169
SQL> alter table ACCOUNTS ...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
2) repeatable end to end testing
170
prueba repetible de extremo a extremo
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
171
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
12.2+
172
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback pluggable database
173
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
3) production data for developers
174
datos de producción para desarrolladores
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"hidden" example
175
ejemplo "oculto"
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
Data Guard
176
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
177
5:00am
11:30pm
standby recovery
convert to snapshot
revert to physical
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback
data archive
182
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
less flashback, more archive
183
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> CREATE FLASHBACK ARCHIVE longterm
2 TABLESPACE space_for_archive
3 RETENTION 1 YEAR;
Flashback archive created.
185
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> ALTER TABLE EMP FLASHBACK ARCHIVE LONGTERM;
Table altered.
[lots of DML on EMP]
186
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select * from EMP;
--------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
--------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 518 |
| 1 | TABLE ACCESS FULL| EMP | 14 | 518 |
--------------------------------------------------
187
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select * from EMP
2 AS OF TIMESTAMP SYSDATE-1/24;
--------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
--------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 518 |
| 1 | TABLE ACCESS FULL| EMP | 14 | 518 |
--------------------------------------------------
188
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
3 days later...
189
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select * from EMP
2 AS OF TIMESTAMP SYSDATE-3;
-----------------------------------------------------------------
| Id | Operation | Name | Rows |
-----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 446 |
| 1 | VIEW | | 446 |
| 2 | UNION-ALL | | |
|* 3 | FILTER | | |
| 4 | PARTITION RANGE ITERATOR| | 445 |
|* 5 | TABLE ACCESS FULL | SYS_FBA_HIST_69539 | 445 |
|* 6 | FILTER | | |
|* 7 | HASH JOIN OUTER | | 1 |
|* 8 | TABLE ACCESS FULL | EMP | 1 |
|* 9 | TABLE ACCESS FULL | SYS_FBA_TCRV_69539 | 14 |
------------------------------------------------------------------190
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select table_name
2 from user_tables
3 /
TABLE_NAME
---------------------------
SYS_FBA_HIST_71036
SYS_FBA_TCRV_71036
SYS_FBA_DDL_COLMAP_71036
EMP
191
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select dbms_metadata.get_ddl(
2 'TABLE',
3 'SYS_FBA_TCRV_71036') from dual;
DDL
------------------------------------
CREATE TABLE "SCOTT"."SYS_FBA_TCRV_71036"
( "RID" VARCHAR2(4000),
"STARTSCN" NUMBER,
"ENDSCN" NUMBER,
"XID" RAW(8),
"OP" VARCHAR2(1)
)
SEGMENT CREATION IMMEDIATE
TABLESPACE "SPACE_FOR_ARCHIVE"
192
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select dbms_metadata.get_ddl(
2 'TABLE',
3 'SYS_FBA_HIST_71036') from dual;
DDL
------------------------------------------
CREATE TABLE "SCOTT"."SYS_FBA_HIST_71036"
( "RID" VARCHAR2(4000),
"STARTSCN" NUMBER,
"ENDSCN" NUMBER,
"XID" RAW(8),
"OPERATION" VARCHAR2(1),
"EMPNO" NUMBER(4,0), "ENAME" VARCHAR2(10),
"JOB" VARCHAR2(9), "MGR" NUMBER(4,0),
"HIREDATE" DATE, "SAL" NUMBER(7,2),
"COMM" NUMBER(7,2), "DEPTNO" NUMBER(2,0)
) COMPRESS FOR OLTP
TABLESPACE "SPACE_FOR_ARCHIVE"
PARTITION BY RANGE ("ENDSCN")
( PARTITION "HIGH_PART" VALUES LESS THAN (MAXVALUE) )
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"What's in it for me?"
196
"Qué hay para mi ahí dentro?"
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"I don't care what EMP looked
like last March..."
197
"No me importa cómo se veía EMP
como el pasado marzo ... "
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
198
why talk about it ?
por qué hablar de eso?
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
199
SQL> select * from EMP AS OF "JUNE";
SQL> select * from EMP AS OF "MARCH";
SQL> select * from EMP AS OF "2pm Wednesday";
SQL> select * from EMP AS OF etc etc etc
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
200
every historical version...
cada versión histórica ...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
201
... of every row
de cada fila
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
202
sound familiar ?
suena familiar ?
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
203
audit history
historial de auditoria
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
206
SQL> create or replace
2 trigger AUDIT_TRG
3 after insert or update or delete on T
4 for each row
5 declare
6 v_action varchar2(1) := case when updating
7 then 'U' when deleting then 'D' else 'I' end;
8 begin
9 if updating or inserting then
10 insert into T_AUDIT
11 values (sysdate
12 ,v_action
13 ,:new.owner
14 ,:new.object_name);
15 else
16 insert into T_AUDIT
17 values (sysdate
18 ,v_action
19 ,:old.owner
20 ,:old.object_name);
21 end if;
22 end;
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
a better, faster, robust version ...
209
una versión mejor, más rápida y robusta ...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback data archive
210
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select empno, ename, job, sal, comm,
2 nvl(VERSIONS_STARTTIME,LAST_MOD) TS
3 ,nvl(VERSIONS_OPERATION,'I') op
4 from EMP
5 versions between timestamp
6 timestamp '2019-02-11 20:12:00' and systimestamp
7 order by empno, ts;
EMPNO ENAME JOB SAL COMM TS O
---------- ---------- --------- ---------- ---------- ------------ -
7369 SMITH CLERK 806 08.10.51 PM I
7369 SMITH SALES 8060 1000 08.12.10 PM U
7499 ALLEN SALESMAN 1606 300000000 08.10.51 PM I
7521 WARD SALESMAN 1256 500000000 08.10.51 PM I
7566 JONES MANAGER 2981 08.10.51 PM I
...
7900 JAMES CLERK 956 08.10.51 PM I
7902 FORD ANALYST 3006 08.10.51 PM I
7934 MILLER CLERK 1306 08.10.51 PM I
7934 MILLER CLERK 1306 08.12.10 PM D
211
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
so why didn't we do it?
212
Entonces, por qué no lo hicimos?
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
separately licensed
218
licencia por separado
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback data archive is now …
232
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
233
gratis!
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
this is not a typo
234
Esto no es un error tipográfico
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
basic versus advanced
235
básico versus avanzado
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
wrap up
259
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback query
flashback table
flashback drop
flashback database
flashback transaction
flashback data archive
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
all included in EE
262
todo incluido en EE
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
all cool for modern development
263
todo genial para el desarrollo moderno
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
Thank you!
youtube bit.ly/youtube-connor
blog bit.ly/blog-connor
twitter bit.ly/twitter-connor
Gracias!
slideshare bit.ly/slideshare-connor

More Related Content

PDF
Latin America Tour 2019 - pattern matching
PPTX
OpenWorld 2018 - Common Application Developer Disasters
PPTX
Cool SQL Features
PDF
Kscope19 - Flashback: Good for Developers as well as DBAs
PDF
Pattern Matching with SQL - APEX World Rotterdam 2019
PPTX
OpenWorld 2018 - 20 years of hints and tips
PDF
Latin America Tour 2019 - slow data and sql processing
PDF
APEX Connect 2019 - SQL Tuning 101
Latin America Tour 2019 - pattern matching
OpenWorld 2018 - Common Application Developer Disasters
Cool SQL Features
Kscope19 - Flashback: Good for Developers as well as DBAs
Pattern Matching with SQL - APEX World Rotterdam 2019
OpenWorld 2018 - 20 years of hints and tips
Latin America Tour 2019 - slow data and sql processing
APEX Connect 2019 - SQL Tuning 101

What's hot (20)

PPTX
Flashback features in Oracle - UKOUG 2017
PPTX
OpenWorld 2018 - Pagination
PDF
Latin America Tour 2019 - 10 great sql features
PDF
APEX Connect 2019 - array/bulk processing in PLSQL
PDF
ANSI vs Oracle language
PDF
Sangam 2019 - The Latest Features
PDF
KScope19 - SQL Features
PDF
Latin America Tour 2019 - 18c and 19c featues
PDF
UKOUG 2019 - SQL features
PPTX
Perth APAC Groundbreakers tour - SQL Techniques
PDF
Sangam 19 - PLSQL still the coolest
PDF
Sangam 19 - Analytic SQL
PDF
UKOUG - 25 years of hints and tips
PDF
Sangam 19 - Successful Applications on Autonomous
PDF
OOW19 - Flashback, not just for DBAs
PDF
OOW19 - Ten Amazing SQL features
PDF
Flashback ITOUG
PPTX
SQL techniques for faster applications
PDF
OOW19 - Killing database sessions
PDF
Oracle Database 12c Application Development
Flashback features in Oracle - UKOUG 2017
OpenWorld 2018 - Pagination
Latin America Tour 2019 - 10 great sql features
APEX Connect 2019 - array/bulk processing in PLSQL
ANSI vs Oracle language
Sangam 2019 - The Latest Features
KScope19 - SQL Features
Latin America Tour 2019 - 18c and 19c featues
UKOUG 2019 - SQL features
Perth APAC Groundbreakers tour - SQL Techniques
Sangam 19 - PLSQL still the coolest
Sangam 19 - Analytic SQL
UKOUG - 25 years of hints and tips
Sangam 19 - Successful Applications on Autonomous
OOW19 - Flashback, not just for DBAs
OOW19 - Ten Amazing SQL features
Flashback ITOUG
SQL techniques for faster applications
OOW19 - Killing database sessions
Oracle Database 12c Application Development
Ad

Similar to Latin America tour 2019 - Flashback (20)

PDF
ILOUG 2019 - Flashback, the forgotten feature
PDF
OG Yatra - Flashback, not just for developers
PDF
ILOUG 2019 - 25 years of hints and tips
PDF
ITOUG 2019 - 18c, 19c features
PPTX
Melbourne Groundbreakers Tour - Hints and Tips
PPTX
Flashback features in Oracle - UKOUG 2017
PDF
18c and 19c features for DBAs
PDF
ITOUG 2019 - 25 years of hints and tips
PDF
OG Yatra - 25 years of hints and tips
PDF
Hyderabad Mar 2019 - Database 18c / 19c
PDF
ILOUG 2019 - 18c/19c features
PPTX
Perth APAC Groundbreakers tour - 18c features
PDF
AskTOM Office Hours on Database Triggers
PPTX
Melbourne Groundbreakers Tour - Upgrading without risk
PPTX
Sangam 18 - The New Optimizer in Oracle 12c
PPTX
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
PDF
Patching like a hero - DOAG
PDF
Troubleshooting Ecommerce Performance
PDF
DataOpsbarcelona 2019: Deep dive into MySQL Group Replication... the magic e...
PDF
OG Yatra - upgrading to the new 12c+ optimizer
ILOUG 2019 - Flashback, the forgotten feature
OG Yatra - Flashback, not just for developers
ILOUG 2019 - 25 years of hints and tips
ITOUG 2019 - 18c, 19c features
Melbourne Groundbreakers Tour - Hints and Tips
Flashback features in Oracle - UKOUG 2017
18c and 19c features for DBAs
ITOUG 2019 - 25 years of hints and tips
OG Yatra - 25 years of hints and tips
Hyderabad Mar 2019 - Database 18c / 19c
ILOUG 2019 - 18c/19c features
Perth APAC Groundbreakers tour - 18c features
AskTOM Office Hours on Database Triggers
Melbourne Groundbreakers Tour - Upgrading without risk
Sangam 18 - The New Optimizer in Oracle 12c
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Patching like a hero - DOAG
Troubleshooting Ecommerce Performance
DataOpsbarcelona 2019: Deep dive into MySQL Group Replication... the magic e...
OG Yatra - upgrading to the new 12c+ optimizer
Ad

More from Connor McDonald (6)

PDF
APEX tour 2019 - successful development with autonomous
PDF
APAC Groundbreakers 2019 - Perth/Melbourne
PDF
OOW19 - Read consistency
PDF
OOW19 - Slower and less secure applications
PDF
Kscope19 - Understanding the basics of SQL processing
PDF
APEX Connect 2019 - successful application development
APEX tour 2019 - successful development with autonomous
APAC Groundbreakers 2019 - Perth/Melbourne
OOW19 - Read consistency
OOW19 - Slower and less secure applications
Kscope19 - Understanding the basics of SQL processing
APEX Connect 2019 - successful application development

Recently uploaded (20)

DOCX
Basics of Cloud Computing - Cloud Ecosystem
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PPTX
Module 1 Introduction to Web Programming .pptx
PPTX
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
PDF
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
PDF
giants, standing on the shoulders of - by Daniel Stenberg
PPTX
SGT Report The Beast Plan and Cyberphysical Systems of Control
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
LMS bot: enhanced learning management systems for improved student learning e...
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PDF
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
PDF
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
PDF
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
PDF
Advancing precision in air quality forecasting through machine learning integ...
PDF
“The Future of Visual AI: Efficient Multimodal Intelligence,” a Keynote Prese...
PDF
A hybrid framework for wild animal classification using fine-tuned DenseNet12...
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PDF
Build Real-Time ML Apps with Python, Feast & NoSQL
PDF
Ensemble model-based arrhythmia classification with local interpretable model...
PDF
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
Basics of Cloud Computing - Cloud Ecosystem
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
Module 1 Introduction to Web Programming .pptx
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
giants, standing on the shoulders of - by Daniel Stenberg
SGT Report The Beast Plan and Cyberphysical Systems of Control
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
LMS bot: enhanced learning management systems for improved student learning e...
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
Advancing precision in air quality forecasting through machine learning integ...
“The Future of Visual AI: Efficient Multimodal Intelligence,” a Keynote Prese...
A hybrid framework for wild animal classification using fine-tuned DenseNet12...
Early detection and classification of bone marrow changes in lumbar vertebrae...
Build Real-Time ML Apps with Python, Feast & NoSQL
Ensemble model-based arrhythmia classification with local interpretable model...
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf

Latin America tour 2019 - Flashback

  • 1. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | bienvenido
  • 2. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Lo siento, no hablo español :-(
  • 3. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | But I will do my best to help Pero haré todo lo posible para ayudar
  • 4. Flashback - great for DBAs, great for Developers Connor McDonald Database Advocate una gran herramienta para DBA y desarrolladores
  • 5. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 5
  • 6. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 6
  • 7. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Me youtube bit.ly/youtube-connor blog bit.ly/blog-connor twitter bit.ly/twitter-connor 400+ posts mainly on database & development 250 technical videos, new uploads every week Más de 400 publicaciones principalmente en bases de datos y desarrollo 250 videos técnicos, nuevas cargas cada semana
  • 8. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. etc... facebook bit.ly/facebook-connor linkedin bit.ly/linkedin-connor instagram bit.ly/instagram-connor slideshare bit.ly/slideshare-connor
  • 9. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
  • 10. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
  • 11. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback 11
  • 12. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com several technologies 12 varias tecnologías diferentes
  • 13. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback query flashback table flashback drop flashback database flashback transaction flashback data archive
  • 14. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback query 14
  • 15. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com controversy 15 controversia
  • 16. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com you have always... 16 siempre has ...
  • 17. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com .. been using flashback query 17 .. estado usando una consulta flashback
  • 18. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com revision 18
  • 19. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> update EMP 2 set SAL = SAL * 1.10 3 / 14 rows updated. SQL> rollback; Rollback complete. how ? 19
  • 20. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com we remember stuff 20 recordamos cosas
  • 21. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> update EMP 2 set SAL = SAL * 1.10 3 / undo header smith $1,0001 block 2754 jones $9002 brown $1,5003 wells $2,0004 wilson $1,0005 block 2754, row 1, sal $1000 block 2754, row 2, sal $900 block 2754, row 3, sal $1500 block 2754, row 4, sal $2000 uba 5 5 $1,100 $990 $1,650 $2,200 uba 5.1uba 5.2
  • 22. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> rollback; 23
  • 23. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> rollback; undo header smith $1,0001 block 2754 jones $9002 brown $1,5003 wells $2,0004 wilson $1,0005 block 2754, row 1, sal $1000 block 2754, row 2, sal $900 block 2754, row 3, sal $1500 block 2754, row 4, sal $2000 uba 5 5 $1,100 $990 $1,650 $2,200 uba 5.1uba 5.2
  • 24. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com we can use this for queries! (Oracle version 4) 26 podemos usar esto para consultas!
  • 25. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com read consistency 27
  • 26. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com select * from emp where hiredate > '01/01/2004' update emp set … where empno = 1234; Block 3217 "I need block 3217… … as it was at 9:00" 9:00 9:03 9:05 session 1 session 2 ...and time = scn
  • 27. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com system change number 29 número de cambio del sistema
  • 28. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com Session 1 Request Block 3217, SCN 4567192 Block 3217, SCN 4567234 "ABC" Block 3217, SCN 4567003, change ABC => XYZ undo segment block(s) No good..too new take a copy of the block Locate apply undo Block 3217, SCN 4567234 "ABC" Block 3217, SCN 4567234 "ABC" Block 3217, SCN 4567003 "XYZ" Block 3217, SCN 4567003 "XYZ" Session 2 update emp set ename = "ABC" where empno = 1234; commit; Done ! 30
  • 29. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com every query = locked at a SCN 31 cada consulta = bloqueada en un SCN
  • 30. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 32 go back even further.... volver aún más lejos ...
  • 31. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback query = choose SCN 33 consulta de flashback = elegir SCN
  • 32. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com v9 34
  • 33. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select * from DEPT; DEPTNO DNAME LOC ---------- -------------- ------------- 10 UNKNOWN NEW YORK 20 UNKNOWN DALLAS 30 UNKNOWN CHICAGO 40 UNKNOWN BOSTON 35
  • 34. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select * from DEPT AS OF SCN 995401; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 36
  • 35. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com a little less geeky 37 un poco menos geek
  • 36. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select * from DEPT 2 AS OF TIMESTAMP systimestamp - 3 interval '20:00' minute to second; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 38
  • 37. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select TIMESTAMP_TO_SCN(systimestamp) from DUAL; TIMESTAMP_TO_SCN(SYSTIMESTAMP) ------------------------------ 998332 42
  • 38. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select SCN_TO_TIMESTAMP(998314) from DUAL; SCN_TO_TIMESTAMP(998314) ----------------------------------------------- 25-AUG-19 09.12.48.000000000 PM 43
  • 39. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 3 seconds 44
  • 40. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select scn_to_timestamp(2409511-rownum) 2 from dual 3 connect by level <= 50; SCN_TO_TIMESTAMP(2409511-ROWNUM) --------------------------------------------- 28-AUG-19 05.47.47.000000000 PM 28-AUG-19 05.47.47.000000000 PM 28-AUG-19 05.47.44.000000000 PM 28-AUG-19 05.47.41.000000000 PM 28-AUG-19 05.47.37.000000000 PM 28-AUG-19 05.47.34.000000000 PM 28-AUG-19 05.47.31.000000000 PM 28-AUG-19 05.47.28.000000000 PM 28-AUG-19 05.47.25.000000000 PM 45
  • 41. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com use in "normal" queries 46 utilizar en consultas "normales"
  • 42. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select e.empno, e.ename, d.dname 2 from emp e, 3 dept AS OF TIMESTAMP '23-AUG-19 11.51.02 PM' d 3 where d.deptno = e.deptno; EMPNO ENAME DNAME ---------- ---------- -------------- 7782 CLARK "PREVIOUS NAME" 7839 KING "PREVIOUS NAME" 7934 MILLER "PREVIOUS NAME" 7566 JONES RESEARCH 7902 FORD RESEARCH 7876 ADAMS RESEARCH 7369 SMITH RESEARCH 7788 SCOTT RESEARCH 47
  • 43. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "What's in it for me?" 48 "Qué hay para mi ahí dentro?"
  • 44. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 1) unit testing 49 código de prueba de la unidad
  • 45. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select case 2 when d1.deptno is null then 'DELETE' 3 when d2.deptno is null then 'INSERT' 4 end action, 5 d1.deptno, d2.deptno, d1.dname, d1.loc 6 from DEPT d1 full outer join 7 DEPT AS OF TIMESTAMP '23-AUG-19 11.51.02 PM' d2 8 on d1.deptno = d2.deptno; ACTION DEPTNO DEPTNO DNAME LOC ------ ---------- ---------- -------------- ---------- 10 10 ACCOUNTING NEW YORK 20 20 RESEARCH DALLAS 30 30 SALES CHICAGO DELETE 40 INSERT 50 MARKETING PERTH 50
  • 46. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 2) not just your data 51 no solo tus datos
  • 47. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> drop procedure debug_msg; Procedure dropped. SQL> connect / as sysdba Connected. SQL> select text 2 from dba_source 3 as of timestamp systimestamp - interval '5' minute 4 where name='DEBUG_MSG' order by line; TEXT --------------------------------------------------------------------- procedure debug_msg(m varchar2) is begin dbms_output.put_line(m); dbms_application_info.set_client_info(m); end; 5 rows selected. 52
  • 48. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 3) functional diagnosis 53 diagnóstico funcional
  • 49. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select * from DEPT; DEPTNO DNAME LOC ---------- -------------- ------------- 10 UNKNOWN NEW YORK SQL> select * from DEPT 2 as of TIMESTAMP SYSTIMESTAMP - 3 INTERVAL '20:00' MINUTE TO SECOND; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 1 change ? 10 changes ?
  • 50. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback row versions 55
  • 51. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> SELECT deptno, dname 2 FROM dept 3 VERSIONS BETWEEN 4 TIMESTAMP SYSTIMESTAMP – 5 INTERVAL '20:00' MINUTE TO SECOND 6 AND SYSTIMESTAMP 7 WHERE deptno = 10; DEPTNO DNAME ---------- -------------- 10 ACCOUNTING 10 MONEY GRABBERS 10 FINANCE 10 BEAN COUNTERS 10 UNKNOWN 1 row 5 versions 56
  • 52. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com versions_starttime versions_startscn versions_endtime versions_endscn versions_xid versions_operation 57
  • 53. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> SELECT deptno, dname, 2 VERSIONS_STARTTIME 3 ,VERSIONS_XID 4 ,VERSIONS_OPERATION 5 FROM dept 6 VERSIONS BETWEEN 7 TIMESTAMP SYSTIMESTAMP - INTERVAL '20:00' MINUTE TO SECOND 8 AND SYSTIMESTAMP 9 WHERE deptno = 10; DEPTNO DNAME VERSIONS_STARTTIME VERSIONS_XID V ---------- -------------- ------------------------ ---------------- - 10 UNKNOWN 03-AUG-19 11.53.45 PM 0200100060040000 U 10 MONEY GRABBERS 03-AUG-19 11.53.36 PM 0600050065040000 U 10 FINANCE 03-AUG-19 11.53.24 PM 09000D001D050000 U 10 BEAN COUNTERS 03-AUG-19 11.53.12 PM 01001A00EA030000 U 10 ACCOUNTING 58
  • 54. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com get everything ... 59 consigue todo ...
  • 55. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> SELECT deptno, dname, 2 VERSIONS_STARTTIME 3 ,VERSIONS_XID 4 ,VERSIONS_OPERATION 5 FROM dept VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE; DEPTNO DNAME VERSIONS_STARTTIME VERSIONS_XID V ---------- -------------- ------------------------ ---------------- - 50 UNKNOWN 03-AUG-19 11.08.15 PM 04000700EA030000 U 30 UNKNOWN 03-AUG-19 11.08.15 PM 04000700EA030000 U 20 NERDS 03-AUG-19 11.07.57 PM 090016001D050000 U 20 R&D 03-AUG-19 11.07.48 PM 05000B0074040000 U ...
  • 56. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com grant flashback to ... 61
  • 57. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com session level 62 nivel de sesión
  • 58. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com dbms_flashback.enable_at_time(systimestamp-1); 63
  • 59. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> exec dbms_flashback.enable_at_time( systimestamp-5/86400) PL/SQL procedure successfully completed. SQL> insert into T values (1); ERROR at line 1: ORA-08182: operation not supported while in Flashback mode 64
  • 60. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> exec dbms_flashback.disable; PL/SQL procedure successfully completed. SQL> exec dbms_flashback.enable_at_time( systimestamp-30/86400) PL/SQL procedure successfully completed. SQL> exec dbms_flashback.enable_at_time( systimestamp-60/86400) ERROR at line 1: ORA-08184: attempting to re-enable Flashback while in Flashback 65
  • 61. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com how far can you go back ? 66 hasta dónde puedes volver?
  • 62. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
  • 63. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com undo_retention 68
  • 64. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> show parameter undo_retention NAME TYPE VALUE ------------------------------ ----------- -------- undo_retention integer 900 69 ~
  • 65. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> desc v$undostat Name Null? Type ----------------------------- -------- ---------------- BEGIN_TIME DATE END_TIME DATE ... ... TUNED_UNDORETENTION NUMBER CON_ID NUMBER 70
  • 66. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com to go much much further flashback data archive ir mucho más lejos
  • 67. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "no" spanning DDL 72 better each version "no" que abarca DDL
  • 68. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com rewind the data, not time 73 charactersets, NLS etc rebobinar los datos, no el tiempo
  • 69. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback transaction 74
  • 70. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> SELECT deptno, dname, 2 VERSIONS_STARTTIME 3 ,VERSIONS_XID 4 ,VERSIONS_OPERATION 5 FROM dept VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE; DEPTNO DNAME VERSIONS_STARTTIME VERSIONS_XID V ---------- -------------- ------------------------ ---------------- - 50 UNKNOWN 03-AUG-19 11.08.15 PM 04000700EA030000 U 30 UNKNOWN 03-AUG-19 11.08.15 PM 04000700EA030000 U 20 NERDS 03-AUG-19 11.07.57 PM 090016001D050000 U 20 R&D 03-AUG-19 11.07.48 PM 05000B0074040000 U ...
  • 71. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com XID ? 76
  • 72. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> desc V$TRANSACTION Name Null? Type ----------------------------- -------- ------- XIDUSN NUMBER XIDSLOT NUMBER XIDSQN NUMBER ... 77
  • 73. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select XIDUSN, XIDSLOT, XIDSQN 2 from v$transaction XIDUSN XIDSLOT XIDSQN ---------- ---------- ---------- 1 31 674 SQL> select versions_xid from ... VERSIONS_XID ------------------- 01 001F 00A202 0000 78
  • 74. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> desc FLASHBACK_TRANSACTION_QUERY Name Null? Type ----------------------- -------- -------------- XID RAW(8) START_SCN NUMBER START_TIMESTAMP DATE COMMIT_SCN NUMBER COMMIT_TIMESTAMP DATE LOGON_USER VARCHAR2(30) UNDO_CHANGE# NUMBER OPERATION VARCHAR2(32) TABLE_NAME VARCHAR2(256) TABLE_OWNER VARCHAR2(32) ROW_ID VARCHAR2(19) UNDO_SQL VARCHAR2(4000) 79
  • 75. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select DNAME from dept 2 where deptno = 10; DNAME ------- FINANCE SQL> select xid, undo_sql 2 from flashback_transaction_query 3 where xid = hextoraw('09000d001d050000'); XID UNDO_SQL ---------------- ------------------------------------ 09000D001D050000 update "SCOTT"."DEPT" set "DNAME" = 'BEAN COUNTERS' where ROWID = 'AAAQ+hAAEAAAAAOAAA'; 80
  • 76. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com be careful 81 ten cuidado
  • 77. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select text from dba_views 2 where view_name 3 = 'FLASHBACK_TRANSACTION_QUERY'; TEXT ------------------------------------------------ select xid, start_scn, start_timestamp, decode(commit_scn, 0, commit_scn, 281474976710655, NULL, commit_scn) commit_scn, commit_timestamp, logon_user, undo_change#, operation, table_name, table_owner, row_id, undo_sql from SYS.X$KTUQQRY 82
  • 78. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com do not query without predicates ... 83 no consultar sin predicados ...
  • 79. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com do not forget hextoraw 84 no te olvides de hextoraw
  • 80. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
  • 81. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select xid, undo_sql 2 from flashback_transaction_query 3 where xid = hextoraw('09000d001d050000'); ----------------------------------------------------- | Id | Operation | Name | ----------------------------------------------------- | 0 | SELECT STATEMENT | | |* 1 | FIXED TABLE FIXED INDEX| X$KTUQQRY (ind:1) | ----------------------------------------------------- 86
  • 82. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select xid, undo_sql 2 from flashback_transaction_query 3 where xid = '09000d001d050000'; -------------------------------------- | Id | Operation | Name | -------------------------------------- | 0 | SELECT STATEMENT | | | 1 | FIXED TABLE FULL| X$KTUQQRY | -------------------------------------- 87
  • 83. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com UNDO_SQL 88
  • 84. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com undo a committed transaction 89 deshacer una transacción comprometida
  • 85. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "What's in it for me?" 90 "Qué hay para mi ahí dentro?"
  • 86. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com three words 91
  • 87. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com delete agggh... commit
  • 88. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 93
  • 89. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback transaction 94
  • 90. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> BEGIN 2 DBMS_FLASHBACK.TRANSACTION_BACKOUT( 3 numtxns=>1, 4 xids=>sys.xid_array('09000D001D050000') 5 ); 6 END; 7 / BEGIN * ERROR at line 1: ORA-55510: Mining could not start ORA-06512: at "SYS.DBMS_FLASHBACK", line 37 ORA-06512: at "SYS.DBMS_FLASHBACK", line 70 ORA-06512: at line 2 '09000D001D050000' 95
  • 91. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 96
  • 92. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> ALTER DATABASE ADD 2 SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS; Database altered. 97
  • 93. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> delete from DEPT 2 where DEPTNO = 10; 1 row deleted. SQL> commit; Commit complete. SQL> SELECT VERSIONS_XID 2 FROM dept 3 VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE; VERSIONS_XID ---------------- 080017006C040000 98
  • 94. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> BEGIN 2 DBMS_FLASHBACK.TRANSACTION_BACKOUT( 3 numtxns=>1, 4 xids=>sys.xid_array('080017006C040000') 5 ); 6 END; 7 / SQL> select * from DEPT; DEPTNO DNAME LOC ---------- -------------- ---------- 20 RESEARCH DALLAS 30 SALES CHICAGO 50 MARKETING PERTH 40 HR US 99
  • 95. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com KEEP CALM AND DON'T PANIC
  • 96. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> SELECT COMPENSATING_XID 2 FROM DBA_FLASHBACK_TXN_STATE 3 WHERE xid = '080017006C040000'; COMPENSATING_XID ---------------- 03001C0072040000 101
  • 97. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> SELECT xid_report 2 FROM DBA_FLASHBACK_TXN_REPORT 3 WHERE compensating_xid = '03001C0072040000'; XID_REPORT -------------------------------------------------------- <COMP_XID_REPORT XID="03001C0072040000"> <TRANSACTION XID="080017006C040000"> <UNDO_SQL> <USQL exec="yes"> insert into "SCOTT"."DEPT"("DEPTNO","DNAME","LOC") values ('10','ACCOUNTING','NEW YORK') </USQL> </UNDO_SQL> </TRANSACTION> <EXECUTED_UNDO_SQL> <EXEC_USQL> insert into "SCOTT"."DEPT"("DEPTNO","DNAME","LOC") values ('10','ACCOUNTING','NEW YORK') </EXEC_USQL> </EXECUTED_UNDO_SQL> </COMP_XID_REPORT> 102
  • 98. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> commit; Commit complete. SQL> select * from dept; DEPTNO DNAME LOC ---------- -------------- ---------- 20 RESEARCH DALLAS 30 SALES CHICAGO 50 MARKETING PERTH 40 HR US 10 ACCOUNTING NEW YORK 103
  • 99. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com some typical restrictions 104 ddl, old lobs, xml algunas restricciones típicas
  • 100. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback drop 105
  • 101. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com delete agggh... commit
  • 102. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback transaction 107
  • 103. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com three words two 108
  • 104. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com drop agggh...
  • 105. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> desc EMP ERROR: ORA-04043: object EMP does not exist 110
  • 106. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 111
  • 107. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "undrop" 113
  • 108. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com not cool enough 114 no lo suficientemente genial
  • 109. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback table to before drop 115
  • 110. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
  • 111. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> desc USER_RECYCLEBIN Name Null? Type ----------------------------- -------- -------------------- OBJECT_NAME NOT NULL VARCHAR2(30) ORIGINAL_NAME VARCHAR2(32) OPERATION VARCHAR2(9) TYPE VARCHAR2(25) TS_NAME VARCHAR2(30) CREATETIME VARCHAR2(19) DROPTIME VARCHAR2(19) DROPSCN NUMBER PARTITION_NAME VARCHAR2(32) CAN_UNDROP VARCHAR2(3) CAN_PURGE VARCHAR2(3) RELATED NOT NULL NUMBER BASE_OBJECT NOT NULL NUMBER PURGE_OBJECT NOT NULL NUMBER SPACE NUMBER 117
  • 112. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select OBJECT_NAME, ORIGINAL_NAME, 2 CAN_UNDROP, CAN_PURGE 3 from USER_RECYCLEBIN; OBJECT_NAME ORIGINAL_NAME CAN CAN -------------------------------- ------------------- --- --- BIN$CmYCdNcITL6hp9l266nskA==$0 PK_EMP NO YES BIN$b/W75+c/Q/CeFMBIK7cXfw==$0 EMP YES YES 118
  • 113. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> show RECYCLEBIN 119
  • 114. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com indexes / constraints / triggers ... all renamed todos renombrados
  • 115. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> flashback table EMP to before drop; Flashback complete. 121
  • 116. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> flashback table EMP to before drop 2 rename to OLD_EMP; Flashback complete. 122
  • 117. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com indexes / constraints / triggers ... not renamed back no renombrado de nuevo
  • 118. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com how long ? 124 cuánto tiempo ?
  • 119. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 1 second... ...10 years 125
  • 120. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> PURGE RECYCLEBIN; SQL> PURGE TABLE emp; SQL> PURGE TABLE "BIN$xyWe0+q+SniItJ0pn/u54A==$0"; SQL> PURGE TABLESPACE user1; SQL> PURGE INDEX "BIN$FTX34MN88J7==$0"; SQL> PURGE TABLESPACE user1 USER fred; 126
  • 121. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com no untruncate 127
  • 122. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback table 128
  • 123. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
  • 124. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback table 130
  • 125. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> FLASHBACK TABLE DEPT 2 TO TIMESTAMP TO_TIMESTAMP('2019-08-23 12:05:00') 131
  • 126. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "undrop" 132
  • 127. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "What's in it for me?" 133 "Qué hay para mi ahí dentro?"
  • 128. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com repeatable tests without cleanup scripts 134 pruebas repetibles sin scripts de limpieza
  • 129. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com deletes modified rows since SCN inserts fresh rows as of SCN ... busy elimina registros modificadas desde SCN inserta registros nuevas a partir de SCN
  • 130. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> FLASHBACK TABLE DEPT 2 TO TIMESTAMP TO_TIMESTAMP('2019-08-23 12:05:00') 3 ENABLE TRIGGERS; 136
  • 131. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com rowid's change ... enable row movement 137
  • 132. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com indexes existence unaffected 138 indexa la existencia no afectada
  • 133. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com single transaction 139 ... multiple tables allowed transacción única
  • 134. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com tables locked 140 mesas cerradas
  • 135. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com R.I must still be valid 141 R.I todavía debe ser válido
  • 136. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com statistics unchanged 142 estadísticas sin cambios
  • 137. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com most DDL is a flashback boundary 143 la mayoría de DDL es un límite de flashback
  • 138. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> flashback table DEPT to scn ...; ORA-01466: unable to read data - table definition has changed 144
  • 139. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com each version gets better 145 cada versión mejora
  • 140. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> alter table DEPT add column XXX date; SQL> flashback table DEPT to scn ...; SQL> desc DEPT Name Null? Type -------------------------- -------- -------------- DEPTNO NUMBER(2) DNAME VARCHAR2(14) LOC VARCHAR2(13) XXX DATE 146
  • 141. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> flashback table DEPT to scn ...; ORA-08183: Flashback cannot be enabled in the middle of a transaction 147
  • 142. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback database 148
  • 143. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
  • 144. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
  • 145. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback database 151
  • 146. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | AUTHORISED DATABASE ADMINSTRATORS ONLY !
  • 147. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> alter database flashback on; Database altered. 153
  • 148. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 154 data changes "new" blocks to disk changes to disk "old" blocks to disk redo fbdadbwr
  • 149. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> FLASHBACK DATABASE TO '2:05PM' 155
  • 150. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> create restore point OK_SO_FAR; ... SQL> flashback database to restore point OK_SO_FAR; 156
  • 151. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com what is the resource cost ? 157 Cuál es el costo de los recursos?
  • 152. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> desc V$FLASHBACK_DATABASE_STAT Name Null? Type ----------------------------- -------- --------- BEGIN_TIME DATE END_TIME DATE FLASHBACK_DATA NUMBER DB_DATA NUMBER REDO_DATA NUMBER ESTIMATED_FLASHBACK_SIZE NUMBER 158
  • 153. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com a good compromise 162 un buen compromiso
  • 154. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com guaranteed restore points 163 puntos de restauración garantizados
  • 155. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback logging "optional" 164
  • 156. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "What's in it for me?" 166 "Qué hay para mi ahí dentro?"
  • 157. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 1) safer deployment 167 despliegue más seguro
  • 158. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com scenario: "My New Application" 168 escenario: "Mi nueva aplicación"
  • 159. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 9:00 9:40 9:45 SQL> FLASHBACK DATABASE... 169 SQL> alter table ACCOUNTS ...
  • 160. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 2) repeatable end to end testing 170 prueba repetible de extremo a extremo
  • 161. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 171
  • 162. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 12.2+ 172
  • 163. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback pluggable database 173
  • 164. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 3) production data for developers 174 datos de producción para desarrolladores
  • 165. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "hidden" example 175 ejemplo "oculto"
  • 166. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com Data Guard 176
  • 167. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 177 5:00am 11:30pm standby recovery convert to snapshot revert to physical
  • 168. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback data archive 182
  • 169. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com less flashback, more archive 183
  • 170. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> CREATE FLASHBACK ARCHIVE longterm 2 TABLESPACE space_for_archive 3 RETENTION 1 YEAR; Flashback archive created. 185
  • 171. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> ALTER TABLE EMP FLASHBACK ARCHIVE LONGTERM; Table altered. [lots of DML on EMP] 186
  • 172. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select * from EMP; -------------------------------------------------- | Id | Operation | Name | Rows | Bytes | -------------------------------------------------- | 0 | SELECT STATEMENT | | 14 | 518 | | 1 | TABLE ACCESS FULL| EMP | 14 | 518 | -------------------------------------------------- 187
  • 173. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select * from EMP 2 AS OF TIMESTAMP SYSDATE-1/24; -------------------------------------------------- | Id | Operation | Name | Rows | Bytes | -------------------------------------------------- | 0 | SELECT STATEMENT | | 14 | 518 | | 1 | TABLE ACCESS FULL| EMP | 14 | 518 | -------------------------------------------------- 188
  • 174. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 3 days later... 189
  • 175. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select * from EMP 2 AS OF TIMESTAMP SYSDATE-3; ----------------------------------------------------------------- | Id | Operation | Name | Rows | ----------------------------------------------------------------- | 0 | SELECT STATEMENT | | 446 | | 1 | VIEW | | 446 | | 2 | UNION-ALL | | | |* 3 | FILTER | | | | 4 | PARTITION RANGE ITERATOR| | 445 | |* 5 | TABLE ACCESS FULL | SYS_FBA_HIST_69539 | 445 | |* 6 | FILTER | | | |* 7 | HASH JOIN OUTER | | 1 | |* 8 | TABLE ACCESS FULL | EMP | 1 | |* 9 | TABLE ACCESS FULL | SYS_FBA_TCRV_69539 | 14 | ------------------------------------------------------------------190
  • 176. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select table_name 2 from user_tables 3 / TABLE_NAME --------------------------- SYS_FBA_HIST_71036 SYS_FBA_TCRV_71036 SYS_FBA_DDL_COLMAP_71036 EMP 191
  • 177. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select dbms_metadata.get_ddl( 2 'TABLE', 3 'SYS_FBA_TCRV_71036') from dual; DDL ------------------------------------ CREATE TABLE "SCOTT"."SYS_FBA_TCRV_71036" ( "RID" VARCHAR2(4000), "STARTSCN" NUMBER, "ENDSCN" NUMBER, "XID" RAW(8), "OP" VARCHAR2(1) ) SEGMENT CREATION IMMEDIATE TABLESPACE "SPACE_FOR_ARCHIVE" 192
  • 178. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select dbms_metadata.get_ddl( 2 'TABLE', 3 'SYS_FBA_HIST_71036') from dual; DDL ------------------------------------------ CREATE TABLE "SCOTT"."SYS_FBA_HIST_71036" ( "RID" VARCHAR2(4000), "STARTSCN" NUMBER, "ENDSCN" NUMBER, "XID" RAW(8), "OPERATION" VARCHAR2(1), "EMPNO" NUMBER(4,0), "ENAME" VARCHAR2(10), "JOB" VARCHAR2(9), "MGR" NUMBER(4,0), "HIREDATE" DATE, "SAL" NUMBER(7,2), "COMM" NUMBER(7,2), "DEPTNO" NUMBER(2,0) ) COMPRESS FOR OLTP TABLESPACE "SPACE_FOR_ARCHIVE" PARTITION BY RANGE ("ENDSCN") ( PARTITION "HIGH_PART" VALUES LESS THAN (MAXVALUE) )
  • 179. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "What's in it for me?" 196 "Qué hay para mi ahí dentro?"
  • 180. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "I don't care what EMP looked like last March..." 197 "No me importa cómo se veía EMP como el pasado marzo ... "
  • 181. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 198 why talk about it ? por qué hablar de eso?
  • 182. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 199 SQL> select * from EMP AS OF "JUNE"; SQL> select * from EMP AS OF "MARCH"; SQL> select * from EMP AS OF "2pm Wednesday"; SQL> select * from EMP AS OF etc etc etc
  • 183. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 200 every historical version... cada versión histórica ...
  • 184. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 201 ... of every row de cada fila
  • 185. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 202 sound familiar ? suena familiar ?
  • 186. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 203 audit history historial de auditoria
  • 187. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 206 SQL> create or replace 2 trigger AUDIT_TRG 3 after insert or update or delete on T 4 for each row 5 declare 6 v_action varchar2(1) := case when updating 7 then 'U' when deleting then 'D' else 'I' end; 8 begin 9 if updating or inserting then 10 insert into T_AUDIT 11 values (sysdate 12 ,v_action 13 ,:new.owner 14 ,:new.object_name); 15 else 16 insert into T_AUDIT 17 values (sysdate 18 ,v_action 19 ,:old.owner 20 ,:old.object_name); 21 end if; 22 end;
  • 188. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com a better, faster, robust version ... 209 una versión mejor, más rápida y robusta ...
  • 189. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback data archive 210
  • 190. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select empno, ename, job, sal, comm, 2 nvl(VERSIONS_STARTTIME,LAST_MOD) TS 3 ,nvl(VERSIONS_OPERATION,'I') op 4 from EMP 5 versions between timestamp 6 timestamp '2019-02-11 20:12:00' and systimestamp 7 order by empno, ts; EMPNO ENAME JOB SAL COMM TS O ---------- ---------- --------- ---------- ---------- ------------ - 7369 SMITH CLERK 806 08.10.51 PM I 7369 SMITH SALES 8060 1000 08.12.10 PM U 7499 ALLEN SALESMAN 1606 300000000 08.10.51 PM I 7521 WARD SALESMAN 1256 500000000 08.10.51 PM I 7566 JONES MANAGER 2981 08.10.51 PM I ... 7900 JAMES CLERK 956 08.10.51 PM I 7902 FORD ANALYST 3006 08.10.51 PM I 7934 MILLER CLERK 1306 08.10.51 PM I 7934 MILLER CLERK 1306 08.12.10 PM D 211
  • 191. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com so why didn't we do it? 212 Entonces, por qué no lo hicimos?
  • 192. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
  • 193. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com separately licensed 218 licencia por separado
  • 194. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback data archive is now … 232
  • 195. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 233 gratis!
  • 196. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com this is not a typo 234 Esto no es un error tipográfico
  • 197. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com basic versus advanced 235 básico versus avanzado
  • 198. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com wrap up 259
  • 199. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback query flashback table flashback drop flashback database flashback transaction flashback data archive
  • 200. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com all included in EE 262 todo incluido en EE
  • 201. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com all cool for modern development 263 todo genial para el desarrollo moderno
  • 202. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com Thank you! youtube bit.ly/youtube-connor blog bit.ly/blog-connor twitter bit.ly/twitter-connor Gracias! slideshare bit.ly/slideshare-connor