SlideShare uma empresa Scribd logo
1 de 100
Baixar para ler offline
9/19/2019
1
Copyright © 2019 Oracle and/or its affiliates.
2
Connor McDonald
1
2
9/19/2019
2
3 3
4 4
3
4
9/19/2019
3
5 5
6
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 :-)
5
6
9/19/2019
4
7
etc...
facebook bit.ly/facebook-connor
linkedin bit.ly/linkedin-connor
instagram bit.ly/instagram-connor
slideshare bit.ly/slideshare-connor
8
7
8
9/19/2019
5
9 9https://asktom.oracle.com
10 10https://asktom.oracle.com/officehours
9
10
9/19/2019
6
Flashback - not just for DBAs
Database Advocate
Connor McDonald
14
flashback
11
14
9/19/2019
7
15
several different technologies
16
flashback query
flashback table
flashback drop
flashback database
flashback transaction
flashback data archive
15
16
9/19/2019
8
flashback query
18
controversy
17
18
9/19/2019
9
19
you have always
20
been using flashback query
19
20
9/19/2019
10
21
revision
22
SQL> update EMP
2 set SAL = SAL * 1.10
3 /
14 rows updated.
SQL> rollback;
Rollback complete.
how ?
22
21
22
9/19/2019
11
23
we remember stuff
24
SQL> update EMP
2 set SAL = SAL * 1.10
3 where ename = 'SMITH'
undo header
smith $1,0001
block 2754
jones $9002
brown $1,5003
wells $2,0004
wilson $1,0005
block 2754, row 1,
sal $1000
uba 5 5
$1,100
uba 5.1
23
24
9/19/2019
12
25
SQL> rollback;
25
26
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
uba 5
5
$1,100
uba 5.1
25
26
9/19/2019
13
27
we can use this stuff for queries!
(Oracle version 4)
27
28
read consistency
28
27
28
9/19/2019
14
29
select * from emp
where hiredate > '01/01/2004'
update emp set ename = 'SUE'
where ename = 'JOHN';
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
30
system change number
29
30
9/19/2019
15
31
Session 1
Request
Block 3217,
SCN 4567192
Block 3217,
SCN 4567234
"SUE"
Block 3217,
SCN 4567003,
change SUE => JOHN
undo segment block(s)
No good..too new
take a copy of the block
Locate
apply undo
Block 3217,
SCN 4567234
" SUE"
Block 3217,
SCN 4567234
" SUE"
Block 3217,
SCN 4567003
" JOHN"
Block 3217,
SCN 4567003
"JOHN"
Session 2
update emp
set ename = 'SUE'
where ename = 'JOHN'
commit;
Done !
32
stress: vast simplification
in-memory undo
throwaway undo
slots
expiry
wrap#
31
32
9/19/2019
16
33
every query = locked at a SCN
34
go back further....
33
34
9/19/2019
17
35
flashback query = choose the SCN
36
v9
circa 2001
35
36
9/19/2019
18
37
SQL> select * from DEPT;
DEPTNO DNAME LOC
---------- -------------- -------------
10 UNKNOWN NEW YORK
20 UNKNOWN DALLAS
30 UNKNOWN CHICAGO
40 UNKNOWN BOSTON
38
SQL> select * from DEPT AS OF SCN 995401;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
37
38
9/19/2019
19
39
less geeky
40
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
39
40
9/19/2019
20
44
SQL> select TIMESTAMP_TO_SCN(systimestamp)
2 from DUAL;
TIMESTAMP_TO_SCN(SYSTIMESTAMP)
------------------------------
998332
SQL> select SCN_TO_TIMESTAMP(998314) from DUAL;
SCN_TO_TIMESTAMP(998314)
-----------------------------------------------
16-SEP-19 09.12.48.000000000 PM
45
3 seconds
44
45
9/19/2019
21
46
SQL> select scn_to_timestamp(2409511-rownum)
2 from dual
3 connect by level <= 50;
SCN_TO_TIMESTAMP(2409511-ROWNUM)
---------------------------------------------
16-SEP-19 05.47.47.000000000 PM
16-SEP-19 05.47.47.000000000 PM
16-SEP-19 05.47.44.000000000 PM
16-SEP-19 05.47.41.000000000 PM
16-SEP-19 05.47.37.000000000 PM
16-SEP-19 05.47.34.000000000 PM
16-SEP-19 05.47.31.000000000 PM
16-SEP-19 05.47.28.000000000 PM
16-SEP-19 05.47.25.000000000 PM
47
use in "normal" queries
46
47
9/19/2019
22
48
SQL> select e.empno, e.ename, d.dname
2 from emp e,
3 dept AS OF TIMESTAMP '16-SEP-19' 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
"What is in it for me?"
48
49
9/19/2019
23
50
1) unit testing
before vs after
51
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 '16-SEP-19 11.51.02 PM' d2
8 on d1.deptno = d2.deptno;
ACTION DEPTNO DEPTNO DNAME LOC
------ ---------- ---------- -------------- ----------
10 10 ACCOUNTING NEW YORK
20 20 RESEARCH DALLAS
30 30 SALES CHICAGO
DELETE 40
INSERT 50 MARKETING PERTH
50
51
9/19/2019
24
52
2) not just your data
53
SQL> drop procedure debug_msg;
Procedure dropped.
SQL> connect / as sysdba
Connected.
SQL> select text
2 from dba_source
3 as of timestamp systimestamp - interval '5' minute
4 where name='DEBUG_MSG' order by line;
TEXT
---------------------------------------------------------------------
procedure debug_msg(m varchar2) is
begin
dbms_output.put_line(m);
dbms_application_info.set_client_info(m);
end;
5 rows selected.
52
53
9/19/2019
25
54
3) functionality diagnosis
55
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 ?
54
55
9/19/2019
26
56
flashback row versions
57
SQL> SELECT deptno, dname
2 FROM dept
3 VERSIONS BETWEEN
4 TIMESTAMP SYSTIMESTAMP –
5 INTERVAL '20:00' MINUTE TO SECOND
6 AND SYSTIMESTAMP
7 WHERE deptno = 10;
DEPTNO DNAME
---------- --------------
10 ACCOUNTING
10 MONEY GRABBERS
10 FINANCE
10 BEAN COUNTERS
10 UNKNOWN
1 row
5 versions
56
57
9/19/2019
27
58
versions_starttime
versions_startscn
versions_endtime
versions_endscn
versions_xid
versions_operation
59
SQL> SELECT deptno, dname,
2 VERSIONS_STARTTIME
3 ,VERSIONS_XID
4 ,VERSIONS_OPERATION
5 FROM dept
6 VERSIONS BETWEEN TIMESTAMP
7 SYSTIMESTAMP - INTERVAL '20:00' MINUTE TO SECOND
8 AND SYSTIMESTAMP
9 WHERE deptno = 10;
DEPTNO DNAME VERSIONS_STARTTIME VERSIONS_XID V
--------- -------------- ---------------------- ---------------- -
10 UNKNOWN 16-SEP-19 11.53.45 PM 0200100060040000 U
10 MONEY GRABBERS 16-SEP-19 11.53.36 PM 0600050065040000 U
10 FINANCE 16-SEP-19 11.53.24 PM 09000D001D050000 U
10 BEAN COUNTERS 16-SEP-19 11.53.12 PM 01001A00EA030000 U
10 ACCOUNTING
58
59
9/19/2019
28
60
get the lot ...
61
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 16-SEP-19 11.08.15 PM 04000700EA030000 U
30 UNKNOWN 16-SEP-19 11.08.15 PM 04000700EA030000 U
20 NERDS 16-SEP-19 11.07.57 PM 090016001D050000 U
20 R&D 16-SEP-19 11.07.48 PM 05000B0074040000 U
...
60
61
9/19/2019
29
62
it might be expensive
63
grant flashback to ...
62
63
9/19/2019
30
64
session level
65
dbms_flashback.enable_at_time(systimestamp-1/24);
select * from emp;
select * from dept;
etc etc
64
65
9/19/2019
31
68
just how far ?
69
undo_retention
68
69
9/19/2019
32
70
SQL> show parameter undo_retention
NAME TYPE VALUE
------------------------------ ----------- --------
undo_retention integer 900
~
71
SQL> desc v$undostat
Name Null? Type
----------------------------- -------- -----------
BEGIN_TIME DATE
END_TIME DATE
...
...
TUNED_UNDORETENTION NUMBER
CON_ID NUMBER
70
71
9/19/2019
33
73
much much further
flashback data archive
flashback transaction
73
76
9/19/2019
34
77
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 16-SEP-19 11.08.15 PM 04000700EA030000 U
30 UNKNOWN 16-SEP-19 11.08.15 PM 04000700EA030000 U
20 NERDS 16-SEP-19 11.07.57 PM 090016001D050000 U
20 R&D 16-SEP-19 11.07.48 PM 05000B0074040000 U
...
78
XID ?
77
78
9/19/2019
35
79
SQL> desc V$TRANSACTION
Name Null? Type
----------------------------- -------- -------
XIDUSN NUMBER
XIDSLOT NUMBER
XIDSQN NUMBER
...
80
SQL> select
2 XIDUSN, XIDSLOT, XIDSQN
3 from v$transaction
XIDUSN XIDSLOT XIDSQN
---------- ---------- ----------
1 31 674
SQL> select versions_xid from ...
VERSIONS_XID
-------------------
01 001F 00A202 0000
79
80
9/19/2019
36
82
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)
83
SQL> update dept
2 set DNAME = 'FINANCE'
2 where deptno = 10;
1 row updated.
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';
82
83
9/19/2019
37
84
be careful
85
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
84
85
9/19/2019
38
86
do not query without predicates ...
SQL> select xid, undo_sql
2 from flashback_transaction_query
3 where xid = hextoraw('09000d001d050000');
87
do not forget hextoraw
SQL> select xid, undo_sql
2 from flashback_transaction_query
3 where xid = hextoraw('09000d001d050000');
86
87
9/19/2019
39
88
89
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) |
-----------------------------------------------------
88
89
9/19/2019
40
90
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 |
--------------------------------------
91
UNDO_SQL
90
91
9/19/2019
41
92
rollback committed transaction
"What is in it for me?"
92
93
9/19/2019
42
94
1) accidents
95
three words
94
95
9/19/2019
43
96
delete
uh-oh...
commit
9797
96
97
9/19/2019
44
101
flashback transaction
102
SQL> delete from DEPT 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
101
102
9/19/2019
45
103
SQL> BEGIN
2 DBMS_FLASHBACK.TRANSACTION_BACKOUT(
3 numtxns=> 1,
4 xids => sys.xid_array('080017006C040000')
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
104
104
103
104
9/19/2019
46
105
SQL> ALTER DATABASE ADD
2 SUPPLEMENTAL LOG DATA
3 (PRIMARY KEY) COLUMNS;
Database altered.
106
SQL> delete from DEPT 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
105
106
9/19/2019
47
107
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?
108
KEEP CALM
AND
DON'T PANIC
107
108
9/19/2019
48
109
SQL> SELECT COMPENSATING_XID
2 FROM DBA_FLASHBACK_TXN_STATE
3 WHERE xid = '080017006C040000';
COMPENSATING_XID
----------------
03001C0072040000
110
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>
109
110
9/19/2019
49
111
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
112
2) unit tests
111
112
9/19/2019
50
113
run test ... capture XID
114
commit... validate... undo transaction
113
114
9/19/2019
51
flashback drop
116
delete
uh-oh...
commit
115
116
9/19/2019
52
117
flashback transaction
118
three words
two
117
118
9/19/2019
53
119
drop
uh-oh...
120
120
119
120
9/19/2019
54
121
SQL> desc EMP
ERROR:
ORA-04043: object EMP does not exist
122
"undrop"
121
122
9/19/2019
55
123
not cool enough
124
flashback table to before drop
123
124
9/19/2019
56
125
126
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
125
126
9/19/2019
57
127
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
128
SQL> show RECYCLEBIN
127
128
9/19/2019
58
130
SQL> flashback table EMP to before drop;
Flashback complete.
131
SQL> flashback table EMP to before drop
2 rename to OLD_EMP;
Flashback complete.
130
131
9/19/2019
59
133
how long ?
134
133
134
9/19/2019
60
135
SQL> PURGE RECYCLEBIN;
SQL> PURGE DBA_RECYCLEBIN;
SQL> PURGE TABLE emp;
SQL> PURGE TABLE "BIN$xyWe0+q+SniItJ0pn/u54A==$0";
SQL> PURGE TABLESPACE user1;
SQL> PURGE TABLESPACE user1 USER fred;
SQL> PURGE INDEX "BIN$FTX34MN88J7==$0";
136
no untruncate
135
136
9/19/2019
61
flashback table
138
137
138
9/19/2019
62
139
flashback table
140
SQL> FLASHBACK TABLE DEPT
2 TO TIMESTAMP TIMESTAMP '2019-09-16 12:05:00'
139
140
9/19/2019
63
141
"undrop"
"What is in it for me?"
141
142
9/19/2019
64
143
repeatable tests without cleanup scripts
144
test ... commit ... flashback to start point
143
144
9/19/2019
65
145
deletes modified rows since SCN
inserts fresh rows as of SCN
... busy
149
single transaction
... multiple tables allowed
145
149
9/19/2019
66
150
tables locked
151
R.I must still be valid
150
151
9/19/2019
67
154
most DDL is a flashback boundary
155
SQL> flashback table DEPT to scn ...;
ORA-01466: unable to read data - table definition has changed
154
155
9/19/2019
68
156
each release gets better
157
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
156
157
9/19/2019
69
flashback database
160
159
160
9/19/2019
70
161
162
flashback database
161
162
9/19/2019
71
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
AUTHORISED
DATABASE
ADMINSTRATORS
ONLY !
164
SQL> alter database flashback on;
Database altered.
163
164
9/19/2019
72
165
data
changes
"new" blocks
to disk
changes
to disk
"old" blocks
to disk
redo fbdadbwr
166
SQL> FLASHBACK DATABASE TO '2:05PM'
165
166
9/19/2019
73
167
SQL> create restore point OK_SO_FAR;
...
SQL> flashback database to
2 restore point OK_SO_FAR;
168
what does it cost ?
167
168
9/19/2019
74
169
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
173
a good compromise
169
173
9/19/2019
75
174
guaranteed restore points
175
flashback logging "optional"
174
175
9/19/2019
76
"What is in it for me?"
177
1) safer deployment
176
177
9/19/2019
77
178
scenario: "My New Application"
179
9:00
9:40
9:45 SQL> FLASHBACK DATABASE...
SQL> alter table ACCOUNTS add ...
178
179
9/19/2019
78
180
2) repeatable end to end testing
181
181
180
181
9/19/2019
79
182
flashback pluggable database
183
3) production data for developers
182
183
9/19/2019
80
184
aka "hidden" flashback database
185
5:00am
11:30pm
standby recovery
convert to snapshot
revert to physical
184
185
9/19/2019
81
flashback data archive
191
less flashback, more archive
190
191
9/19/2019
82
193
SQL> CREATE FLASHBACK ARCHIVE longterm
2 TABLESPACE space_for_archive
3 RETENTION 1 YEAR;
Flashback archive created.
194
SQL> ALTER TABLE EMP FLASHBACK ARCHIVE LONGTERM;
Table altered.
[lots of DML on EMP]
193
194
9/19/2019
83
195
195
SQL> select * from EMP;
--------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
--------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 518 |
| 1 | TABLE ACCESS FULL| EMP | 14 | 518 |
--------------------------------------------------
196
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 |
--------------------------------------------------
195
196
9/19/2019
84
197
3 days later...
198
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 |
------------------------------------------------------------------
197
198
9/19/2019
85
199
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
200
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"
199
200
9/19/2019
86
201
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) )
"What is in it for me?"
201
204
9/19/2019
87
205
"I dont care what EMP looked like in June"
206206
why talk about it ?
205
206
9/19/2019
88
207207
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
208208
every historical version...
207
208
9/19/2019
89
209209
... of every row
210210
sound familiar ?
209
210
9/19/2019
90
211211
audit history
212212
we've all done it
211
212
9/19/2019
91
213213
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)
214214
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) :=
7 case when updating then 'U'
8 when deleting then 'D' else 'I' end;
9 begin
10 if updating or inserting then
11 insert into T_AUDIT
12 values (sysdate
13 ,v_action
14 ,:new.owner
15 ,:new.object_name);
16 else
17 insert into T_AUDIT
18 values (sysdate
19 ,v_action
20 ,:old.owner
21 ,:old.object_name);
22 end if;
23 end;
213
214
9/19/2019
92
217
a better, faster, robust version ...
218
flashback data archive
217
218
9/19/2019
93
219
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-09-16 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
220
so why didn't we ?
219
220
9/19/2019
94
225
226
separately licensed
225
226
9/19/2019
95
240
flashback data archive is now …
240
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 241
240
241
9/19/2019
96
242
not a typo
242
243
compression option
243
242
243
9/19/2019
97
266
wrap up
267
flashback query
flashback table
flashback drop
flashback database
flashback transaction
flashback data archive
266
267
9/19/2019
98
268
all cool for modern development
269
all included in EE
268
269
9/19/2019
99
270
hanging around ?
271
PL/SQL: Still the Best Data Access Language
Thursday, September 19, 12:15 PM - 01:00 PM,
Moscone South - Room 155A
270
271
9/19/2019
100
272
Thanks for attending !!!
youtube tinyurl.com/connortube
blog connor-mcdonald.com
twitter @connor_mc_d
272

