Sunteți pe pagina 1din 64

LOB Internals

Julian Dyke
Independent Consultant

Web Version - December 2008


1 © 2008 Julian Dyke juliandyke.com
Objectives

1. Understand how LOBs use storage in the


Oracle database

2. Consider options to optimize LOB performance


in terms of:
 Reads
 Writes
 Impact on physical I/O
 Impact on buffer cache

2 © 2008 Julian Dyke juliandyke.com


Agenda

 Basic Files
 Secure Files

3 © 2008 Julian Dyke juliandyke.com


Basic
Files

4 © 2008 Julian Dyke juliandyke.com


Basic Files
Overview
 Introduced in Oracle 8.0
 Known as Basic Files in Oracle 11.1 and above

 Intended to replace LONG columns

 Can be used to store large blocks of unstructured data e.g.:


 text
 graphics
 video clips
 sound waveforms
 XML documents

 Can store either character or binary data

 Can be stored
 within database (internal)
 outside database (external)

5 © 2008 Julian Dyke juliandyke.com


Basic Files
LOB Types
 There are four types of LOB:

 BLOB - Binary Large Object


 Stored within database
 Contains raw data

 CLOB - Character Large Object


 Stored within database
 Supports database character set

 NCLOB - NLS Character Large Object


 Stored within database
 Supports NLS character set

 BFILE - Binary File Large Object


 Stored in a binary file outside the database
 Pointed to by a file locator within the database

6 © 2008 Julian Dyke juliandyke.com


Basic Files
Internal LOBs
 Stored outside of database
 BLOB, CLOB or NCLOB

 Maximum size is dependent on version and chunk size

 Support features such as:


 concurrency
 redo logging and recovery
 transactions with commits and rollbacks

 For each row with an internal LOB column, the LOB can:
 Be NULL
 Point to an empty BLOB, CLOB or NCLOB
 Point to a BLOB, CLOB or NCLOB value

7 © 2008 Julian Dyke juliandyke.com


Basic Files
LOB columns versus LONG columns
 LOBs are intended to replace LONG columns:
 Oracle recommends converting LONG columns to LOB columns
 LONG columns still used by many applications
 LONG columns still used in Oracle 11.1 data dictionary tables including:
 COL$, TABPART$, INDPART$, TRIGGER$, VIEW$ and CDEF$
 Therefore it is unlikely LONG columns will be desupported in the near
future

 LONGs  LOBs
 Single column per table  Multiple columns per table

 Maximum size 2GB  Maximum size 4GB or more

 Data always stored in-line  Data stored in-line or out-of-line

 Cannot be an object attribute  Can be an object attribute

 Cannot be partitioned  Can be partitioned

 Cannot be used in IOTs  Can be used in IOTs

 Cannot be replicated  Can be replicated

 Access is sequential  Access can be is random

 Partial PL/SQL support  Full PL/SQL support

8 © 2008 Julian Dyke juliandyke.com


Basic Files
DBMS_LOB Package
 BLOB and CLOB Subroutines
 APPEND  GETOPTIONS (11.1+)
 CLOSE  GET_STORAGE_LIMIT
 COMPARE  INSTR ISSECUREFILE
 CONVERTTOBLOB  ISTEMPORARY
 CONVERTTOCLOB  ISOPEN
 COPY  LOADFROMFILE
 CREATETEMPORARY  LOADBLOBFROMFILE
 ERASE  LOADCLOBFROMFILE
 FRAGMENT_DELETE (11.1+)  OPEN
 FRAGMENT_INSERT (11.1+)  READ
 FRAGMENT_MOVE (11.1+)  SETOPTIONS (11.1+)
 FRAGMENT_REPLACE (11.1+)  SUBSTR
 FREETEMPORARY  TRIM
 GETCHUNKSIZE  WRITE
 GET_DEDUPLICATE_REGIONS (11.1+)  WRITEAPPEND
 GETLENGTH

9 © 2008 Julian Dyke juliandyke.com


Basic Files
DBMS_LOB Package
 BFILE Subroutines
 CLOSE
 COMPARE
 FILECLOSE
 FILECLOSEALL
 FILEEXISTS
 FILEGETNAME
 FILEISOPEN
 FILEOPEN
 GETLENGTH
 INSTR
 ISOPEN
 OPEN
 READ
 SUBSTR

1 © 2008 Julian Dyke juliandyke.com


Basic Files
DBA_LOBS View
Column Name Data Type Comments
OWNER VARCHAR2(30)
TABLE_NAME VARCHAR2(30)
COLUMN_NAME VARCHAR2(4000)
SEGMENT_NAME VARCHAR2(30)
TABLESPACE_NAME VARCHAR2(30)
INDEX_NAME VARCHAR2(30)
CHUNK NUMBER
PCTVERSION NUMBER
RETENTION NUMBER
FREEPOOLS NUMBER
CACHE VARCHAR2(10)
LOGGING VARCHAR2(7)
ENCRYPT VARCHAR2(4) Oracle 11.1 and
above
COMPRESSION VARCHAR2(6) Oracle 11.1 and
above
DEDUPLICATION VARCHAR2(15) Oracle 11.1 and
above
IN_ROW VARCHAR2(3)
FORMAT VARCHAR2(15)
11 © 2008 Julian Dyke
PARTITIONED VARCHAR2(3) juliandyke.com
Basic Files
LOB Objects
 If a table includes an internal LOB column, the following objects will be
created
 LOB index
 LOB data

 Each object has a separate segment

 For example:
T1
LOB
TABLE
CREATE TABLE t1
(
c1 NUMBER, SYS_IL0000055604C00002$$
LOB
c2 CLOB, LOB INDEX
);

SYS_LOB0000055604C00002$$
LOB
LOB DATA

1 © 2008 Julian Dyke juliandyke.com


Basic Files
LOB Segments
 Every LOB has a LOB data segment and a LOB index segment

 LOB data segment is reported by DBA_OBJECTS


 Segment name is system generated e.g. SYS_LOB0000070479C00002$$
 where:
 0000070479 is the OBJECT_ID of the table
 00002 is the column number of the LOB column within the table

 LOB index is not reported by DBA_OBJECTS


 Index is still defined in SYS.OBJ$ and SYS.IND$
 Index name is reported by DBA_LOBS e.g. SYS_IL0000070479C00002$$
 where:
 0000070479 is the OBJECT_ID of the table
 00002 is the column number of the LOB column within the table

