Presentation on how to chat with PDF using ChatGPT code interpreter
Database & Technology 1 _ Clancy Bufton _ Flashback Query - oracle total recall and some of the uses.pdf
1. Flashback
Query
Total
Recall
and
some
of
it’s
uses
By
Clancy
Bu*on
Park
Lane
IT
2. Introduc:on
• Clancy
Bu*on
–
Oracle
DBA
at
Park
Lane
IT
• 7
years
experience
as
an
Oracle
Database
Administrator
working
for
clients
in
government
and
uDliDes
• Clancy.Bu*on@parklane.com.au
3. Flashback
Query
• Available
since
version
9.2
– Implemented
on
Oracles
UNDO
based
read
consistency
• Select
statement
has
two
new
clauses
• AS
of
– Returns
the
enDre
table
as
it
existed
at
a
point
in
Dme
• Versions
Between
– returns
all
commiOed
versions
of
rows
that
existed
between
two
points
in
Dme
4. Flashback
Query
Examples
• select
*
from
scott.emp
as
of
timestamp
sysdate
-‐
interval
'60'
minute;
• select
*
from
scott.emp
versions
between
timestamp
sysdate
-‐
interval
'60'
minute
and
sysdate
-‐
interval
'5'
minute;
5. Flashback
Query
•
Versions
Pseudo
Columns
Used
with
versions
between
– VERSIONS_STARTSCN
and
VERSIONS_STARTTIME
•
StarDng
System
Change
Number
(SCN)
or
TIMESTAMP
when
the
row
version
was
created.
This
pseudocolumn
idenDfies
the
Dme
when
the
data
first
had
the
values
reflected
in
the
row
version.
Use
this
pseudocolumn
to
idenDfy
the
past
target
Dme
for
Oracle
Flashback
Table
or
Oracle
Flashback
Query.
If
this
pseudocolumn
is
NULL,
then
the
row
version
was
created
before
start.
– VERSIONS_ENDSCN
and
VERSIONS_ENDTIME
•
SCN
or
TIMESTAMP
when
the
row
version
expired.
If
the
pseudocolumn
is
NULL,
then
either
the
row
version
was
current
at
the
Dme
of
the
query
or
the
row
corresponds
to
a
DELETE
operaDon.
– VERSIONS_XID
• For
each
version
of
each
row,
returns
the
transacDon
ID
(a
RAW
number)
of
the
transacDon
that
created
the
row
version.
– VERSIONS_OPERATION
•
OperaDon
performed
by
the
transacDon:
I
for
inserDon,
D
for
deleDon,
or
U
for
update.
The
version
is
that
of
the
row
that
was
inserted,
deleted,
or
updated;
that
is,
the
row
a*er
an
INSERT
operaDon,
the
row
before
a
DELETE
operaDon,
or
the
row
affected
by
an
UPDATE
operaDon.
6. Versions
Pseudo
Column
Query
Example
• Can
be
used
in
the
select
list,
the
where
clause
and
order
by
clause
• Select
versions_startscn
,versions_endscn
,versions_operation
,emp.*
from
scott.emp
versions
between
timestamp
sysdate
-‐
interval
'20'
hour
and
sysdate
-‐
interval
'5'
minute
emp
where
versions_operation='U'
order
by
versions_startscn;
7. Total
Recall
• Total
Recall
is
new
in
version
11
• Introduces
Flashback
Archives
to
the
database
• Built
on
ParDDoning
and
Advanced
Compression
technology
• Introduces
a
new
background
process
FBDA
8. Flashback
Archive
• New
privilege
FLASHBACK
ARCHIVE
ADMINISTER
• New
DDL
statement
– create
flashback
archive
flba1
tablespace
flash_archives
retention
10
day;
• Creates
archive
tables
in
a
normal
tablespace
automaDcally
• Enabled
per
table
– alter
table
scott.emp
flashback
archive
flba1;
10. Flashback
Archive
-‐
Internal
Tables
• Enabling
flashback
archive
on
a
table
automaDcally
creates
three
new
tables
in
the
schema
• The
table
name
is
formed
by
SYS_FBA_<purpose>_<FBDA_object_iden3fier>
• SYS_FBA_DDL_COLMAP_<object_id>
– Records
current
and
past
columns
that
existed
on
the
base
table
(supports
DDL
on
the
base
table)
• SYS_FBA_HIST_<object_id>
– Contains
the
actual
historical
values
• SYS_FBA_TCRV_<object_id>
– Maps
start
and
end
SCN
to
rowids
in
the
base
table
to
idenDfy
the
current
version
of
the
row
14. Historical
Indexes
• Indexes
on
base
table
aren’t
mirrored
on
history
tables
• Indexes
can
be
created
on
history
tables
• E.g.
local
prefixed
index
created
for
start
and
end
scn
CREATE
INDEX
"SCOTT"."EMP_SCN_INDEX"
ON
"SCOTT"."SYS_FBA_HIST_73257"
(
"ENDSCN",
"STARTSCN"
)
local;
15. Par::oning
and
Compression
• PARTITION
BY
RANGE
clause
on
SCN
column
of
SYS_FBA_HIST
tables
– Oracle
ParDDoning
opDon
• COMPRESS
FOR
OLTP
clause
on
SYS_FBA_HIST
tables
– Oracle
Advanced
Compression
opDon
16. Flash
Back
Data
Archiver
(FBDA)
• Is
a
new
background
process
• Maintains
the
Flashback
archives
• FBDA
archives
the
historical
rows
of
tracked
tables
into
flashback
data
archives.
• FBDA
is
also
responsible
for
automaDcally
managing
the
flashback
data
archive
for
space,
organizaDon,
and
retenDon
and
keeps
track
of
how
far
the
archiving
of
tracked
transacDons
has
occurred.
17. Flash
Back
Data
Archiver
(FBDA)
• Dynamic
based
on
DML
workload
• AutomaDcally
spawns
parallel
slaves
• Run
asynchronously
by
default
every
5
minutes
• Runs
more
frequently
depending
on
workload
• Reads
UNDO
buffers
from
cache,
or
from
disk
if
they
have
aged
out.
18. DDL
Support
• All
DDL
is
supported
in
11.2
• For
complex
schema
changes
dbms_flashback
• disassociate_sa
and
reassociate_sa
• Manual
changes
can
be
made
a*er
disassociaDon
to
base
table
and
history
table
• ReassociaDon
can
only
occur
if
base
table
and
history
table
schema
is
the
same
19. DBMS_FLASHBACK_ARCHIVE
• begin
dbms_flashback_archive.disassociate_sa('SCOTT','EMP');
end;
/
• begin
dbms_flashback_archive.reassociate_sa('SCOTT','EMP');
end;
/
20. DML
Support
• FBDA
supports
parallel
DML
• DML
cannot
be
performed
on
history
table
by
a
user
• Except
when
it
is
disassociated
from
the
base
table
21. Uses
for
Total
Recall
• AudiDng
– Provides
a
tamper
proof
historical
record
of
all
changes
• Row
based
recovery
– Can
be
used
to
recover
individual
rows
by
updaDng
back
to
a
previous
value
• Change
data
capture
– Fine
grained
change
capture
for
data
warehouse
extracts
22. Cau:on
• Seung
a
very
long
UNDO_RETENTION
in
place
of
using
flashback
archives
• Asynchronous
FBDA
–
changes
may
not
be
visible
to
a
flashback
archive
query
for
several
minutes
a*er
commit
• Global
indexes
on
history
tables
– When
FBDA
automaDcally
maintains
the
parDDons
the
enDre
index
will
be
invalidated
and
need
to
be
rebuilt.
• Don’t
use
in
11.1
– Versions
between
semi
funcDonal
– No
DDL
support
– Many
bugs
– FBDA
no
parallel
DML