Mais conteúdo relacionado

Mais procurados

Sg510 installation guide_(sgos_5.2.x)
Sg510 installation guide_(sgos_5.2.x)Sg510 installation guide_(sgos_5.2.x)
Sg510 installation guide_(sgos_5.2.x)Sultan AbuAlsondos
 
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 tipsConnor McDonald
 
Oracle trace data collection errors: the story about oceans, islands, and rivers
Oracle trace data collection errors: the story about oceans, islands, and riversOracle trace data collection errors: the story about oceans, islands, and rivers
Oracle trace data collection errors: the story about oceans, islands, and riversCary Millsap
 
Sangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL JediSangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL JediConnor McDonald
 
Most important "trick" of performance instrumentation
Most important "trick" of performance instrumentationMost important "trick" of performance instrumentation
Most important "trick" of performance instrumentationCary Millsap
 
Oracle12c For Developers
Oracle12c For DevelopersOracle12c For Developers
Oracle12c For DevelopersAlex Nuijten
 

Mais procurados (6)

Sg510 installation guide_(sgos_5.2.x)
Sg510 installation guide_(sgos_5.2.x)Sg510 installation guide_(sgos_5.2.x)
Sg510 installation guide_(sgos_5.2.x)
 
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
 
Oracle trace data collection errors: the story about oceans, islands, and rivers
Oracle trace data collection errors: the story about oceans, islands, and riversOracle trace data collection errors: the story about oceans, islands, and rivers
Oracle trace data collection errors: the story about oceans, islands, and rivers
 
Sangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL JediSangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL Jedi
 
Most important "trick" of performance instrumentation
Most important "trick" of performance instrumentationMost important "trick" of performance instrumentation
Most important "trick" of performance instrumentation
 
Oracle12c For Developers
Oracle12c For DevelopersOracle12c For Developers
Oracle12c For Developers
 

Semelhante a OOW19 - Flashback, not just for DBAs

APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne Connor McDonald
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesConnor McDonald
 
ILOUG 2019 - Flashback, the forgotten feature
ILOUG 2019 - Flashback, the forgotten featureILOUG 2019 - Flashback, the forgotten feature
ILOUG 2019 - Flashback, the forgotten featureConnor 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 tipsConnor McDonald
 
12c for Developers - Feb 2014
12c for Developers - Feb 201412c for Developers - Feb 2014
12c for Developers - Feb 2014Connor McDonald
 
Kscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAsKscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAsConnor McDonald
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application DevelopmentSaurabh K. Gupta
 
OpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersOpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersConnor McDonald
 
COBOL DB2 BATCH EXAMPLE-RPR6520
COBOL DB2 BATCH EXAMPLE-RPR6520COBOL DB2 BATCH EXAMPLE-RPR6520
COBOL DB2 BATCH EXAMPLE-RPR6520Jon Fortman
 