1 © 2008 Julian Dyke juliandyke.com


Basic Files
LOB Objects
 One LOB index segment and one LOB data segment will be created for each
LOB column

 For example: CREATE TABLE t2


(
c1 NUMBER,
c2 CLOB,
c3 CLOB
);

T2
LOB
TABLE

SYS_IL0000055607C00002$$ SYS_IL0000055607C00003$$
LOB LOB
LOB INDEX LOB INDEX

SYS_LOB0000055607C00002$$ SYS_LOB0000055607C00003$$
LOB LOB
LOB DATA LOB DATA

1 © 2008 Julian Dyke juliandyke.com


Basic Files
Partitioned LOBs
 Oracle supports partitioned and sub-partitioned LOBS in Oracle 8.1.5 and
above
 LOBs are supported in partitioned IOTs in Oracle 9.0.1 and above

 LOB and and LOB index segments are equi-partitioned with base table

 Partitioning key cannot contain a LOB column

CREATE TABLE t3
(
c1 NUMBER,
c2 CLOB
)
PARTITION BY RANGE (c1)
(
PARTITION p1 VALUES LESS THAN (100),
PARTITION p2 VALUES LESS THAN (200)
);

1 © 2008 Julian Dyke juliandyke.com


Basic Files
Partitioned LOBs

T3
LOB
TABLE

P1 P2
TABLE PARTITION TABLE PARTITION

SYS_IL0000055612C00002$$
LOB
LOB INDEX
SYS_LOB_P23 SYS_LOB_P24
INDEX PARTITION INDEX PARTITION

SYS_LOB0000055612C00002$$
LOB
LOB

SYS_LOB_P21 SYS_LOB_P22
LOB PARTITION LOB PARTITION

1 © 2008 Julian Dyke juliandyke.com


Basic Files
Sub Partitioned LOBs
CREATE TABLE t4
(
c1 NUMBER,
c2 NUMBER,
c3 CLOB
)
PARTITION BY RANGE (c1)
(
PARTITION p1 VALUES LESS THAN (100)
(
SUBPARTITION p1s1 VALUES LESS THAN (10),
SUBPARTITION p1s2 VALUES LESS THAN (20)
),
PARTITION p2 VALUES LESS THAN (200)
(
SUBPARTITION p2s1 VALUES LESS THAN (10),
SUBPARTITION p2s2 VALUES LESS THAN (20)
)
);

1 © 2008 Julian Dyke juliandyke.com


Basic Files
Sub Partitioned LOBs
T4
LOB
TABLE

P1 P2
TABLE PARTITION TABLE PARTITION

P1S1 P1S2 P2S1 P2S2


TABLE SUBPARTITION TABLE SUBPARTITION TABLE SUBPARTITION TABLE SUBPARTITION

SYS_IL0000055633C00003$$
LOB
LOB INDEX
SYS_LOB_P41 SYS_LOB_P44
SYS_IL_P23
INDEX PARTITION SYS_IL_P24
INDEX PARTITION

SYS_LOB_SUBP32 SYS_LOB_SUBP33 SYS_LOB_SUBP35 SYS_LOB_SUBP36


INDEX SUBPARTITION INDEX SUBPARTITION INDEX SUBPARTITION INDEX SUBPARTITION

SYS_LOB0000055633C00003$$
LOB
LOB

SYS_LOB_P31 SYS_LOB_P34
LOB PARTITION LOB PARTITION

SYS_LOB_SUBP32 SYS_LOB_SUBP33 SYS_LOB_SUBP35 SYS_LOB_SUBP36


LOB SUBPARTITION LOB SUBPARTITION LOB SUBPARTITION LOB SUBPARTITION

1 © 2008 Julian Dyke juliandyke.com


Basic Files
In Row versus Out-of-Line Storage
 Values can be stored
 in-line - in a row piece
 out-of-line - in a separate LOB segment

CREATE TABLE t1 (c1 NUMBER, c2 CLOB)


LOB (c2) STORE AS (ENABLE STORAGE IN ROW);
CREATE TABLE t2 (c1 NUMBER, c2 CLOB)
LOB (c2) STORE AS (DISABLE STORAGE IN ROW);

 ENABLE STORAGE IN ROW (default)


 LOB value is stored within row if size is < 3964 bytes
 LOB value is stored out-of-line if size > 3964 bytes
 If in-line LOB grows to more than 3964 bytes
 LOB value is moved out-of-line to LOB segment
 If out-of-line LOB shrinks to less than 3964 bytes
 LOB value remains out-of-line in LOB segment
 DISABLE STORAGE IN ROW
 LOB value is always stored out-of-line in LOB segment

1 © 2008 Julian Dyke juliandyke.com


Basic Files
LOB Initialization
 LOBs are initialized using built-in functions
 EMPTY_BLOB ()
 EMPTY_CLOB ()
 Both functions create LOB locators
 Minimum size is 36 bytes
 Maximum size is 86 bytes

CREATE TABLE t1
(
c1 NUMBER,
c2 CLOB,
);

INSERT INTO t1 VALUES (c1,NULL);

C2 occupies 0 bytes

INSERT INTO t1 VALUES (c1,EMPTY_CLOB());


C2 occupies 37bytes

2 © 2008 Julian Dyke juliandyke.com


Basic Files
LOB Initialization
 LOB locator is initialized using EMPTY_CLOB() or EMPTY_BLOB()
 For example:

INSERT INTO t1 VALUES (c1,EMPTY_CLOB());


 Block dump includes :

tab 0, row 151, @0x579


tl: 44 fb: --H-FL-- lb: 0x1 cc: 2
col 0: [ 3] c2 08 53
col 1: [36]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 89 3d 00 10 09 00 00
00 00 00 00 00 00 00 00 00 00 00

Header LOBID

00 54 0 01 0 0c 0 00 0 01 0 00 0 01 0 00 00 0 89 3d
0 2 0 0 0 0 0 0
00 10 0 00 0 00 0 00 0 00 0 00 0 00 0 00
9 0 0 0 0 0 0
Body Length Flags LOB Length Version

2 © 2008 Julian Dyke juliandyke.com


Basic Files
LOB ID
 LOB ID is a 10 byte number identifying individual instance of a LOB
 Allocated when LOB value is created including EMPTY_CLOB() etc
 Format is <X><Y> where
 <X> is a currently unknown 4-byte number (always 1)
 <Y> is a 6-byte number generated from sequence SYS.IDGEN$
 For example:
