Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Internals
Julian Dyke
Independent Consultant
Web Version
1
Agenda
1.
2.
3.
4.
5.
6.
7.
8.
9.
What is Redo?
Redo Records
Change Vectors
Row Operations
Index Operations
Other Redo Operations
Direct Loads / NOLOGGING
Transaction Auditing
Supplemental Logging
What is Redo?
The redo log buffer is flushed to the redo log file when a
COMMIT is issued
What is Redo?
Redo Log
Buffer
LGWR
Redo Log
File
Data Block
Buffer
DBWR
Data File
Arch 2
Arch 3
LGWR
Group 2
ARCH
Arch 4
Arch 5
Group 3
Arch 6
Block 0
File
Header
Block 1
Redo
Header
Block 2
Block 3
Block 4
Redo
Redo
Redo
Record Records Records
2&3
3&4
1
...
Block M
Redo
Record
N
Redo Records
Redo
Record
Header
Change
#1
Change
#2
Change
#3
.....
Change
#N
Fields include
Thread
Thread Number
RBA
LEN
SCN
Contains
Wrap (2 bytes) e.g 0000
Base (4 bytes) e.g 0ac67cc3
Change Vector
Can apply to
undo headers
undo blocks
data segment headers
data blocks
Consists of
header
array of change record lengths
array of change records
Change Vector
For example
Change Header
Length Vector
16
Change Record 1
20
Change Record 2
48
Change Record 3
28
Change Record 4
29
Change Record 5
Change Record 6
Change Record 7
10
Fields include
CHANGE
Change number
TYP
Change type
CLS
Class
AFN
DBA
SCN
SEQ
OP
Operation Code
Block Classes
Description
Data Block
Sort Block
10
Unused
11 + 2r
12 + 2r
DECLARE
l_dba NUMBER := TO_NUMBER ('0144D023','XXXXXXXX');
l_file NUMBER := DBMS_UTILITY.DATA_BLOCK_ADDRESS_FILE (l_dba);
l_block NUMBER := DBMS_UTILITY.DATA_BLOCK_ADDRESS_BLOCK (l_dba);
BEGIN
DBMS_OUTPUT.PUT_LINE ('File : '||l_file);
DBMS_OUTPUT.PUT_LINE ('Block : '||l_block);
END;
Operation Codes
Layers include
Layer
Description
Layer
Description
Block Cleanout
18
Transaction Management
19
Direct Loader
10
Index Operations
20
Compatibility Segment
11
Row Operations
22
13
Segment Management
23
Block Writes
14
Extent Management
24
DDL Statements
17
Tablespace Management
Transactions
Transaction ID (XID)
Contains
Undo segment number (USN) of transaction (0x0004)
Undo segment header transaction table slot (0x00e)
Sequence number (wrap) (0x0000449b)
Contains
DBA of undo block (0x00c01f17)
Sequence number (2758)
Record number in block (4)
Transactions
Statements
UPDATE t1
SET c2 = 101
WHERE c1 = 1;
Redo Logs
Undo Header
Undo Header
5.2
Undo
Slot 0 c2 = 100
5.1
Redo
11.5
Slot 0 c2 = 101
UPDATE t1
SET c2 = 201
WHERE c1 = 2;
COMMIT;
Undo
Slot 1 c2 = 200
5.1
SLOT
0
Undo Block
Undo
Slot 0 c2 = 100
Undo
Slot 1 c2 = 200
11.5
Redo
Slot 1 c2 = 201
Commit
5.4
STATUS
10
9
Data Block
SLOT
C1
C2
100
101
201
200
Physiological Logging
Undo
Redo
INSERT INTO t1
VALUES (1, 'ABC');
Delete row 1
Row 1
c1 := 1
c2 := 'ABC'
UPDATE t1
SET c2 = 'DEF'
WHERE c1 = 1;
Row 1
c2 := 'ABC'
Row 1
c2 := 'DEF'
DELETE FROM t1
WHERE c1 = 1;
Row 1
c1 := 1
c2 := 'DEF'
Delete row 1
SELECT c2 FROM t1
WHERE c1 = 1
FOR UPDATE;
Unlock row 1
Lock row 1
Row Operations
Mnemonic
11.2
IRP
11.3
DRP
11.4
LKR
Lock Row
11.5
URP
Update Row
11.6
ORP
Chained Row
11.9
CKI
11.10
SKL
11.11
QMI
11.12
QMD
Description
Statements
-- Statement #1
INSERT INTO t1 VALUES (1);
HEADER
5.2
UNDO #1
5.1
REDO #1
11.2
-- Statement #2
INSERT INTO t1 VALUES (2);
UNDO #2
5.1
REDO #2
11.2
-- Statement #3
INSERT INTO t1 VALUES (3);
UNDO #3
5.1
REDO #3
11.2
COMMIT
5.4
COMMIT;
Statements
-- Statement #1
INSERT INTO t1
SELECT * FROM t2;
COMMIT;
HEADER
5.2
UNDO #1
5.1
REDO #1
11.11
COMMIT
5.4
Statements
-- Statement #1
UPDATE t1 SET c2 = c2 + 1
WHERE c1 = 1;
-- Statement #2
UPDATE t1 SET c2 = c2 + 1
WHERE c1 = 2;
-- Statement #3
UPDATE t1 SET c2 = c2 + 1
WHERE c1 = 3;
COMMIT;
HEADER
5.2
UNDO #1
5.1
REDO #1
11.5
UNDO #2
5.1
REDO #2
11.5
UNDO #3
5.1
REDO #3
11.5
COMMIT
5.4
Statements
-- T1 contains 3 rows
UPDATE t1 SET c2 = c2 + 1;
COMMIT;
HEADER
5.2
UNDO #1
5.1
REDO #1
11.5
UNDO #2
5.1
REDO #2
11.5
UNDO #3
5.1
REDO #3
11.5
COMMIT
5.4
Statements
-- Statement #1
DELETE FROM t1
WHERE c1 = 1;
-- Statement #2
DELETE FROM t1
WHERE c1 = 2;
-- Statement #3
DELETE FROM t1
WHERE c1 = 3;
COMMIT;
HEADER
5.2
UNDO #1
5.1
REDO #1
11.3
UNDO #2
5.1
REDO #2
11.3
UNDO #3
5.1
REDO #3
11.3
COMMIT
5.4
Statements
-- T1 contains 3 rows
DELETE FROM t1;
COMMIT;
HEADER
5.2
UNDO #1
5.1
REDO #1
11.3
UNDO #2
5.1
REDO #2
11.3
UNDO #3
5.1
REDO #3
11.3
COMMIT
5.4
Statements
-- Statement #1
SELECT c2 FROM t1
WHERE c1 = 1
FOR UPDATE;
-- Statement #2
UPDATE t1
SET c2 = c2 + 1
WHERE c1 = 1;
COMMIT;
HEADER
5.2
UNDO #1
5.1
REDO #1
11.4
UNDO #2
5.1
REDO #2
11.5
COMMIT
5.4
Statements
-- T1 contains 3 rows
SELECT c2 FROM t1
FOR UPDATE;
COMMIT;
HEADER
5.2
UNDO #1
5.1
REDO #1
11.4
UNDO #2
5.1
REDO #2
11.4
UNDO #3
5.1
REDO #3
11.4
COMMIT
5.4
Rollback
Redo
Statements
HEADER
5.2
UNDO #1
5.1
REDO #1
11.2
-- Statement #2
INSERT INTO t1 VALUES (2);
UNDO #2
5.1
REDO #2
11.2
ROLLBACK;
UNDO #3
11.3
REDO #3
5.6
UNDO #4
11.3
REDO #4
5.11
COMMIT
5.4
-- Statement #1
INSERT INTO t1 VALUES (1);
Statements
-- Statement #1
INSERT INTO t1 VALUES (1);
HEADER
5.2
UNDO #1
5.1
REDO #1
11.2
-- Statement #2
INSERT INTO t1 VALUES (2);
UNDO #2
5.1
REDO #2
11.2
-- Statement #3
INSERT INTO t1 VALUES (3);
UNDO #3
5.1
REDO #3
11.2
COMMIT
5.4
COMMIT;
Index Operations
Opcode
Description
Opcode Description
10.2
10.13
10.3
10.15
10.4
10.16
10.5
10.18
10.6
Lock block
10.19
10.7
10.21
10.8
Initialise header
10.22
10.9
10.24
Shrink ITL
10.10
10.30
10.11
10.31
Create/Load Index
10.12
10.34
Index Insert
Redo
Statements
-- Insert into table t1
INSERT INTO t1
VALUES (1,10);
HEADER
5.2
UNDO #1
5.1
REDO #1
11.2
UNDO #2
5.1
REDO #2
10.2
UNDO #3
5.1
REDO #3
10.2
COMMIT
5.4
COMMIT;
Index Updates
Redo
Statements
-- Update table t1
UPDATE t1
SET c1 = 2
WHERE c1 = 1;
-- Delete from index i1
-- Insert into index i1
COMMIT;
HEADER
5.2
UNDO #1
5.1
REDO #1
11.5
UNDO #2
5.1
REDO #2
10.4
UNDO #3
5.1
REDO #3
10.2
COMMIT
5.4
Index Deletes
Redo
Statements
-- Delete from table t1
DELETE FROM t1
WHERE c1 = 1;
-- Delete from index i1
-- Delete from index i2
COMMIT;
HEADER
5.2
UNDO #1
5.1
REDO #1
11.3
UNDO #2
5.1
REDO #2
10.4
UNDO #3
5.1
REDO #3
10.4
COMMIT
5.4
1
2
UPDATE t1
SET c1 = 2
WHERE c1 = 1;
Update UNDO #1 5.1
table
REDO #1 11.5
row
Delete
index
row
UNDO #2
Insert
index
row
UNDO #3
5.1
REDO #2 10.4
5.1
REDO #3 10.2
Before
After
1
1
UPDATE t1
SET c1 = 1
WHERE c1 = 1
UNDO #1
5.1
REDO #1 11.5
Before
After
1
NULL
UPDATE t1
SET c1 = NULL
WHERE c1 = 1;
UNDO #1
5.1
REDO #1 11.5
UNDO #2
Before
After
NULL
1
UPDATE t1
SET c1 = 1
WHERE c1 IS NULL
UNDO #1
5.1
REDO #1 11.5
5.1
REDO #2 10.4
UNDO #3
5.1
REDO #3 10.2
Block Cleanout
Occurs when ITL on data block has not been updated when
changes were committed
Backups
A block image is written to the redo log for each block that is
modified (opcode 18.1)
Block Writes
Direct Loads
NOLOGGING
NOLOGGING
LOGGING NOLOGGING
14238844
39548
14227236
45340
14221904
42452
20726784
3784532
CREATE INDEX
2042532
24548
2056440
32192
2083832
67840
SQL*Loader (Direct)
14248116
56712
Online Reorganization
21330788
7169472
FORCE NOLOGGING
or
ALTER TABLESPACE <tablespace_name>
FORCE LOGGING;
Transaction Auditing
Transaction Auditing
Supplemental Logging
Can be specified at
Database level
Table level
Supplemental Logging
Disabled using
ALTER DATABASE DROP SUPPLEMENTAL LOG DATA;
Supplemental Logging
Disabled using
ALTER TABLE table1
DROP SUPPLEMENTAL LOG GROUP group1;
Supplemental Logging
Statements
-- Statement #1
UPDATE t1
SET c3 = 400
WHERE c1 = 100;
Redo
HEADER
HEADER
UNDO #1
5.25.2
5.1
c3 = 300
c1 = 100
c2 = 200
REDO #1
c3 = 400
11.5
Dumping Logfiles