Cryptography for everyone
Cryptography for everyoneCryptography for everyone
Cryptography for everyoneArcBlock
 
Connor McDonald Partitioning
Connor McDonald PartitioningConnor McDonald Partitioning
Connor McDonald PartitioningInSync Conference
 
Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...
Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...
Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...Anne Nicolas
 
Kernel Recipes 2017: Performance Analysis with BPF
Kernel Recipes 2017: Performance Analysis with BPFKernel Recipes 2017: Performance Analysis with BPF
Kernel Recipes 2017: Performance Analysis with BPFBrendan Gregg
 

Semelhante a OOW19 - Flashback, not just for DBAs (20)

APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne
 
Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
 
Sql queries
Sql queriesSql queries
Sql queries
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
 
ILOUG 2019 - Flashback, the forgotten feature
ILOUG 2019 - Flashback, the forgotten featureILOUG 2019 - Flashback, the forgotten feature
ILOUG 2019 - Flashback, the forgotten feature
 
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
 
12c for Developers - Feb 2014
12c for Developers - Feb 201412c for Developers - Feb 2014
12c for Developers - Feb 2014
 
Kscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAsKscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAs
 
Oracle 11G- PLSQL
Oracle 11G- PLSQLOracle 11G- PLSQL
Oracle 11G- PLSQL
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application Development
 