SELECT sequence_owner, sequence_name, nextvalue, increment_by, cache_size
FROM v$_sequences;
Sequence Owner Sequence Name Next Value Increment By Cache Size
SYS IDGEN1$ 37401 50 20

INSERT INTO t1 VALUES (0,EMPTY_CLOB)

 LOB ID = 00 0 00 0 00 00 0 00 9 19 (0x9219 = 37401)


0 1 0 2
SELECT sequence_owner, sequence_name, nextvalue, increment_by, cache_size
FROM v$_sequences;
Sequence Owner Sequence Name Next Value Increment By Cache Size
SYS IDGEN1$ 37451 50 20

2 © 2008 Julian Dyke juliandyke.com


Basic Files
LOB Inline Storage
 Example 1 - 12 byte LOB - ENABLE STORAGE IN ROW

INSERT INTO t1 VALUES (c1, LPAD ('X',12,'X'));

ab 0, row 0, @0x1f62
tl: 54 fb: --H-FL-- lb: 0x1 cc: 2
col 0: [ 1] 80
col 1: [48]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 8a 7b 00 1c 09 00 00
00 00 00 00 0c 00 00 00 00 00 01 58 58 58 58 58 58 58 58 58 58 58 58

0 54 00 0 02 0 00 0 00 0 00 0 00 0 00 0 00 0 8a 7b
0 1 c 0 1 0 1 0 0
0 1c 09 0 00 0 00 0 00 0 00 0 00 0 00 0 58 5 58 58
0 0 0 0 c 0 0 1 8
5 58 58 5 58 5 58 5
8 0x1C
8 = 28 8 8 0x0C = 12

2 © 2008 Julian Dyke juliandyke.com


Basic Files
LOB Inline Storage
 Example 2 - 400 byte LOB - ENABLE STORAGE IN ROW

INSERT INTO t1 VALUES (c1,LPAD ('X',400,'X'));

tab 0, row 0, @0x1ddc


tl: 444 fb: --H-FL-- lb: 0x1 cc: 2
col 0: [ 1] 80
col 1: [436]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 8a ad 01 a0 09 00 00
00 00 00 01 90 00 00 00 00 00 01 58 58 58 58 58 58 58 58 58 58 58 58 58 58
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
.......

00 54 0 01 0 0c 0 00 0 01 0 00 0 01 0 00 00 0 8a ad
0 2 0 0 0 0 0 0
01 a0 0 00 0 00 0 00 0 90 0 00 0 00 0 01 58 5 58 58
9 0 0 1 0 0 0 8
58 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 58 5 58 58
0x01A0
8 = 416
8 8 8 0x0190
8 = 8400 8 8
2 ©58 58Julian
2008 5 58 5
Dyke 58 5 58 5 58 5 58 5 58 5 juliandyke.com
5858 5 58 58
Basic Files
LOB Inline Storage
 Example 3 - 3964 byte LOB - ENABLE STORAGE IN ROW

INSERT INTO t1 VALUES (c1,LPAD ('X',3964,'X'));

tab 0, row 0, @0xff0


tl: 4008 fb: --H-FL-- lb: 0x1 cc: 2
col 0: [ 1] 80
col 1: [4000]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 8c a1 0f 8c 09 00 00
00 00 00 0f 7c 00 00 00 00 00 01 58 58 58 58 58 58 58 58 58 58 58 58 58 58
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
58 . . . . . . .

0 54 00 0 02 0 00 0 00 0 00 0 00 0 00 0 00 0 8c a
0 1 c 0 1 0 1 0 0 1
0f 8c 09 0 00 0 00 0 0f 7 00 0 00 0 00 0 58 5 58 5
0 0 0 c 0 0 1 8 8
5 58 58
5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5
8 0x0F8C8= 3980 8 8 8 8 = 3964
0x0F7C 8 8 8 8
5 58 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5
2 8
© 2008 8
Julian Dyke 8 8 8 8 8 juliandyke.com
8 8 8
Basic Files
LOB Out-of-Line Storage
 Example 4 - 3965 byte LOB - ENABLE STORAGE IN ROW

INSERT INTO t1 VALUES (c1,LPAD ('X',3965,'X'));

tab 0, row 0, @0x1f6a


tl: 46 fb: --H-FL-- lb: 0x1 cc: 2
col 0: [ 1] 80
col 1: [40]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 8d 05 00 14 05 00 00
00 00 00 0f 7d 00 00 00 00 00 02 01 00 01 b5

00 54 00 01 0 0c 0 00 0 01 00 00 0 01 0 00 00 0 8d 05
2 0 0 0 0 0
00 14 05 00 0 00 0 00 0f 7d 00 00 0 00 0 02 01 0 01 b5
0 0 0 0 0

0x0014 = 20 0x0F7D bytes Address of


first chunk

0x0F7D = 3965
2 © 2008 Julian Dyke juliandyke.com
Basic Files
LOB Out-of-Line Storage
 Out-of-line LOB data is stored in a PAGETABLE MANAGED LOB BLOCK
 Each block has
 a 56 byte header
 a 4 byte trailer
 For example for a 8192 byte block

Header
56 bytes

LOB Data
8132 bytes

Trailer
4 bytes

2 © 2008 Julian Dyke juliandyke.com


Basic Files
Out-of-Line Storage
CREATE DIRECTORY dir1 AS '/tmp';
CREATE TABLE t11
(
c1 NUMBER,
c2 CLOB
DECLARE
);
l_bfile BFILE;
INSERT INTO t11 l_clob CLOB;
VALUES (0,EMPTY_CLOB()); l_result NUMBER;
BEGIN
l_bfile := BFILENAME ('DIR1','dbms_stats.lst');
DBMS_LOB.OPEN (l_bfile);
SELECT c2 INTO l_clob FROM t11
WHERE c1 = 0 FOR UPDATE;
l_result := DBMS_LOB.GETLENGTH (l_bfile);
DBMS_LOB.LOADFROMFILE (l_clob,l_bfile,l_result);
DBMS_LOB.CLOSE (l_bfile);
END;

2 © 2008 Julian Dyke juliandyke.com


Basic Files
LOB Out-of-Line Storage
 Example 5 - 69237 byte LOB - ENABLE STORAGE IN ROW

INSERT INTO t1 VALUES (c1,BFILE...);

tl: 78 fb: --H-FL-- lb: 0x2 cc: 2


