SlideShare a Scribd company logo
7/22/2019
1
Flashback - the forgotten feature
Connor McDonald
Database Advocate
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
2
1
2
7/22/2019
2
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
3
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Stuff
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
rants and raves on tech and the world :-)
3
4
7/22/2019
3
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 © 2018, Oracle and/or its affiliates. All rights reserved. |
In Memoriam
5
6
7/22/2019
4
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
7
8
7/22/2019
5
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback
9
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
several technologies
10
9
10
7/22/2019
6
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
12
11
12
7/22/2019
7
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
controversy
13
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
you have always...
14
13
14
7/22/2019
8
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
.. been using flashback query
15
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
revision
16
15
16
7/22/2019
9
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 ?
17
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
we remember stuff
18
17
18
7/22/2019
10
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;
21
20
21
7/22/2019
11
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 stuff for queries!
(Oracle version 4)
24
23
24
7/22/2019
12
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
read consistency
25
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
25
26
7/22/2019
13
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
system change number
27
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 !
28
27
28
7/22/2019
14
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
every query = locked at a SCN
29
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
30
go back even further....
29
30
7/22/2019
15
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback query = choose SCN
31
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
v9
32
31
32
7/22/2019
16
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
33
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
34
33
34
7/22/2019
17
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
a little less geeky
35
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
36
35
36
7/22/2019
18
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
smon_scn_time
37
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
smon_scn_time ???
38
37
38
7/22/2019
19
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
obsolete*
39
more later on this
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
40
39
40
7/22/2019
20
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-FEB-19 09.12.48.000000000 PM
41
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
3 seconds
42
41
42
7/22/2019
21
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-FEB-19 05.47.47.000000000 PM
28-FEB-19 05.47.47.000000000 PM
28-FEB-19 05.47.44.000000000 PM
28-FEB-19 05.47.41.000000000 PM
28-FEB-19 05.47.37.000000000 PM
28-FEB-19 05.47.34.000000000 PM
28-FEB-19 05.47.31.000000000 PM
28-FEB-19 05.47.28.000000000 PM
28-FEB-19 05.47.25.000000000 PM
43
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
use in "normal" queries
44
43
44
7/22/2019
22
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-FEB-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
45
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"What's in it for me?"
46
45
46
7/22/2019
23
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
1) unit testing
47
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-FEB-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
48
47
48
7/22/2019
24
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
2) not just your data
49
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.
50
49
50
7/22/2019
25
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
3) functional diagnosis
51
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 ?
51
52
7/22/2019
26
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback row versions
53
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
54
53
54
7/22/2019
27
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
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
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-SEP-18 11.53.45 PM 0200100060040000 U
10 MONEY GRABBERS 03-SEP-18 11.53.36 PM 0600050065040000 U
10 FINANCE 03-SEP-18 11.53.24 PM 09000D001D050000 U
10 BEAN COUNTERS 03-SEP-18 11.53.12 PM 01001A00EA030000 U
10 ACCOUNTING
56
55
56
7/22/2019
28
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
get the lot ...
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 VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE;
DEPTNO DNAME VERSIONS_STARTTIME VERSIONS_XID V
---------- -------------- ------------------------ ---------------- -
50 UNKNOWN 03-SEP-18 11.08.15 PM 04000700EA030000 U
30 UNKNOWN 03-SEP-18 11.08.15 PM 04000700EA030000 U
20 NERDS 03-SEP-18 11.07.57 PM 090016001D050000 U
20 R&D 03-SEP-18 11.07.48 PM 05000B0074040000 U
...
57
58
7/22/2019
29
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
grant flashback to ...
59
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
session level
60
59
60
7/22/2019
30
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
dbms_flashback.enable_at_time(systimestamp-1);
61
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
62
61
62
7/22/2019
31
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
63
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
just how far ?
64
63
64
7/22/2019
32
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
66
65
66
7/22/2019
33
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
67
~
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
68
67
68
7/22/2019
34
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
much much further
flashback data archive
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"no" spanning DDL
70
better each version
69
70
7/22/2019
35
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
rewind the data, not time
71
charactersets,
NLS etc
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback
transaction
72
71
72
7/22/2019
36
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-SEP-18 11.08.15 PM 04000700EA030000 U
30 UNKNOWN 03-SEP-18 11.08.15 PM 04000700EA030000 U
20 NERDS 03-SEP-18 11.07.57 PM 090016001D050000 U
20 R&D 03-SEP-18 11.07.48 PM 05000B0074040000 U
...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
XID ?
74
73
74
7/22/2019
37
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
...
75
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
76
75
76
7/22/2019
38
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)
77
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';
78
77
78
7/22/2019
39
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
be careful
79
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
80
79
80
7/22/2019
40
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
do not query without predicates ...
81
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
do not forget hextoraw
82
81
82
7/22/2019
41
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) |
-----------------------------------------------------
84
83
84
7/22/2019
42
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 |
--------------------------------------
85
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
UNDO_SQL
86
85
86
7/22/2019
43
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
rollback committed transaction
87
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"What's in it for me?"
88
87
88
7/22/2019
44
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
three words
89
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
delete
uh-oh...
commit
89
90
7/22/2019
45
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
91
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
undo a committed transaction
92
91
92
7/22/2019
46
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback transaction
93
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'
94
93
94
7/22/2019
47
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
95
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.
96
95
96
7/22/2019
48
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
97
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
? 98
97
98
7/22/2019
49
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
100
99
100
7/22/2019
50
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>
101
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
102
101
102
7/22/2019
51
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
some typical restrictions
103
ddl, old lobs, xml
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback
drop
104
103
104
7/22/2019
52
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
delete
uh-oh...
commit
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback transaction
106
105
106
7/22/2019
53
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
three words
two
107
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
drop
uh-oh...
107
108
7/22/2019
54
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
109
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
109
110
7/22/2019
55
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
hard
place
You are here
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"undrop"
112
111
112
7/22/2019
56
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
not cool enough
113
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback table to before drop
114
113
114
7/22/2019
57
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
116
115
116
7/22/2019
58
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
117
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> show RECYCLEBIN
118
117
118
7/22/2019
59
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
indexes / constraints / triggers
... all renamed
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> flashback table EMP to before drop;
Flashback complete.
120
119
120
7/22/2019
60
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.
121
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
indexes / constraints / triggers
... not renamed back
121
122
7/22/2019
61
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
how long ?
123
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
1 second...
...10 years
124
123
124
7/22/2019
62
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;
125
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
no untruncate
126
125
126
7/22/2019
63
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback
table
127
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
127
128
7/22/2019
64
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback table
129
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-06-03 12:05:00')
130
129
130
7/22/2019
65
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"undrop"
131
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"What's in it for me?"
132
131
132
7/22/2019
66
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
repeatable tests without cleanup scripts
133
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
133
134
7/22/2019
67
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-06-03 12:05:00')
3 ENABLE TRIGGERS;
135
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
rowid's change
... enable row movement
136
135
136
7/22/2019
68
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
indexes existence unaffected
137
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
single transaction
138
... multiple tables allowed
137
138
7/22/2019
69
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
tables locked
139
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
R.I must still be valid
140
139
140
7/22/2019
70
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
statistics unchanged
141
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
most DDL is a flashback boundary
142
141
142
7/22/2019
71
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
143
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
each release gets better
144
143
144
7/22/2019
72
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
145
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
146
145
146
7/22/2019
73
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback
database
147
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
147
148
7/22/2019
74
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
150
149
150
7/22/2019
75
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.
152
151
152
7/22/2019
76
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
153
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'
154
153
154
7/22/2019
77
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;
155
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
what does it cost ?
156
155
156
7/22/2019
78
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
157
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
a good compromise
161
157
161
7/22/2019
79
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
guaranteed restore points
162
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback logging "optional"
163
162
163
7/22/2019
80
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"What's in it for me?"
165
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
1) safer deployment
166
165
166
7/22/2019
81
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
scenario: "My New Application"
167
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
9:00
9:40
9:45 SQL> FLASHBACK DATABASE...
168
SQL> alter table ACCOUNTS ...
167
168
7/22/2019
82
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
2) repeatable end to end testing
169
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
170
169
170
7/22/2019
83
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
12.2+
171
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback pluggable database
172
171
172
7/22/2019
84
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
3) production data for developers
173
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"hidden" example
174
173
174
7/22/2019
85
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
Data Guard
175
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
176
5:00am
11:30pm
standby recovery
convert to snapshot
revert to physical
175
176
7/22/2019
86
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback
data archive
181
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
less flashback, more archive
182
181
182
7/22/2019
87
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.
184
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]
185
184
185
7/22/2019
88
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 |
--------------------------------------------------
186
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 |
--------------------------------------------------
187
186
187
7/22/2019
89
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
3 days later...
188
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 |
------------------------------------------------------------------189
188
189
7/22/2019
90
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
190
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"
191
190
191
7/22/2019
91
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
193
note
192
193
7/22/2019
92
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
194
"The table does not use any of these
Flashback Data Archive reserved words
as column names:
• STARTSCN
• ENDSCN
• RID
• XID
• OP
• OPERATION"
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"What's in it for me?"
195
194
195
7/22/2019
93
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..."
196
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
197
why talk about it ?
196
197
7/22/2019
94
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
198
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
199
every historical version...
198
199
7/22/2019
95
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
200
... of every row
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
201
sound familiar ?
200
201
7/22/2019
96
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
202
audit history
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
203
we've all done it
202
203
7/22/2019
97
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
204
SQL> desc T
Name Null? Type
------------------------ -------- -------------
OWNER NOT NULL VARCHAR2(30)
OBJECT_NAME NOT NULL VARCHAR2(30)
SQL> desc T_AUDIT
Name Null? Type
------------------------ -------- --------------
AUDIT_DATE DATE
AUDIT_ACTION CHAR(1)
OWNER NOT NULL VARCHAR2(30)
OBJECT_NAME NOT NULL VARCHAR2(30)
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
205
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;
204
205
7/22/2019
98
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
206
works but slow...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
207
SQL> insert into T
2 select owner, object_name
3 from all_objects
4 where rownum <= 10000;
10000 rows created.
insert into T select owner, object_name
from all_objects where rownum <= 10000
call count cpu elapsed disk query current rows
------- ------ ------- ---------- -------- --------- ---------- ----------
Parse 1 0.01 0.00 0 0 0 0
Execute 1 3.10 3.05 88 123 10642 10000
Fetch 0 0.00 0.00 0 0 0 0
------- ------ ------- ---------- -------- --------- ---------- ----------
total 2 3.12 3.06 88 123 10642 10000
INSERT INTO T_AUDIT
VALUES (SYSDATE ,:B3 ,:B1 ,:B2 )
call count cpu elapsed disk query current rows
------- ------ ------- ---------- -------- --------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 10000 0.79 0.97 2 109 10845 10000
Fetch 0 0.00 0.00 0 0 0 0
------- ------ ------- ---------- -------- --------- ---------- ----------
total 10001 0.79 0.97 2 109 10845 10000
206
207
7/22/2019
99
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
a better, faster, robust version ...
208
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback data archive
209
208
209
7/22/2019
100
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
210
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
so why didn't we ?
211
210
211
7/22/2019
101
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
reason 1
212
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"yeah...but who ? where ? how ?"
213
212
213
7/22/2019
102
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> alter table EMP add UPDATED_BY varchar2(10);
Table altered.
SQL> alter table EMP add UPDATED_PGM varchar2(10);
Table altered.
[etc]
214
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
reason 2
215
214
215
7/22/2019
103
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
217
216
217
7/22/2019
104
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
12c+ ... more options
218
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
1) context extension
219
218
219
7/22/2019
105
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> begin
2 dbms_flashback_archive.set_context_level(
3 level=> 'ALL');
4 end;
PL/SQL procedure successfully completed.
220
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> update EMP
2 set sal = sal*10
3 where empno = 7499;
1 row updated.
SQL> commit;
221
220
221
7/22/2019
106
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select XID from SYS_FBA_HIST_510592;
XID
----------------
09000B00C7080000
222
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> set serverout on
SQL> begin
2 dbms_output.put_line(
3 dbms_flashback_archive.get_sys_context (
4 '09000B00C7080000', 'USERENV', 'SESSION_USER'));
5
6 dbms_output.put_line(
7 dbms_flashback_archive.get_sys_context (
8 '09000B00C7080000', 'USERENV', 'HOST'));
9
10 dbms_output.put_line(
11 dbms_flashback_archive.get_sys_context (
12 '09000B00C7080000', 'USERENV', 'MODULE'));
13 end;
14 /
SCOTT
WORKGROUPXPS
SQL*Plus
223
222
223
7/22/2019
107
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
...and a few other things :-)
224
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> desc SYS.SYS_FBA_CONTEXT_AUD
Name Null? Type
------------------------- -------- ------------------
XID RAW(8)
ACTION VARCHAR2(256)
AUTHENTICATED_IDENTITY VARCHAR2(256)
CLIENT_IDENTIFIER VARCHAR2(256)
CLIENT_INFO VARCHAR2(256)
CURRENT_EDITION_NAME VARCHAR2(256)
CURRENT_SCHEMA VARCHAR2(256)
CURRENT_USER VARCHAR2(256)
DATABASE_ROLE VARCHAR2(256)
DB_NAME VARCHAR2(256)
GLOBAL_UID VARCHAR2(256)
HOST VARCHAR2(256)
IDENTIFICATION_TYPE VARCHAR2(256)
INSTANCE_NAME VARCHAR2(256)
IP_ADDRESS VARCHAR2(256)
MODULE VARCHAR2(256)
OS_USER VARCHAR2(256)
225
224
225
7/22/2019
108
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> @pt "select * from SYS.SYS_FBA_CONTEXT_AUD
where xid = '09000B00C7080000'"
XID : 09000B00C7080000
AUTHENTICATED_IDENTITY : scott
CLIENT_IDENTIFIER :
CLIENT_INFO :
CURRENT_EDITION_NAME : ORA$BASE
CURRENT_SCHEMA : SYS
CURRENT_USER : SYS
DATABASE_ROLE : PRIMARY
DB_NAME : np12
HOST : WORKGROUPXPS
IDENTIFICATION_TYPE : LOCAL
INSTANCE_NAME : np12
MODULE : SQL*Plus
OS_USER : xpshamcdc
SERVER_HOST : xps
...
226
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select empno, ename, job, sal, comm,
2 VERSIONS_XID
3 from EMP
4 versions between timestamp
5 timestamp '2019-02-11 20:12:00' and systimestamp
6 order by empno;
EMPNO ENAME JOB SAL COMM VERSIONS_XID
---------- ---------- --------- ---------- ---------- ----------------
7369 SMITH CLERK 806
7369 SMITH SALES 8060 1000 09001C00E04A0000
7499 ALLEN CLERK 16060 300000000 0A000A0024080000
7499 ALLEN SALESMAN 16060 300000000 09000B00C7080000
7499 ALLEN SALESMAN 1606 300000000
7521 WARD SALESMAN 1256 500000000
227
226
227
7/22/2019
109
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> select ...
2 from
3 ( select
4 empno, ename, job,
5 sal, comm, VERSIONS_XID
6 from EMP
7 versions between timestamp
8 timestamp '2019-02-11 20:12:00' and
9 systimestamp
10 ) e, SYS.SYS_FBA_CONTEXT_AUD a
11 where e.VERSIONS_XID = a.XID;
228
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
2) price...
230
228
230
7/22/2019
110
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
flashback data archive is now …
231
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
232
231
232
7/22/2019
111
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
not a typo
233
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
basic versus advanced
234
233
234
7/22/2019
112
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
choose your cost
compression
235
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
so think about FDA
236
235
236
7/22/2019
113
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
secure
read only
237
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
efficient
fdba
238
237
238
7/22/2019
114
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
all of your history...
239
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
... all of your audit
240
239
240
7/22/2019
115
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
"Where were you in 2004 ?!?!?"
241
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
dbms_flashback_archive.import_history
242
241
242
7/22/2019
116
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
be careful ... silent errors
243
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
SQL> ALTER TABLE EMP FLASHBACK ARCHIVE LONGTERM;
Table altered.
Flashback Archive:
Error ORA-1950 in SQL create table "SCOTT".SYS_FBA_DDL_COLMAP_91938
(STARTSCN NUMBER, ENDSCN NUMBER...
Flashback Archive:
Error ORA-942 in SQL insert into "SCOTT".SYS_FBA_DDL_COLMAP_91938
(ENDSCN, COLUMN_NAME, TYPE, ...
244
243
244
7/22/2019
117
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
wrap up
258
248
258
7/22/2019
118
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
260
259
260
7/22/2019
119
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
all cool for modern development
261
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com
That's a wrap!
youtube bit.ly/youtube-connor
blog bit.ly/blog-connor
twitter bit.ly/twitter-connor
261
262

More Related Content

Similar to OG Yatra - Flashback, not just for developers

ILOUG 2019 - 25 years of hints and tips
ILOUG 2019 - 25 years of hints and tipsILOUG 2019 - 25 years of hints and tips
ILOUG 2019 - 25 years of hints and tips
Connor McDonald
 
ITOUG 2019 - 18c, 19c features
ITOUG 2019 - 18c, 19c featuresITOUG 2019 - 18c, 19c features
ITOUG 2019 - 18c, 19c features
Connor McDonald
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizer
Connor McDonald
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne
Connor McDonald
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matching
Connor McDonald
 
ILOUG 2019 - 18c/19c features
ILOUG 2019 - 18c/19c featuresILOUG 2019 - 18c/19c features
ILOUG 2019 - 18c/19c features
Connor McDonald
 
Flashback features in Oracle - UKOUG 2017
Flashback features in Oracle - UKOUG 2017Flashback features in Oracle - UKOUG 2017
Flashback features in Oracle - UKOUG 2017
Connor McDonald
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
Connor McDonald
 
Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019
Connor McDonald
 
Melbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsMelbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and Tips
Connor McDonald
 
OpenWorld 2018 - 20 years of hints and tips
OpenWorld 2018 - 20 years of hints and tipsOpenWorld 2018 - 20 years of hints and tips
OpenWorld 2018 - 20 years of hints and tips
Connor McDonald
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
Connor McDonald
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featues
Connor McDonald
 
Perth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c featuresPerth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c features
Connor McDonald
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19c
Connor McDonald
 
OpenWorld 2018 - Pagination
OpenWorld 2018 - PaginationOpenWorld 2018 - Pagination
OpenWorld 2018 - Pagination
Connor McDonald
 
Troubleshooting Ecommerce Performance
 Troubleshooting Ecommerce Performance Troubleshooting Ecommerce Performance
Troubleshooting Ecommerce Performance
Diego Cardozo
 
OpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 minsOpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 mins
Connor McDonald
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
Connor McDonald
 
Oracle APEX 기초 워크샵 - 실습 가이드 문서: Part 2 (2/2)
Oracle APEX 기초 워크샵 - 실습 가이드 문서:  Part 2 (2/2)Oracle APEX 기초 워크샵 - 실습 가이드 문서:  Part 2 (2/2)
Oracle APEX 기초 워크샵 - 실습 가이드 문서: Part 2 (2/2)
Taewan Kim
 

Similar to OG Yatra - Flashback, not just for developers (20)

ILOUG 2019 - 25 years of hints and tips
ILOUG 2019 - 25 years of hints and tipsILOUG 2019 - 25 years of hints and tips
ILOUG 2019 - 25 years of hints and tips
 
ITOUG 2019 - 18c, 19c features
ITOUG 2019 - 18c, 19c featuresITOUG 2019 - 18c, 19c features
ITOUG 2019 - 18c, 19c features
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizer
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matching
 
ILOUG 2019 - 18c/19c features
ILOUG 2019 - 18c/19c featuresILOUG 2019 - 18c/19c features
ILOUG 2019 - 18c/19c features
 
Flashback features in Oracle - UKOUG 2017
Flashback features in Oracle - UKOUG 2017Flashback features in Oracle - UKOUG 2017
Flashback features in Oracle - UKOUG 2017
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
 
Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019
 
Melbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsMelbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and Tips
 
OpenWorld 2018 - 20 years of hints and tips
OpenWorld 2018 - 20 years of hints and tipsOpenWorld 2018 - 20 years of hints and tips
OpenWorld 2018 - 20 years of hints and tips
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featues
 
Perth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c featuresPerth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c features
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19c
 
OpenWorld 2018 - Pagination
OpenWorld 2018 - PaginationOpenWorld 2018 - Pagination
OpenWorld 2018 - Pagination
 
Troubleshooting Ecommerce Performance
 Troubleshooting Ecommerce Performance Troubleshooting Ecommerce Performance
Troubleshooting Ecommerce Performance
 
OpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 minsOpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 mins
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
 
Oracle APEX 기초 워크샵 - 실습 가이드 문서: Part 2 (2/2)
Oracle APEX 기초 워크샵 - 실습 가이드 문서:  Part 2 (2/2)Oracle APEX 기초 워크샵 - 실습 가이드 문서:  Part 2 (2/2)
Oracle APEX 기초 워크샵 - 실습 가이드 문서: Part 2 (2/2)
 

More from Connor McDonald

Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
Connor McDonald
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
Connor McDonald
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
Connor McDonald
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tips
Connor McDonald
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
Connor McDonald
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL features
Connor McDonald
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomous
Connor McDonald
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applications
Connor McDonald
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
Connor McDonald
 
Latin America Tour 2019 - slow data and sql processing
Latin America Tour 2019  - slow data and sql processingLatin America Tour 2019  - slow data and sql processing
Latin America Tour 2019 - slow data and sql processing
Connor McDonald
 
ANSI vs Oracle language
ANSI vs Oracle languageANSI vs Oracle language
ANSI vs Oracle language
Connor McDonald
 
Kscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processingKscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processing
Connor McDonald
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
Connor McDonald
 
APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101
Connor McDonald
 
APEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLAPEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQL
Connor McDonald
 
APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application development
Connor McDonald
 

More from Connor McDonald (16)

Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tips
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL features
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomous
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applications
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
 
Latin America Tour 2019 - slow data and sql processing
Latin America Tour 2019  - slow data and sql processingLatin America Tour 2019  - slow data and sql processing
Latin America Tour 2019 - slow data and sql processing
 
ANSI vs Oracle language
ANSI vs Oracle languageANSI vs Oracle language
ANSI vs Oracle language
 
Kscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processingKscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processing
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
 
APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101
 
APEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLAPEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQL
 
APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application development
 

Recently uploaded

Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 

Recently uploaded (20)

Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 

OG Yatra - Flashback, not just for developers

  • 1. 7/22/2019 1 Flashback - the forgotten feature Connor McDonald Database Advocate Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 2 1 2
  • 2. 7/22/2019 2 Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 3 Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Stuff 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 rants and raves on tech and the world :-) 3 4
  • 3. 7/22/2019 3 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 © 2018, Oracle and/or its affiliates. All rights reserved. | In Memoriam 5 6
  • 4. 7/22/2019 4 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 7 8
  • 5. 7/22/2019 5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback 9 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com several technologies 10 9 10
  • 6. 7/22/2019 6 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 12 11 12
  • 7. 7/22/2019 7 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com controversy 13 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com you have always... 14 13 14
  • 8. 7/22/2019 8 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com .. been using flashback query 15 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com revision 16 15 16
  • 9. 7/22/2019 9 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 ? 17 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com we remember stuff 18 17 18
  • 10. 7/22/2019 10 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; 21 20 21
  • 11. 7/22/2019 11 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 stuff for queries! (Oracle version 4) 24 23 24
  • 12. 7/22/2019 12 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com read consistency 25 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 25 26
  • 13. 7/22/2019 13 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com system change number 27 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 ! 28 27 28
  • 14. 7/22/2019 14 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com every query = locked at a SCN 29 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 30 go back even further.... 29 30
  • 15. 7/22/2019 15 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback query = choose SCN 31 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com v9 32 31 32
  • 16. 7/22/2019 16 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 33 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 34 33 34
  • 17. 7/22/2019 17 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com a little less geeky 35 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 36 35 36
  • 18. 7/22/2019 18 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com smon_scn_time 37 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com smon_scn_time ??? 38 37 38
  • 19. 7/22/2019 19 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com obsolete* 39 more later on this 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 40 39 40
  • 20. 7/22/2019 20 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-FEB-19 09.12.48.000000000 PM 41 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 3 seconds 42 41 42
  • 21. 7/22/2019 21 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-FEB-19 05.47.47.000000000 PM 28-FEB-19 05.47.47.000000000 PM 28-FEB-19 05.47.44.000000000 PM 28-FEB-19 05.47.41.000000000 PM 28-FEB-19 05.47.37.000000000 PM 28-FEB-19 05.47.34.000000000 PM 28-FEB-19 05.47.31.000000000 PM 28-FEB-19 05.47.28.000000000 PM 28-FEB-19 05.47.25.000000000 PM 43 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com use in "normal" queries 44 43 44
  • 22. 7/22/2019 22 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-FEB-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 45 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "What's in it for me?" 46 45 46
  • 23. 7/22/2019 23 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 1) unit testing 47 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-FEB-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 48 47 48
  • 24. 7/22/2019 24 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 2) not just your data 49 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. 50 49 50
  • 25. 7/22/2019 25 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 3) functional diagnosis 51 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 ? 51 52
  • 26. 7/22/2019 26 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback row versions 53 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 54 53 54
  • 27. 7/22/2019 27 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 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 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-SEP-18 11.53.45 PM 0200100060040000 U 10 MONEY GRABBERS 03-SEP-18 11.53.36 PM 0600050065040000 U 10 FINANCE 03-SEP-18 11.53.24 PM 09000D001D050000 U 10 BEAN COUNTERS 03-SEP-18 11.53.12 PM 01001A00EA030000 U 10 ACCOUNTING 56 55 56
  • 28. 7/22/2019 28 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com get the lot ... 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 VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE; DEPTNO DNAME VERSIONS_STARTTIME VERSIONS_XID V ---------- -------------- ------------------------ ---------------- - 50 UNKNOWN 03-SEP-18 11.08.15 PM 04000700EA030000 U 30 UNKNOWN 03-SEP-18 11.08.15 PM 04000700EA030000 U 20 NERDS 03-SEP-18 11.07.57 PM 090016001D050000 U 20 R&D 03-SEP-18 11.07.48 PM 05000B0074040000 U ... 57 58
  • 29. 7/22/2019 29 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com grant flashback to ... 59 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com session level 60 59 60
  • 30. 7/22/2019 30 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com dbms_flashback.enable_at_time(systimestamp-1); 61 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 62 61 62
  • 31. 7/22/2019 31 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 63 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com just how far ? 64 63 64
  • 32. 7/22/2019 32 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 66 65 66
  • 33. 7/22/2019 33 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 67 ~ 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 68 67 68
  • 34. 7/22/2019 34 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com much much further flashback data archive Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "no" spanning DDL 70 better each version 69 70
  • 35. 7/22/2019 35 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com rewind the data, not time 71 charactersets, NLS etc Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback transaction 72 71 72
  • 36. 7/22/2019 36 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-SEP-18 11.08.15 PM 04000700EA030000 U 30 UNKNOWN 03-SEP-18 11.08.15 PM 04000700EA030000 U 20 NERDS 03-SEP-18 11.07.57 PM 090016001D050000 U 20 R&D 03-SEP-18 11.07.48 PM 05000B0074040000 U ... Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com XID ? 74 73 74
  • 37. 7/22/2019 37 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 ... 75 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 76 75 76
  • 38. 7/22/2019 38 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) 77 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'; 78 77 78
  • 39. 7/22/2019 39 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com be careful 79 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 80 79 80
  • 40. 7/22/2019 40 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com do not query without predicates ... 81 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com do not forget hextoraw 82 81 82
  • 41. 7/22/2019 41 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) | ----------------------------------------------------- 84 83 84
  • 42. 7/22/2019 42 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 | -------------------------------------- 85 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com UNDO_SQL 86 85 86
  • 43. 7/22/2019 43 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com rollback committed transaction 87 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "What's in it for me?" 88 87 88
  • 44. 7/22/2019 44 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com three words 89 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com delete uh-oh... commit 89 90
  • 45. 7/22/2019 45 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 91 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com undo a committed transaction 92 91 92
  • 46. 7/22/2019 46 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback transaction 93 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' 94 93 94
  • 47. 7/22/2019 47 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 95 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. 96 95 96
  • 48. 7/22/2019 48 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 97 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 ? 98 97 98
  • 49. 7/22/2019 49 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 100 99 100
  • 50. 7/22/2019 50 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> 101 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 102 101 102
  • 51. 7/22/2019 51 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com some typical restrictions 103 ddl, old lobs, xml Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback drop 104 103 104
  • 52. 7/22/2019 52 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com delete uh-oh... commit Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback transaction 106 105 106
  • 53. 7/22/2019 53 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com three words two 107 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com drop uh-oh... 107 108
  • 54. 7/22/2019 54 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 109 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 109 110
  • 55. 7/22/2019 55 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com hard place You are here Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "undrop" 112 111 112
  • 56. 7/22/2019 56 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com not cool enough 113 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback table to before drop 114 113 114
  • 57. 7/22/2019 57 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 116 115 116
  • 58. 7/22/2019 58 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 117 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> show RECYCLEBIN 118 117 118
  • 59. 7/22/2019 59 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com indexes / constraints / triggers ... all renamed Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> flashback table EMP to before drop; Flashback complete. 120 119 120
  • 60. 7/22/2019 60 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. 121 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com indexes / constraints / triggers ... not renamed back 121 122
  • 61. 7/22/2019 61 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com how long ? 123 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 1 second... ...10 years 124 123 124
  • 62. 7/22/2019 62 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; 125 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com no untruncate 126 125 126
  • 63. 7/22/2019 63 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback table 127 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 127 128
  • 64. 7/22/2019 64 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback table 129 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-06-03 12:05:00') 130 129 130
  • 65. 7/22/2019 65 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "undrop" 131 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "What's in it for me?" 132 131 132
  • 66. 7/22/2019 66 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com repeatable tests without cleanup scripts 133 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 133 134
  • 67. 7/22/2019 67 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-06-03 12:05:00') 3 ENABLE TRIGGERS; 135 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com rowid's change ... enable row movement 136 135 136
  • 68. 7/22/2019 68 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com indexes existence unaffected 137 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com single transaction 138 ... multiple tables allowed 137 138
  • 69. 7/22/2019 69 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com tables locked 139 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com R.I must still be valid 140 139 140
  • 70. 7/22/2019 70 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com statistics unchanged 141 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com most DDL is a flashback boundary 142 141 142
  • 71. 7/22/2019 71 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 143 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com each release gets better 144 143 144
  • 72. 7/22/2019 72 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 145 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 146 145 146
  • 73. 7/22/2019 73 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback database 147 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 147 148
  • 74. 7/22/2019 74 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 150 149 150
  • 75. 7/22/2019 75 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. 152 151 152
  • 76. 7/22/2019 76 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 153 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' 154 153 154
  • 77. 7/22/2019 77 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; 155 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com what does it cost ? 156 155 156
  • 78. 7/22/2019 78 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 157 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com a good compromise 161 157 161
  • 79. 7/22/2019 79 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com guaranteed restore points 162 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback logging "optional" 163 162 163
  • 80. 7/22/2019 80 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "What's in it for me?" 165 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 1) safer deployment 166 165 166
  • 81. 7/22/2019 81 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com scenario: "My New Application" 167 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 9:00 9:40 9:45 SQL> FLASHBACK DATABASE... 168 SQL> alter table ACCOUNTS ... 167 168
  • 82. 7/22/2019 82 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 2) repeatable end to end testing 169 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 170 169 170
  • 83. 7/22/2019 83 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 12.2+ 171 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback pluggable database 172 171 172
  • 84. 7/22/2019 84 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 3) production data for developers 173 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "hidden" example 174 173 174
  • 85. 7/22/2019 85 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com Data Guard 175 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 176 5:00am 11:30pm standby recovery convert to snapshot revert to physical 175 176
  • 86. 7/22/2019 86 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback data archive 181 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com less flashback, more archive 182 181 182
  • 87. 7/22/2019 87 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. 184 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] 185 184 185
  • 88. 7/22/2019 88 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 | -------------------------------------------------- 186 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 | -------------------------------------------------- 187 186 187
  • 89. 7/22/2019 89 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 3 days later... 188 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 | ------------------------------------------------------------------189 188 189
  • 90. 7/22/2019 90 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 190 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" 191 190 191
  • 91. 7/22/2019 91 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 193 note 192 193
  • 92. 7/22/2019 92 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 194 "The table does not use any of these Flashback Data Archive reserved words as column names: • STARTSCN • ENDSCN • RID • XID • OP • OPERATION" Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "What's in it for me?" 195 194 195
  • 93. 7/22/2019 93 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..." 196 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 197 why talk about it ? 196 197
  • 94. 7/22/2019 94 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 198 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 199 every historical version... 198 199
  • 95. 7/22/2019 95 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 200 ... of every row Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 201 sound familiar ? 200 201
  • 96. 7/22/2019 96 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 202 audit history Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 203 we've all done it 202 203
  • 97. 7/22/2019 97 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 204 SQL> desc T Name Null? Type ------------------------ -------- ------------- OWNER NOT NULL VARCHAR2(30) OBJECT_NAME NOT NULL VARCHAR2(30) SQL> desc T_AUDIT Name Null? Type ------------------------ -------- -------------- AUDIT_DATE DATE AUDIT_ACTION CHAR(1) OWNER NOT NULL VARCHAR2(30) OBJECT_NAME NOT NULL VARCHAR2(30) Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 205 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; 204 205
  • 98. 7/22/2019 98 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 206 works but slow... Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 207 SQL> insert into T 2 select owner, object_name 3 from all_objects 4 where rownum <= 10000; 10000 rows created. insert into T select owner, object_name from all_objects where rownum <= 10000 call count cpu elapsed disk query current rows ------- ------ ------- ---------- -------- --------- ---------- ---------- Parse 1 0.01 0.00 0 0 0 0 Execute 1 3.10 3.05 88 123 10642 10000 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ ------- ---------- -------- --------- ---------- ---------- total 2 3.12 3.06 88 123 10642 10000 INSERT INTO T_AUDIT VALUES (SYSDATE ,:B3 ,:B1 ,:B2 ) call count cpu elapsed disk query current rows ------- ------ ------- ---------- -------- --------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 10000 0.79 0.97 2 109 10845 10000 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ ------- ---------- -------- --------- ---------- ---------- total 10001 0.79 0.97 2 109 10845 10000 206 207
  • 99. 7/22/2019 99 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com a better, faster, robust version ... 208 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback data archive 209 208 209
  • 100. 7/22/2019 100 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 210 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com so why didn't we ? 211 210 211
  • 101. 7/22/2019 101 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com reason 1 212 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "yeah...but who ? where ? how ?" 213 212 213
  • 102. 7/22/2019 102 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> alter table EMP add UPDATED_BY varchar2(10); Table altered. SQL> alter table EMP add UPDATED_PGM varchar2(10); Table altered. [etc] 214 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com reason 2 215 214 215
  • 103. 7/22/2019 103 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 217 216 217
  • 104. 7/22/2019 104 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 12c+ ... more options 218 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 1) context extension 219 218 219
  • 105. 7/22/2019 105 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> begin 2 dbms_flashback_archive.set_context_level( 3 level=> 'ALL'); 4 end; PL/SQL procedure successfully completed. 220 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> update EMP 2 set sal = sal*10 3 where empno = 7499; 1 row updated. SQL> commit; 221 220 221
  • 106. 7/22/2019 106 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select XID from SYS_FBA_HIST_510592; XID ---------------- 09000B00C7080000 222 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> set serverout on SQL> begin 2 dbms_output.put_line( 3 dbms_flashback_archive.get_sys_context ( 4 '09000B00C7080000', 'USERENV', 'SESSION_USER')); 5 6 dbms_output.put_line( 7 dbms_flashback_archive.get_sys_context ( 8 '09000B00C7080000', 'USERENV', 'HOST')); 9 10 dbms_output.put_line( 11 dbms_flashback_archive.get_sys_context ( 12 '09000B00C7080000', 'USERENV', 'MODULE')); 13 end; 14 / SCOTT WORKGROUPXPS SQL*Plus 223 222 223
  • 107. 7/22/2019 107 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com ...and a few other things :-) 224 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> desc SYS.SYS_FBA_CONTEXT_AUD Name Null? Type ------------------------- -------- ------------------ XID RAW(8) ACTION VARCHAR2(256) AUTHENTICATED_IDENTITY VARCHAR2(256) CLIENT_IDENTIFIER VARCHAR2(256) CLIENT_INFO VARCHAR2(256) CURRENT_EDITION_NAME VARCHAR2(256) CURRENT_SCHEMA VARCHAR2(256) CURRENT_USER VARCHAR2(256) DATABASE_ROLE VARCHAR2(256) DB_NAME VARCHAR2(256) GLOBAL_UID VARCHAR2(256) HOST VARCHAR2(256) IDENTIFICATION_TYPE VARCHAR2(256) INSTANCE_NAME VARCHAR2(256) IP_ADDRESS VARCHAR2(256) MODULE VARCHAR2(256) OS_USER VARCHAR2(256) 225 224 225
  • 108. 7/22/2019 108 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> @pt "select * from SYS.SYS_FBA_CONTEXT_AUD where xid = '09000B00C7080000'" XID : 09000B00C7080000 AUTHENTICATED_IDENTITY : scott CLIENT_IDENTIFIER : CLIENT_INFO : CURRENT_EDITION_NAME : ORA$BASE CURRENT_SCHEMA : SYS CURRENT_USER : SYS DATABASE_ROLE : PRIMARY DB_NAME : np12 HOST : WORKGROUPXPS IDENTIFICATION_TYPE : LOCAL INSTANCE_NAME : np12 MODULE : SQL*Plus OS_USER : xpshamcdc SERVER_HOST : xps ... 226 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select empno, ename, job, sal, comm, 2 VERSIONS_XID 3 from EMP 4 versions between timestamp 5 timestamp '2019-02-11 20:12:00' and systimestamp 6 order by empno; EMPNO ENAME JOB SAL COMM VERSIONS_XID ---------- ---------- --------- ---------- ---------- ---------------- 7369 SMITH CLERK 806 7369 SMITH SALES 8060 1000 09001C00E04A0000 7499 ALLEN CLERK 16060 300000000 0A000A0024080000 7499 ALLEN SALESMAN 16060 300000000 09000B00C7080000 7499 ALLEN SALESMAN 1606 300000000 7521 WARD SALESMAN 1256 500000000 227 226 227
  • 109. 7/22/2019 109 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> select ... 2 from 3 ( select 4 empno, ename, job, 5 sal, comm, VERSIONS_XID 6 from EMP 7 versions between timestamp 8 timestamp '2019-02-11 20:12:00' and 9 systimestamp 10 ) e, SYS.SYS_FBA_CONTEXT_AUD a 11 where e.VERSIONS_XID = a.XID; 228 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 2) price... 230 228 230
  • 110. 7/22/2019 110 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com flashback data archive is now … 231 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com 232 231 232
  • 111. 7/22/2019 111 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com not a typo 233 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com basic versus advanced 234 233 234
  • 112. 7/22/2019 112 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com choose your cost compression 235 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com so think about FDA 236 235 236
  • 113. 7/22/2019 113 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com secure read only 237 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com efficient fdba 238 237 238
  • 114. 7/22/2019 114 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com all of your history... 239 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com ... all of your audit 240 239 240
  • 115. 7/22/2019 115 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com "Where were you in 2004 ?!?!?" 241 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com dbms_flashback_archive.import_history 242 241 242
  • 116. 7/22/2019 116 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com be careful ... silent errors 243 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com SQL> ALTER TABLE EMP FLASHBACK ARCHIVE LONGTERM; Table altered. Flashback Archive: Error ORA-1950 in SQL create table "SCOTT".SYS_FBA_DDL_COLMAP_91938 (STARTSCN NUMBER, ENDSCN NUMBER... Flashback Archive: Error ORA-942 in SQL insert into "SCOTT".SYS_FBA_DDL_COLMAP_91938 (ENDSCN, COLUMN_NAME, TYPE, ... 244 243 244
  • 117. 7/22/2019 117 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 wrap up 258 248 258
  • 118. 7/22/2019 118 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 260 259 260
  • 119. 7/22/2019 119 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com all cool for modern development 261 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dconnor-mcdonald.com That's a wrap! youtube bit.ly/youtube-connor blog bit.ly/blog-connor twitter bit.ly/twitter-connor 261 262