Abap tips
Abap tipsAbap tips
Abap tips
 
OpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersOpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developers
 
COBOL DB2 BATCH EXAMPLE-RPR6520
COBOL DB2 BATCH EXAMPLE-RPR6520COBOL DB2 BATCH EXAMPLE-RPR6520
COBOL DB2 BATCH EXAMPLE-RPR6520
 
Sql2
Sql2Sql2
Sql2
 
Cryptography for everyone
Cryptography for everyoneCryptography for everyone
Cryptography for everyone
 
Connor McDonald Partitioning
Connor McDonald PartitioningConnor McDonald Partitioning
Connor McDonald Partitioning
 
Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...
Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...
Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...
 
Kernel Recipes 2017: Performance Analysis with BPF
Kernel Recipes 2017: Performance Analysis with BPFKernel Recipes 2017: Performance Analysis with BPF
Kernel Recipes 2017: Performance Analysis with BPF
 
BCMC4.pdf
BCMC4.pdfBCMC4.pdf
BCMC4.pdf
 
BCMC6 (2).pdf
BCMC6 (2).pdfBCMC6 (2).pdf
BCMC6 (2).pdf
 

Mais de Connor McDonald

Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestConnor McDonald
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQLConnor McDonald
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousConnor McDonald
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresConnor 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 autonomousConnor McDonald
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsConnor 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 featuesConnor 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 featuresConnor 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 processingConnor 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+ optimizerConnor McDonald
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsConnor 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 processingConnor McDonald
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAsConnor McDonald
 
APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101Connor 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 PLSQLConnor McDonald
 
APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentConnor McDonald
 

Mais de Connor McDonald (18)

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
 
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 - 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
 
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
 
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
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tips
 
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
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
 
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
 

Último

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 

Último (20)

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 