col 0: [ 1] 80
col 1: [72]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 8d ff 00 34 05 00 00
00 00 08 10 55 00 00 00 00 00 02 01 00 02 5f 01 00 02 60 01 00 02 5c 01 00
02 5d 01 00 02 5e 01 00 02 6e 01 00 02 6f 01 00 02 70 01 00 02 6a

00 54 00 01 0 0c 0 00 0 01 00 00 0 01 0 00 00 0 8d ff
2 0 0 0 0 0
00 34 05 00 0 00 0 08 1 55 00 00 0 00 0 02 01 0 02 5f
0 0 0 0 0 0
01 00 02 60 0 00 0 5c 0 00 02 5d 0 00 0 5e 010 02 6e
1 2 1 1 2 0 of LOB
DBA
0x34 =0152 00 02 6f 0 8 chunks
00 0 70 0 0x1055
00 02bytes
6a chunks
1 2 1
8 x 8132 = 65056 0x1055 = 4181 65056 + 4181+ 69237

2 © 2008 Julian Dyke juliandyke.com


Basic Files
LOB Out-of-Line Storage
 Example 6 - 97584 byte LOB - ENABLE STORAGE IN ROW

INSERT INTO t1 VALUES (c1,BFILE...);

tab 0, row 0, @0x1f14


tl: 90 fb: --H-FL-- lb: 0x2 cc: 2
col 0: [ 1] 80
col 1: [84]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 90 25 00 40 05 00 00
00 00 0c 00 00 00 00 00 00 00 02 01 00 02 3d 01 00 02 3e 01 00 02 3f 01 00
02 40 01 00 02 3c 01 00 02 37 01 00 02 38 01 00 02 32 01 00 02 33 01 00 02
34 01 00 02 35 01 00 02 36

00 54 0 01 02 0 00 00 0 01 00 00 0 01 0 00 00 0 90 25
0 c 0 0 0 0
00 40 0 00 00 0 00 0c 0 00 00 00 0 00 0 02 01 0 02 3d
5 0 0 0 0 0
01 00 0 3e 01 0 02 3f 0 00 02 40 0 00 0 3c 01 0 02 37
2 0 1 1 2 0
01 00 0 38 01 0 02 32 0 00 02 33 0 00 0 LOB
34 Index
01 0exists
02 35
0x40 = 264 12 0chunks 1 0 bytes 1 2 but is empty
0
3 01 00 Julian
© 2008 0 36 Dyke 12 x 8132 = 97584 juliandyke.com
Basic Files
LOB Out-of-Line Storage
 Example 7- 97585 byte LOB - ENABLE STORAGE IN ROW

INSERT INTO t1 VALUES (c1,BFILE...);

tab 0, row 0, @0x1f14


tl: 90 fb: --H-FL-- lb: 0x2 cc: 2
col 0: [ 1] 80
col 1: [84]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 90 89 00 40 05 00 00
00 00 0c 00 01 00 00 00 00 00 02 01 00 03 2d 01 00 03 2e 01 00 03 2f 01 00
03 30 01 00 03 2c 01 00 03 27 01 00 03 28 01 00 03 22 01 00 03 23 01 00 03
24 01 00 03 25 01 00 03 26

00 54 00 01 0 0c 0 00 0 01 0 00 00 0 00 00 0 00 90 89
2 0 0 0 1 0
00 40 05 00 0 00 0 0c 0 01 0 00 00 0 00 02 0 00 03 2d
0 0 0 0 0 1
01 00 03 2e 0 00 0 2f 0 00 0 30 01 0 03 2c 0 00 03 27
1 3 1 3 0 1
01 00 03 28 0 00 0 22 0 00 0 23 01
LOB Index is used 03 25
0 03 th 24 0 00
0x40 = 64 1
12 chunks
3 1
1 byte
3 0for 13 chunk
1
3 ©012008
00 Julian
03 26Dyke juliandyke.com
Basic Files
LOB Out-of-Line Storage
 Example 7 continued - 97585 byte LOB - ENABLE STORAGE IN ROW
 LOB Index

row#0[7982] flag: ------, lock: 2, len=50, data:(32):


01 00 03 3f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00
col 0; len 10; (10): 00 00 00 01 00 00 00 00 90 89
col 1; len 4; (4): 00 00 00 0c

LOBID First chunk number

Key 00 00 00 0 00 0 00 00 9 89 0 00 00 0
1 0 0 0 c
Data 01 00 03 3f 0 00 0 00 0 00 0 00 00 0 00 00
0 0 0 0 0
00 00 00 00 0 00 0 00 0 00 0 00 00 0 00 00
0 0 0 0 0
 LOB Index is always unique
 Data is always 32 bytes

3 © 2008 Julian Dyke juliandyke.com


Basic Files
LOB Out-of-Line Storage
 Example 8 - 187264 byte LOB - ENABLE STORAGE IN ROW

INSERT INTO t1 VALUES (c1,BFILE...);

tab 0, row 0, @0x1f14


tl: 90 fb: --H-FL-- lb: 0x2 cc: 2
col 0: [ 1] 80
col 1: [84]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 90 ed 00 40 05 00 00
00 00 17 00 e4 00 00 00 00 00 02 01 00 03 35 01 00 03 36 01 00 03 37 01 00
03 38 01 00 03 34 01 00 03 5f 01 00 03 60 01 00 03 5a 01 00 03 5b 01 00 03
5c 01 00 03 5d 01 00 03 5e

00 54 0 01 02 0 00 00 0 01 00 00 0 01 0 00 00 0 90 ed
0 c 0 0 0 0
00 40 0 00 00 0 00 17 0 e4 00 00 0 00 0 02 01 0 03 35
5 0 0 0 0 0
01 00 0 36 01 0 03 37 0 00 03 38 0 00 0 34 01 0 03 5f
3 0 1 1 3 0
12 chunks in row
01 00 0 60 01 0 03 5a 0 00 03 5b 0 00 0 11 5c 01 0in index
chunks 03 5d
3 0
0x17 = 231 0xe4 = 2281 3 0
chunks bytes
3 01 00 Julian
© 2008 0 5e Dyke juliandyke.com
Basic Files
LOB Out-of-Line Storage
 Example 8 continued - 187264 byte LOB - ENABLE STORAGE IN ROW
 Lob Index
row#0[7982] flag: ------, lock: 2, len=50, data:(32):
01 00 03 6f 01 00 03 70 01 00 03 6a 01 00 03 6b 01 00 03 6c 01 00 03 6d 01
00 03 6e 01 00 03 57
col 0; len 10; (10): 00 00 00 01 00 00 00 00 90 ed
col 1; len 4; (4): 00 00 00 0c
row#1[7932] flag: ------, lock: 2, len=50, data:(32):
01 00 03 58 01 00 03 52 01 00 03 53 01 00 03 54 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00
col 0; len 10; (10): 00 00 00 01 00 00 00 00 90 ed
col 1; len 4; (4): 00 00 00 14

Key 00 00 00 0 00 0 00 00 9 ed 0 00 00 0
1 0 0 0 c
01 00 03 6f 0 00 0 70 01 00 03 6a 0 00 0 6b
Data
1 3 1 3
01 00 03 6c 0 00 0 6d 01 00 03 6e 0 00 0 57
Key 00 00 00 0 00
1 0 00
3 00 9 ed 0 00 00
1 1 3
1 0 0 0 4
Data 01 00 03 58 0 00 0 52 01 00 03 53 0 00 0 54
1 3 1 3
3 © 200800 00 Dyke
Julian 00 00 0 00 0 00 00 00 00 00 0 00 juliandyke.com
0 00
Basic Files
Chunk Size
 Each internal LOB has a chunk size
 Chunks can be manipulated individually
 Default chunk size is block size
 Maximum chunk size is 32768 for all tablespace block sizes
 Chunk size is:
 specified in bytes
 rounded up to nearest block size

CREATE TABLE t3 (c1 NUMBER, c2 CLOB)


LOB (c2) STORE AS (CHUNK 32768);

 Chunk size is reported in DBA_LOB.CHUNK


 Chunk size is stored in SYS.LOB$.CHUNK
 Although chunk size is specified and reported in bytes, it is stored in
LOB$ in terms of tablespace blocks

3 © 2008 Julian Dyke juliandyke.com


Basic Files
Chunk Size
 Example 12 - 69237 byte LOB
 CHUNK = 8192 (default)
00 54 00 01 0 0c 0 00 0 01 00 00 0 01 0 00 0 00 8d ff
2 0 0 0 0 0
00 34 05 00 0 00 0 08 1 55 00 00 0 00 0 02 0 00 02 5f
0 0 0 0 0 1
01 00 02 060 00 0 5c 0 00 02 5d 0 00 0 5e 0 00 02 6e
 CHUNK = 32768 1(maximum)
2 1 1 2 1
01 00 02 6f 0 00 0 70 0 00 02 6a
tab 0, row 0, @0x1f38
1 2 1
tl: 54 fb: --H-FL-- lb: 0x2 cc: 2
col 0: [ 1] 80
col 1: [48]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 94 d5 00 1c 05 00 00
00 00 08 10 55 00 00 00 00 00 02 01 00 04 45 01 00 04 55 01 00 04 5d

00 54 00 01 0 0c 0 00 00 01 0 00 00 0 00 0 00 0 94 d5
2 0 0 1 0 0
00 1c 05 00 0 00 0 08 10 55 0 00 00 0 00 0 01 0 04 45
0 0 0 0 2 0
4 01
x 8132
00 =04
32528
55 0 2 x00
32528
0 =5d65056 0x1055 = 4181 65056 + 4181+ 69237
3 © 2008 Julian Dyke1 4 juliandyke.com
Basic Files
Chunk Size
 In Oracle 11.1 maximum LOB size is determined by chunk size:
CREATE TABLE t1 (
c1 NUMBER,
c2 CLOB,
c3 CLOB,
c4 CLOB
)
LOB (c2) STORE AS (CHUNK 8192),
LOB (c3) STORE AS (CHUNK 16384),
LOB (c4) STORE AS (CHUNK 32768);

SELECT
dbms_lob.getchunksize (c2), dbms_lob.get_storage_limit (c2),
dbms_lob.getchunksize (c3), dbms_lob.get_storage_limit (c3),
dbms_lob.getchunksize (c4), dbms_lob.get_storage_limit (c4)
FROM t1;

Chunk Size Storage Limit # Chunks


8132 34,926,674,042,940 4,294,967,29
5
16264 69,853,348,085,880 4,294,967,29
5

3 © 2008 Julian Dyke 32528 139,706,696,171,76


0
4,294,967,29
5
juliandyke.com
Basic Files
Read Consistency
 PCTVERSION clause
 Specifies the amount of space that will be used for the LOB consistent-
read mechanism
 Affects reclamation of old copies of LOB data
 Affects the ability to perform consistent read
 Range is 0 to 100
 Default value is 10

CREATE TABLE t4 (c1 NUMBER, c2 CLOB)


LOB (c2) STORE AS (PCTVERSION 20);

 Reported in DBA_LOB.PCTVERSION
 Can be set to 0 for read-only LOBs
 PCTVERSION should be set to a low value if:
 updates and reads are not concurrent
 the LOB is written once and then read-only
 PCTVERSION should be set to a high value if:
 there are large numbers of queries
 there is heavy read and write activity

3 © 2008 Julian Dyke juliandyke.com


Basic Files
Read Consistency
 Example 9 - 32768 byte LOB - update 4000 bytes starting at offset 10000
 PCTVERSION = 10 (default)

DECLARE
l_clob CLOB;
l_str VARCHAR2(4000);
BEGIN
l_str := LPAD ('Y',4000,'Y');

SELECT c2 INTO l_clob


FROM t19
WHERE c1 = 0;
FOR UPDATE;
DBMS_LOB.WRITE (l_clob,4000,10000,l_str);
END;
/

3 © 2008 Julian Dyke juliandyke.com


Basic Files
Read Consistency
 Example 9 (continued)
 Before Update

00 54 00 01 0 0c 0 00 00 01 00 00 0 01 0 00 00 00 93 45
2 0 0 0
00 24 05 00 0 00 0 04 00 f0 00 00 0 00 0 02 01 00 03 fd
0 0 0 0
 01After
00 03 fe 0
Update 00 0 ff 01 00 04 00 0 00 0 fc
1 3 1 3
tl: 62 fb: --H-FL-- lb: 0x1 cc: 2
col 0: [ 1] 80
col 1: [56]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 93 45 00 24 05 00 00
00 00 04 00 f0 00 00 00 00 00 03 01 00 03 fd 01 00 04 0f 01 00 03 ff 01 00
04 00 01 00 03 fc