OOW19 - Flashback, not just for DBAs

  • 1. 9/19/2019 1 Copyright © 2019 Oracle and/or its affiliates. 2 Connor McDonald 1 2
  • 3. 9/19/2019 3 5 5 6 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 :-) 5 6
  • 4. 9/19/2019 4 7 etc... facebook bit.ly/facebook-connor linkedin bit.ly/linkedin-connor instagram bit.ly/instagram-connor slideshare bit.ly/slideshare-connor 8 7 8
  • 6. 9/19/2019 6 Flashback - not just for DBAs Database Advocate Connor McDonald 14 flashback 11 14
  • 7. 9/19/2019 7 15 several different technologies 16 flashback query flashback table flashback drop flashback database flashback transaction flashback data archive 15 16
  • 9. 9/19/2019 9 19 you have always 20 been using flashback query 19 20
  • 10. 9/19/2019 10 21 revision 22 SQL> update EMP 2 set SAL = SAL * 1.10 3 / 14 rows updated. SQL> rollback; Rollback complete. how ? 22 21 22
  • 11. 9/19/2019 11 23 we remember stuff 24 SQL> update EMP 2 set SAL = SAL * 1.10 3 where ename = 'SMITH' undo header smith $1,0001 block 2754 jones $9002 brown $1,5003 wells $2,0004 wilson $1,0005 block 2754, row 1, sal $1000 uba 5 5 $1,100 uba 5.1 23 24
  • 12. 9/19/2019 12 25 SQL> rollback; 25 26 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 uba 5 5 $1,100 uba 5.1 25 26
  • 13. 9/19/2019 13 27 we can use this stuff for queries! (Oracle version 4) 27 28 read consistency 28 27 28
  • 14. 9/19/2019 14 29 select * from emp where hiredate > '01/01/2004' update emp set ename = 'SUE' where ename = 'JOHN'; 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 30 system change number 29 30
  • 15. 9/19/2019 15 31 Session 1 Request Block 3217, SCN 4567192 Block 3217, SCN 4567234 "SUE" Block 3217, SCN 4567003, change SUE => JOHN undo segment block(s) No good..too new take a copy of the block Locate apply undo Block 3217, SCN 4567234 " SUE" Block 3217, SCN 4567234 " SUE" Block 3217, SCN 4567003 " JOHN" Block 3217, SCN 4567003 "JOHN" Session 2 update emp set ename = 'SUE' where ename = 'JOHN' commit; Done ! 32 stress: vast simplification in-memory undo throwaway undo slots expiry wrap# 31 32
  • 16. 9/19/2019 16 33 every query = locked at a SCN 34 go back further.... 33 34
  • 17. 9/19/2019 17 35 flashback query = choose the SCN 36 v9 circa 2001 35 36
  • 18. 9/19/2019 18 37 SQL> select * from DEPT; DEPTNO DNAME LOC ---------- -------------- ------------- 10 UNKNOWN NEW YORK 20 UNKNOWN DALLAS 30 UNKNOWN CHICAGO 40 UNKNOWN BOSTON 38 SQL> select * from DEPT AS OF SCN 995401; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 37 38
  • 19. 9/19/2019 19 39 less geeky 40 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 39 40
  • 20. 9/19/2019 20 44 SQL> select TIMESTAMP_TO_SCN(systimestamp) 2 from DUAL; TIMESTAMP_TO_SCN(SYSTIMESTAMP) ------------------------------ 998332 SQL> select SCN_TO_TIMESTAMP(998314) from DUAL; SCN_TO_TIMESTAMP(998314) ----------------------------------------------- 16-SEP-19 09.12.48.000000000 PM 45 3 seconds 44 45
  • 21. 9/19/2019 21 46 SQL> select scn_to_timestamp(2409511-rownum) 2 from dual 3 connect by level <= 50; SCN_TO_TIMESTAMP(2409511-ROWNUM) --------------------------------------------- 16-SEP-19 05.47.47.000000000 PM 16-SEP-19 05.47.47.000000000 PM 16-SEP-19 05.47.44.000000000 PM 16-SEP-19 05.47.41.000000000 PM 16-SEP-19 05.47.37.000000000 PM 16-SEP-19 05.47.34.000000000 PM 16-SEP-19 05.47.31.000000000 PM 16-SEP-19 05.47.28.000000000 PM 16-SEP-19 05.47.25.000000000 PM 47 use in "normal" queries 46 47
  • 22. 9/19/2019 22 48 SQL> select e.empno, e.ename, d.dname 2 from emp e, 3 dept AS OF TIMESTAMP '16-SEP-19' 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 "What is in it for me?" 48 49
  • 23. 9/19/2019 23 50 1) unit testing before vs after 51 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 '16-SEP-19 11.51.02 PM' d2 8 on d1.deptno = d2.deptno; ACTION DEPTNO DEPTNO DNAME LOC ------ ---------- ---------- -------------- ---------- 10 10 ACCOUNTING NEW YORK 20 20 RESEARCH DALLAS 30 30 SALES CHICAGO DELETE 40 INSERT 50 MARKETING PERTH 50 51
  • 24. 9/19/2019 24 52 2) not just your data 53 SQL> drop procedure debug_msg; Procedure dropped. SQL> connect / as sysdba Connected. SQL> select text 2 from dba_source 3 as of timestamp systimestamp - interval '5' minute 4 where name='DEBUG_MSG' order by line; TEXT --------------------------------------------------------------------- procedure debug_msg(m varchar2) is begin dbms_output.put_line(m); dbms_application_info.set_client_info(m); end; 5 rows selected. 52 53
  • 25. 9/19/2019 25 54 3) functionality diagnosis 55 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 ? 54 55
  • 26. 9/19/2019 26 56 flashback row versions 57 SQL> SELECT deptno, dname 2 FROM dept 3 VERSIONS BETWEEN 4 TIMESTAMP SYSTIMESTAMP – 5 INTERVAL '20:00' MINUTE TO SECOND 6 AND SYSTIMESTAMP 7 WHERE deptno = 10; DEPTNO DNAME ---------- -------------- 10 ACCOUNTING 10 MONEY GRABBERS 10 FINANCE 10 BEAN COUNTERS 10 UNKNOWN 1 row 5 versions 56 57
  • 27. 9/19/2019 27 58 versions_starttime versions_startscn versions_endtime versions_endscn versions_xid versions_operation 59 SQL> SELECT deptno, dname, 2 VERSIONS_STARTTIME 3 ,VERSIONS_XID 4 ,VERSIONS_OPERATION 5 FROM dept 6 VERSIONS BETWEEN TIMESTAMP 7 SYSTIMESTAMP - INTERVAL '20:00' MINUTE TO SECOND 8 AND SYSTIMESTAMP 9 WHERE deptno = 10; DEPTNO DNAME VERSIONS_STARTTIME VERSIONS_XID V --------- -------------- ---------------------- ---------------- - 10 UNKNOWN 16-SEP-19 11.53.45 PM 0200100060040000 U 10 MONEY GRABBERS 16-SEP-19 11.53.36 PM 0600050065040000 U 10 FINANCE 16-SEP-19 11.53.24 PM 09000D001D050000 U 10 BEAN COUNTERS 16-SEP-19 11.53.12 PM 01001A00EA030000 U 10 ACCOUNTING 58 59
  • 28. 9/19/2019 28 60 get the lot ... 61 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 16-SEP-19 11.08.15 PM 04000700EA030000 U 30 UNKNOWN 16-SEP-19 11.08.15 PM 04000700EA030000 U 20 NERDS 16-SEP-19 11.07.57 PM 090016001D050000 U 20 R&D 16-SEP-19 11.07.48 PM 05000B0074040000 U ... 60 61
  • 29. 9/19/2019 29 62 it might be expensive 63 grant flashback to ... 62 63
  • 31. 9/19/2019 31 68 just how far ? 69 undo_retention 68 69
  • 32. 9/19/2019 32 70 SQL> show parameter undo_retention NAME TYPE VALUE ------------------------------ ----------- -------- undo_retention integer 900 ~ 71 SQL> desc v$undostat Name Null? Type ----------------------------- -------- ----------- BEGIN_TIME DATE END_TIME DATE ... ... TUNED_UNDORETENTION NUMBER CON_ID NUMBER 70 71
  • 33. 9/19/2019 33 73 much much further flashback data archive flashback transaction 73 76
  • 34. 9/19/2019 34 77 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 16-SEP-19 11.08.15 PM 04000700EA030000 U 30 UNKNOWN 16-SEP-19 11.08.15 PM 04000700EA030000 U 20 NERDS 16-SEP-19 11.07.57 PM 090016001D050000 U 20 R&D 16-SEP-19 11.07.48 PM 05000B0074040000 U ... 78 XID ? 77 78
  • 35. 9/19/2019 35 79 SQL> desc V$TRANSACTION Name Null? Type ----------------------------- -------- ------- XIDUSN NUMBER XIDSLOT NUMBER XIDSQN NUMBER ... 80 SQL> select 2 XIDUSN, XIDSLOT, XIDSQN 3 from v$transaction XIDUSN XIDSLOT XIDSQN ---------- ---------- ---------- 1 31 674 SQL> select versions_xid from ... VERSIONS_XID ------------------- 01 001F 00A202 0000 79 80
  • 36. 9/19/2019 36 82 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) 83 SQL> update dept 2 set DNAME = 'FINANCE' 2 where deptno = 10; 1 row updated. 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'; 82 83
  • 37. 9/19/2019 37 84 be careful 85 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 84 85
  • 38. 9/19/2019 38 86 do not query without predicates ... SQL> select xid, undo_sql 2 from flashback_transaction_query 3 where xid = hextoraw('09000d001d050000'); 87 do not forget hextoraw SQL> select xid, undo_sql 2 from flashback_transaction_query 3 where xid = hextoraw('09000d001d050000'); 86 87
  • 39. 9/19/2019 39 88 89 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) | ----------------------------------------------------- 88 89
  • 40. 9/19/2019 40 90 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 | -------------------------------------- 91 UNDO_SQL 90 91
  • 44. 9/19/2019 44 101 flashback transaction 102 SQL> delete from DEPT 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 101 102
  • 45. 9/19/2019 45 103 SQL> BEGIN 2 DBMS_FLASHBACK.TRANSACTION_BACKOUT( 3 numtxns=> 1, 4 xids => sys.xid_array('080017006C040000') 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 104 104 103 104
  • 46. 9/19/2019 46 105 SQL> ALTER DATABASE ADD 2 SUPPLEMENTAL LOG DATA 3 (PRIMARY KEY) COLUMNS; Database altered. 106 SQL> delete from DEPT 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 105 106
  • 47. 9/19/2019 47 107 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? 108 KEEP CALM AND DON'T PANIC 107 108
  • 48. 9/19/2019 48 109 SQL> SELECT COMPENSATING_XID 2 FROM DBA_FLASHBACK_TXN_STATE 3 WHERE xid = '080017006C040000'; COMPENSATING_XID ---------------- 03001C0072040000 110 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> 109 110
  • 49. 9/19/2019 49 111 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 112 2) unit tests 111 112
  • 50. 9/19/2019 50 113 run test ... capture XID 114 commit... validate... undo transaction 113 114
  • 54. 9/19/2019 54 121 SQL> desc EMP ERROR: ORA-04043: object EMP does not exist 122 "undrop" 121 122
  • 55. 9/19/2019 55 123 not cool enough 124 flashback table to before drop 123 124
  • 56. 9/19/2019 56 125 126 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 125 126
  • 57. 9/19/2019 57 127 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 128 SQL> show RECYCLEBIN 127 128
  • 58. 9/19/2019 58 130 SQL> flashback table EMP to before drop; Flashback complete. 131 SQL> flashback table EMP to before drop 2 rename to OLD_EMP; Flashback complete. 130 131
  • 60. 9/19/2019 60 135 SQL> PURGE RECYCLEBIN; SQL> PURGE DBA_RECYCLEBIN; SQL> PURGE TABLE emp; SQL> PURGE TABLE "BIN$xyWe0+q+SniItJ0pn/u54A==$0"; SQL> PURGE TABLESPACE user1; SQL> PURGE TABLESPACE user1 USER fred; SQL> PURGE INDEX "BIN$FTX34MN88J7==$0"; 136 no untruncate 135 136
  • 62. 9/19/2019 62 139 flashback table 140 SQL> FLASHBACK TABLE DEPT 2 TO TIMESTAMP TIMESTAMP '2019-09-16 12:05:00' 139 140
  • 64. 9/19/2019 64 143 repeatable tests without cleanup scripts 144 test ... commit ... flashback to start point 143 144
  • 65. 9/19/2019 65 145 deletes modified rows since SCN inserts fresh rows as of SCN ... busy 149 single transaction ... multiple tables allowed 145 149
  • 67. 9/19/2019 67 154 most DDL is a flashback boundary 155 SQL> flashback table DEPT to scn ...; ORA-01466: unable to read data - table definition has changed 154 155
  • 68. 9/19/2019 68 156 each release gets better 157 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 156 157
  • 71. 9/19/2019 71 Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | AUTHORISED DATABASE ADMINSTRATORS ONLY ! 164 SQL> alter database flashback on; Database altered. 163 164
  • 72. 9/19/2019 72 165 data changes "new" blocks to disk changes to disk "old" blocks to disk redo fbdadbwr 166 SQL> FLASHBACK DATABASE TO '2:05PM' 165 166
  • 73. 9/19/2019 73 167 SQL> create restore point OK_SO_FAR; ... SQL> flashback database to 2 restore point OK_SO_FAR; 168 what does it cost ? 167 168
  • 74. 9/19/2019 74 169 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 173 a good compromise 169 173
  • 76. 9/19/2019 76 "What is in it for me?" 177 1) safer deployment 176 177
  • 77. 9/19/2019 77 178 scenario: "My New Application" 179 9:00 9:40 9:45 SQL> FLASHBACK DATABASE... SQL> alter table ACCOUNTS add ... 178 179
  • 78. 9/19/2019 78 180 2) repeatable end to end testing 181 181 180 181
  • 79. 9/19/2019 79 182 flashback pluggable database 183 3) production data for developers 182 183
  • 80. 9/19/2019 80 184 aka "hidden" flashback database 185 5:00am 11:30pm standby recovery convert to snapshot revert to physical 184 185
  • 81. 9/19/2019 81 flashback data archive 191 less flashback, more archive 190 191
  • 82. 9/19/2019 82 193 SQL> CREATE FLASHBACK ARCHIVE longterm 2 TABLESPACE space_for_archive 3 RETENTION 1 YEAR; Flashback archive created. 194 SQL> ALTER TABLE EMP FLASHBACK ARCHIVE LONGTERM; Table altered. [lots of DML on EMP] 193 194
  • 83. 9/19/2019 83 195 195 SQL> select * from EMP; -------------------------------------------------- | Id | Operation | Name | Rows | Bytes | -------------------------------------------------- | 0 | SELECT STATEMENT | | 14 | 518 | | 1 | TABLE ACCESS FULL| EMP | 14 | 518 | -------------------------------------------------- 196 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 | -------------------------------------------------- 195 196
  • 84. 9/19/2019 84 197 3 days later... 198 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 | ------------------------------------------------------------------ 197 198
  • 85. 9/19/2019 85 199 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 200 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" 199 200
  • 86. 9/19/2019 86 201 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) ) "What is in it for me?" 201 204
  • 87. 9/19/2019 87 205 "I dont care what EMP looked like in June" 206206 why talk about it ? 205 206
  • 88. 9/19/2019 88 207207 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 208208 every historical version... 207 208
  • 89. 9/19/2019 89 209209 ... of every row 210210 sound familiar ? 209 210
  • 91. 9/19/2019 91 213213 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) 214214 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) := 7 case when updating then 'U' 8 when deleting then 'D' else 'I' end; 9 begin 10 if updating or inserting then 11 insert into T_AUDIT 12 values (sysdate 13 ,v_action 14 ,:new.owner 15 ,:new.object_name); 16 else 17 insert into T_AUDIT 18 values (sysdate 19 ,v_action 20 ,:old.owner 21 ,:old.object_name); 22 end if; 23 end; 213 214
  • 92. 9/19/2019 92 217 a better, faster, robust version ... 218 flashback data archive 217 218
  • 93. 9/19/2019 93 219 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-09-16 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 220 so why didn't we ? 219 220
  • 95. 9/19/2019 95 240 flashback data archive is now … 240 Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 241 240 241
  • 97. 9/19/2019 97 266 wrap up 267 flashback query flashback table flashback drop flashback database flashback transaction flashback data archive 266 267
  • 98. 9/19/2019 98 268 all cool for modern development 269 all included in EE 268 269
  • 99. 9/19/2019 99 270 hanging around ? 271 PL/SQL: Still the Best Data Access Language Thursday, September 19, 12:15 PM - 01:00 PM, Moscone South - Room 155A 270 271
  • 100. 9/19/2019 100 272 Thanks for attending !!! youtube tinyurl.com/connortube blog connor-mcdonald.com twitter @connor_mc_d 272