00 54 00 01 0 0c 0 00 00 01 00 00 0 01 0 00 00 00 93 45
2 0 0 0
00 24 05 00 0 00 0 04 00 f0 00 00 0 00 0 02 01 00 03 fd
0 0 0 0
01 00 04 0f 0 00 0 ff 01 00 04 00 0 00 0 fc
1 Updated
3 Chunk 1 3
4 © 2008 Julian Dyke juliandyke.com
Basic Files
Read Consistency
 Example 9 (continued)

row#0[7982] flag: ------, lock: 2, len=50, data:(32):


01 00 03 fe 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00
col 0; len 10; (10): 00 01 49 14 f1 b7 00 00 00 00
col 1; len 4; (4): 01 00 03 fe

Key 00 01 4 14 fe c0 0 00 00 00 01 00 0 0f
9 0 3
Data 01 00 03 fe 0 00 0 00 00 00 0 00 00 0 00 00
0 0 0 0
00 00 00 00 0 00 0 00 00 00 0 00 00 0 00 00
0 0 0 0
LOB Index Free List

3FD 3FE
40F 3FF 400 3FC 3FE
LOB Data

4 STOP © 2008 Julian Dyke juliandyke.com


Basic Files
Read Consistency
 Example 10 - 32768 byte LOB - update 4000 bytes starting at offset 30000
 PCTVERSION = 10

DECLARE
l_clob CLOB;
l_str VARCHAR2(4000);
BEGIN
l_str := LPAD ('Y',4000,'Y');

SELECT c2 INTO l_clob


FROM t19
WHERE c1 = 0;
FOR UPDATE;
DBMS_LOB.WRITE (l_clob,4000,30000,l_str);
END;
/

4 © 2008 Julian Dyke juliandyke.com


Basic Files
Read Consistency
 Example 10 (continued)
 Before Update
00 54 00 01 0 0c 0 00 00 01 00 00 0 01 0 00 00 00 93 45
2 0 0 0
00 24 05 00 0 00 0 04 00 f0 00 00 0 00 0 02 01 00 03 fd
0 0 0 0
 01After
00 Update
04 0f 0 00 0 ff 01 00 04 00 0 00 0 fc
1 3 1 3
tl: 62 fb: --H-FL-- lb: 0x2 cc: 2
col 0: [ 1] 80
col 1: [56]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 93 45 00 24 05 00 00
00 00 04 05 bf 00 00 00 00 00 04 01 00 03 fd 01 00 04 0f 01 00 03 ff 01 00
03 fe 01 00 04 10

00 54 00 01 0 0c 0 00 00 01 00 00 0 01 0 00 00 00 93 45
2 0 0 0
00 24 05 00 0 00 0 04 05 bf 00 00 0 00 0 04 01 00 03 fd
0 0 0 0
01 00 04 0f 0 00 0 ff 01 00 03 fe 0 00 0 10
1
Updated
3
Chunk Updated 1Chunk 4
4 © 2008 Julian Dyke juliandyke.com
Basic Files
Read Consistency
 Example 10 (continued) - Lob Index

row#0[7982] flag: ------, lock: 2, len=50, data:(32):


01 00 03 fc 01 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00
col 0; len 10; (10): 00 01 49 14 fe c0 00 00 00 00
col 1; len 4; (4): 01 00 03 fc

Key 00 01 49 1 fe c 00 00 0 00 0 00 03 0f
4 0 0 1
Data 01 00 03 fc 0 00 0 00 00 00 0 00 00 0 00 00
1 4 0 0
00 00 00 00 0 00 0 00 00 00 0 00 00 0 00 00
0 0 0 0
LOB Index Free List

3FD 3FE
40F 3FF 400
3FE 3FC
410 3FC
3FE 400
LOB Data

4 STOP © 2008 Julian Dyke juliandyke.com


Basic Files
Partial Deletion
 Example 11 - 69237 byte LOB - Erase 18000 bytes from offset 12000

DECLARE
l_clob CLOB;
l_amount NUMBER := 18000;
BEGIN
SELECT c2 INTO l_clob
FROM t22
WHERE c1 = 0
FOR UPDATE;

DBMS_LOB.ERASE (l_clob,l_amount,12000);
END;

4 © 2008 Julian Dyke juliandyke.com


Basic Files
Partial Deletion
 Example 11 continued - 69237 byte LOB - Erase 18000 bytes from offset 12000
 Before ERASE
00 54 00 01 0 0c 0 00 0 01 00 00 0 01 0 00 0 00 95 6b
2 0 0 0 0 0
00 34 05 00 0 00 0 08 1 55 00 00 0 00 0 02 0 00 04 6d
0 0 0 0 0 1
01 00 04 6e 0 00 0 6f 0 00 04 70 0 00 0 6c 0 00 04 7f
 After ERASE 1 4 1 1 4 1
01 0,
tab 00row04 0,80 0
@0x1f20 00 0 7a 0 00 04 7b
tl: 78 fb: --H-FL--1lb: 0x1 4cc: 2 1
col 0: [ 1] 80
col 1: [72]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 95 6b 00 34 05 00 00
00 00 08 10 55 00 00 00 00 00 03 01 00 04 6d 01 00 04 7d 00 00 00 00 01 00
04 7e 01 00 04 6c 01 00 04 7f 01 00 04 80 01 00 04 7a 01 00 04 7b

00 54 00 01 0 0c 0 00 0 01 00 00 0 01 0 00 0 00 95 6b
2 0 0 0 0 0
00 34 05 00 0 00 0 08 1 55 00 00 0 00 0 03 0 00 04 6d
0 0 0 0 0 1

4
01 00 04
© 2008 Julian Dyke
0
7d 0 00 0
0
00 0
1
00 04 7e 0
1
00 0
4 juliandyke.com
6c 0
1
00 04 7f
Basic Files
Partial Deletion
 Example 11 continued - 69237 byte LOB - Erase 18000 bytes from offset 12000
 After ERASE - Lob Index

row#0[7982] flag: ------, lock: 2, len=50, data:(32):


01 00 04 6e 01 00 04 6f 01 00 04 70 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00
col 0; len 10; (10): 00 01 49 15 3a 62 00 00 00 0
col 1; len 4; (4): 01 00 04 6e

01 00 04 6e 0 00 0 6f 01 00 0 70 00 0 00 00
Data 1 4 4 0
00 00 00 00 0 00 0 00 00 00 0 00 00 0 00 00
0 LOB Index
0 0 0 Free List

46D 46E
47D 46F 470
47E 46C 47F 480 47A 47B 46E 46F 470

LOB Data

4 STOP © 2008 Julian Dyke juliandyke.com


Basic Files
CACHE Clause
 Specifies whether a LOB will be stored in the database buffer cache when
values are read and written.
 Allows LOB values to be shared amongst users.
 Possible values are CACHE, CACHE READS and NOCACHE
 Default value is NOCACHE

CREATE TABLE t4 (c1 NUMBER, c2 CLOB)


LOB (c2) STORE AS (CACHE);

CREATE TABLE t4 (c1 NUMBER, c2 CLOB)


LOB (c2) STORE AS (CACHE READS);

CREATE TABLE t4 (c1 NUMBER, c2 CLOB)


LOB (c2) STORE AS (NOCACHE);

 Reported in DBA_LOB.CACHE
 Can be NO, CACHEREADS or YES

4 © 2008 Julian Dyke juliandyke.com


Basic Files
CACHE versus NOCACHE
 CACHE LOGGING

Top 5 Timed Events Avg %Total


~~~~~~~~~~~~~~~~~~ wait Call
Event Waits Time (s) (ms) Time Wait Class
------------------------------ -------- ----------- ------ ------ ----------
CPU time 558 72.6
log file sync 79,335 210 3 27.2 Commit
log file parallel write 66,613 102 2 13.4 System I/O
SQL*Net more data from client 37,857 19 1 2.6 Network
db file parallel write 5,281 11 2 1.4 System I/O

 NOCACHE NOLOGGING

Top 5 Timed Events Avg %Total


~~~~~~~~~~~~~~~~~~ wait Call
Event Waits Time (s) (ms) Time Wait Class
------------------------------ -------- ----------- ------ ------ ----------
enq: CF - contention 6,211 877 141 22.1 Other
CPU time 300 7.6
log file sync 69,297 171 2 4.3 Commit
control file parallel write 31,126 154 5 3.9 System I/O
log file parallel write 60,083 94 2 2.4 System I/O

4 © 2008 Julian Dyke juliandyke.com


Basic Files
LOGGING
 Possible values are LOGGING (default) and NOLOGGING
 If CACHE option is specified then LOGGING is mandatory
 LOGGING/NOLOGGING cannot be specified without CACHE clause

CREATE TABLE t4 (c1 NUMBER, c2 CLOB)


LOB (c2) STORE AS (CACHE LOGGING);

CREATE TABLE t4 (c1 NUMBER, c2 CLOB)


LOB (c2) STORE AS (CACHE READS LOGGING);
CREATE TABLE t4 (c1 NUMBER, c2 CLOB)
LOB (c2) STORE AS (CACHE READS NOLOGGING);
CREATE TABLE t4 (c1 NUMBER, c2 CLOB)
LOB (c2) STORE AS (NOCACHE LOGGING);
CREATE TABLE t4 (c1 NUMBER, c2 CLOB)
LOB (c2) STORE AS (NOCACHE NOLOGGING);
 Reported in DBA_LOB.LOGGING
 Can be NO or YES

5 © 2008 Julian Dyke juliandyke.com


Basic Files
LOB Compression
 LOBs can be compressed using the LZ_COMPRESS procedure in the
UTL_COMPRESS package

 A quality can be specified File size in bytes


 1 - Fastest Quality dbms_stats.ls alert.log
 9 - Slowest t
 The default quality is 6 Uncompresse 69237 1889203
d
1 14408 868037
 Compression achieved is
not very consistent 2 14121 694521
3 14067 500580
4 14718 1185502
5 14574 1175025
6 14383 1167914
7 14347 1167769
8 14303 1167240
9 14303 1167238

5 © 2008 Julian Dyke juliandyke.com


Basic Files
LOB Compression
CREATE DIRECTORY dir1 AS '/tmp';
 Example DECLARE
CREATE TABLE t34 (c1 NUMBER, c2 CLOB);
l_bfile BFILE;
INSERT INTO t34 VALUES (0,EMPTY_CLOB ());
l_blob BLOB;
l_clob CLOB;
l_length NUMBER;
l_quality NUMBER := 1;
l_dest_offset NUMBER := 1;
l_source_offset NUMBER := 1;
l_blob_csid NUMBER := DBMS_LOB.DEFAULT_CSID;
l_lang_context NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
l_warning NUMBER;
BEGIN
l_bfile := BFILENAME ('DIR1','alert.log');
DBMS_LOB.OPEN (l_bfile);
DBMS_LOB.CREATETEMPORARY (l_blob,FALSE);
l_length := DBMS_LOB.GETLENGTH (l_bfile);
UTL_COMPRESS.LZ_COMPRESS (l_bfile,l_blob,l_quality);
SELECT c2 INTO l_clob FROM t34 WHERE c1 = 0 FOR UPDATE;
DBMS_LOB.CONVERTTOCLOB (l_clob,l_blob,DBMS_LOB.LOBMAXSIZE,
l_dest_offset,l_source_offset,l_blob_csid,l_lang_context,l_warning);
END;
5 © 2008 Julian Dyke juliandyke.com
Secure
Files

5 © 2008 Julian Dyke juliandyke.com


Secure Files
Overview
 In Oracle 11.1 and above there are two types of LOB
 STORE AS BASICFILE (default)
 STORE AS SECUREFILE

 STORE AS BASICFILE
 Default
 Behaves as Oracle 10.2 and below

 STORE AS SECUREFILE
 Oracle 11.1 and above
 Supports several new features including
 LOB compression
 LOB encryption
 LOB deduplication
 Metadata only logging
 Configurable retention time

5 © 2008 Julian Dyke juliandyke.com


SecureFiles
Storage
 Can only be created in an ASSM tablespace

 New block types supporting SecureFiles include:

Description Block Type


NGLOB: Extent Map 0x3c
NGLOB: Hash Bucket 0x3d
NGLOB: Committed Free Space 0x3e
NGLOB: Segment Header 0x3f
NGLOB: Lob Extent Header 0x40
NGLOB: Persistent Undo 0x41

 LOB Data Segments are still stored in blocks of type trans_data (block type 6)

 Note
 CHUNK is advisory - only maintained for backward compatibility
 PCTVERSION not supported - use RETENTION instead

5 © 2008 Julian Dyke juliandyke.com


Secure File
Initialization
 EMPTY_CLOB ()
 Basic File

00 54 0 01 0 0c 0 00 0 01 0 00 0 01 0 00 00 0 89 3d
0 2 0 0 0 0 0 0
00 10 0 00 0 00 0 00 0 00 0 00 0 00 0 00
9 0 0 0 0 0 0
 Secure File
tl: 36 fb: --H-FL-- lb: 0x1 cc: 2
col 0: [ 1] 80
col 1: [30]
00 54 00 01 02 0c 00 80 00 01 00 00 00 01 00 00 00 00 99 53 00 0a 48 90 00
04 00 00 00 00

00 54 00 01 0 0c 0 80 0 01 00 00 0 01 0 00 00 0 99 53
2 0 0 0 0 0
00 0a 48 90 0 04 0 00 0 00
0 0 0

5 © 2008 Julian Dyke juliandyke.com


Secure File
LOB Locator
 Example DBMS_STATS.LST - 69237 bytes
 Basic File
00 54 0 01 02 0 00 0 00 01 0 00 00 0 00 0 00 0 8d ff
0 c 0 0 1 0 0
00 34 0 00 00 0 00 0 10 55 0 00 00 0 00 0 01 0 02 5f
5 0 8 0 0 2 0
01 000 60 01 0 02 5 01 00 0 5d 01 0 02 5 01 0 02 6e
 Secure File
2 0 c 2 0 e 0
01tl: 00 0 --H-FL--
57 fb: 6f 01 lb:
0 0x2
02 cc:
7 2 01 00 0 6a
col 0: 2[ 1] 80 0 0 2
col 1: [51]
00 54 00 01 02 0c 00 80 00 01 00 00 00 01 00 00 00 00 98 8b 00 1f 40 90 00
19 22 00 01 0e 75 01 02 01 01 00 05 6d 04 01 01 00 05 80 01 01 01 00 05 82
04

00 54 0 01 02 0c 0 80 0 01 00 00 0 01 0 00 00 0 98 8b
0 0 0 0 0 0
00 1f 4 90 00 19 2 00 0 0e 75 01 0
0 2 1 20x10E75 = 69237
01 01 0 05 6d 04 # Blocks in extent
0
5 © 2008
01 01Julian
0 Dyke
05 80 01DBA of first block in extent juliandyke.com
Secure Files
Lob Blocks
 Out-of-line LOB data is stored in a trans data block (block type 6)
 Each block has
 a 128 byte header
 a 4 byte trailer
 For example for a 8192 byte block

Header
128 bytes

LOB Data
8060 bytes

Trailer
4 bytes

5 © 2008 Julian Dyke juliandyke.com


Secure Files
LOB Compression
 Oracle 11.1 and above

 Enables server-side LOB compression


 Random read/write access is still possible
 Independent of table compression / index compression
 Only valid for SecureFile LOBs

 Valid values are


 COMPRESS <defaults to MEDIUM>
 COMPRESS MEDIUM
 COMPRESS HIGH
 NOCOMPRESS <default>

 COMPRESS MEDIUM
 Faster (less resource)
 COMPRESS HIGH
 Better compression (less storage)

 Individual LOBs can be compressed using DBMS_LOB.SETOPTIONS ()

5 © 2008 Julian Dyke juliandyke.com


Secure Files
LOB Compression
 Compressed size of LOB is not reported in Oracle 11.1

 To calculate compressed size count number of extents


 In block dump
 Using DBMS_LOBUTIL.GETINODE

 Size will be an (over) estimate

 Example - alert.log - sizes in bytes

Uncompressed Size 1899203


COMPRESS MEDIUM 72540
COMPRESS HIGH 40300

 SecureFile LOB Compression much better than UTLCOMPRESS package


 For example best compression achieved for same file using
LZ_COMPRESS was 500580 bytes

6 © 2008 Julian Dyke juliandyke.com


Secure Files
DBMS_LOBUTIL
 Unsupported package that describes SecureFile LOBs

 Defined in $ORACLE_HOME/rdbms/admin/dbmslobu.sql

 Subroutines include
 GETINODE
 GETLOBMAP
 GETEXTENTS

 GETINODE
 Reports LOB header
 GETLOBMAP
 Reports LOB extent header
 Numeric parameter is extent number (0..N-1)
 GETEXTENTS
 Reports LOB extents in more detail
 Pipelined function - takes REF CURSOR as parameter

6 © 2008 Julian Dyke juliandyke.com


Secure Files
DBMS_LOBUTIL
DECLARE
l_clob CLOB;
l_inode DBMS_LOBUTIL_INODE_T;
l_lobmap DBMS_LOBUTIL_LOBMAP_T;
BEGIN
SELECT c2 INTO l_clob FROM t29
WHERE c1 = 0 FOR UPDATE;
l_inode := DBMS_LOBUTIL.GETINODE (l_clob);
DBMS_OUTPUT.PUT_LINE ('LOBID '||RAWTOHEX (l_inode.lobid));
DBMS_OUTPUT.PUT_LINE (' flags '||l_inode.flags);
DBMS_OUTPUT.PUT_LINE (' length '||l_inode.length);
DBMS_OUTPUT.PUT_LINE (' version '||l_inode.version);
DBMS_OUTPUT.PUT_LINE (' extents '||l_inode.extents);
FOR i IN 0..l_inode.extents - 1
LOOP
l_res := DBMS_LOBUTIL.GETLOBMAP (l_clob,i);
DBMS_OUTPUT.PUT_LINE ('Extent# '||i);
DBMS_OUTPUT.PUT_LINE (' rdba '||l_res.rdba);
DBMS_OUTPUT.PUT_LINE (' nblks '||l_res.nblks);
DBMS_OUTPUT.PUT_LINE (' offset '||l_res.offset);
DBMS_OUTPUT.PUT_LINE (' length '||l_res.length);
END LOOP;
END;

6 © 2008 Julian Dyke juliandyke.com


References
 Oracle Database Application Developer's Guide - Large Objects
10g Release 2 (10.2) - Part Number B14249-01

 Oracle Database SecureFiles and Large Objects Developers Guide


11g Release 1 (11.1) - Part Number B28393-03

6 © 2008 Julian Dyke juliandyke.com


Any Questions ?

info@juliandyke.com

6 © 2008 Julian Dyke juliandyke.com

S-ar putea să vă placă și