Estimating potential storage savings before changing LOB storage is not a new capability. The Compression Advisor (DBMS_COMPRESSION), included with Oracle Database Enterprise Edition, has long supported compression-ratio estimation for tables, indexes, and LOBs. Oracle Database 23ai added DBMS_LOB.GET_LOB_DEDUPLICATION_RATIO to estimate potential storage savings from LOB deduplication.
What is new in Oracle AI Database 26ai (Release Update 23.26.1) is the dedicated DBMS_SECUREFILES package, which provides GET_LOB_COMPR_RATIO and GET_LOB_DEDUPLICATION_RATIO functions for estimating SecureFiles LOB compression and deduplication savings.
The DBMS_SECUREFILES package provides two functions:
GET_LOB_COMPR_RATIO: Estimates the potential compression ratio for a SecureFiles LOB column.
GET_LOB_DEDUPLICATION_RATIO: Estimates the potential storage savings from SecureFiles LOB deduplication.
In this article, I will use a table containing 90,000 CLOB records to demonstrate both functions, apply the corresponding SecureFiles storage options, and compare the resulting segment sizes.
1. Creating and Populating the Test Table
First, create a table with a SecureFiles CLOB column:
SQL> CREATE TABLE vahid.document_store ( document_id NUMBER PRIMARY KEY, document_content CLOB ) LOB (document_content) STORE AS SECUREFILE ( NOCACHE ); Table created. Next, insert 90,000 CLOB rows. The dataset contains three distinct CLOB values: 70,000 rows with the first value, 10,000 with the second, and 10,000 with the third. Each CLOB contains 32,767 characters.
DECLARE l_content VARCHAR2(32767); BEGIN FOR i IN 1 .. 90000 LOOP IF i <= 70000 THEN l_content := RPAD( 'Vahid Yousefzadeh: Oracle DBMS_SECUREFILES Package', 32767, 'A' ); ELSIF i <= 80000 THEN l_content := RPAD( 'Vahid Yousefzadeh: Oracle Database Administration', 32767, 'B' ); ELSE l_content := RPAD( 'Oracle AI Database 26ai: SecureFiles LOB Deduplication', 32767, 'C' ); END IF; INSERT INTO vahid.document_store VALUES (i, l_content); END LOOP; COMMIT; END; / PL/SQL procedure successfully completed. Elapsed: 00:09:31.37 2. Estimating and Applying SecureFiles Deduplication
Before enabling deduplication or compression, check the initial LOB segment size:
SQL> select segment_name from dba_lobs where table_name='DOCUMENT_STORE'; SEGMENT_NAME --------------------------------- SYS_LOB0000073951C00002$$ SQL> select blocks,round(bytes/1024/1024) SIZE_MB from dba_segments where segment_name='SYS_LOB0000073951C00002$$'; BLOCKS SIZE_MB ---------- ---------- 860192 6720 Its initial size was approximately 6,720 MB, occupying 860,192 blocks.
Next, use GET_LOB_DEDUPLICATION_RATIO to estimate the potential storage savings:
Required Role: The SECUREFILE_MONITOR role is required to execute GET_LOB_DEDUPLICATION_RATIO.
SQL> SET SERVEROUTPUT ON; SQL> DECLARE l_dedup_ratio NUMBER; BEGIN l_dedup_ratio := DBMS_SECUREFILES.GET_LOB_DEDUPLICATION_RATIO( tablespacename => 'USERS', tabowner => 'VAHID', tabname => 'DOCUMENT_STORE', lobcolumnname => 'DOCUMENT_CONTENT', partname => NULL, dedup_ratio => l_dedup_ratio, subset_numrows => 90000 ); DBMS_OUTPUT.PUT_LINE( 'Estimated Deduplication Ratio: ' || l_dedup_ratio ); END; / Estimated Deduplication Ratio: 30000 PL/SQL procedure successfully completed. The function returned a deduplication ratio of 30,000, meaning the non-deduplicated LOB data is estimated to be about 30,000 times larger than the deduplicated data. This matches the test data: 90,000 CLOB rows with only three distinct values (90,000 ÷ 3 = 30,000).
After obtaining the estimate, enable deduplication on the LOB column:
SQL> ALTER TABLE VAHID.DOCUMENT_STORE MOVE LOB(DOCUMENT_CONTENT) STORE AS SECUREFILE(DEDUPLICATE); Table altered. Elapsed: 00:00:55.59 After the operation, the LOB segment size was approximately:
SQL> select blocks,round(bytes/1024/1024) SIZE_MB from dba_segments where segment_name='SYS_LOB0000073951C00002$$'; BLOCKS SIZE_MB ---------- ---------- 160 1 Compared with the original segment size of approximately 6,720 MB, this represents a substantial reduction.
3. Estimating and Applying SecureFiles Compression The second function, GET_LOB_COMPR_RATIO, estimates the potential compression ratio for a SecureFiles LOB column. It also provides information about block compression, estimated processing time, and the number of sampled LOBs.
For this test, I will reuse the VAHID.DOCUMENT_STORE table and the same 90,000 CLOB records created in the previous section.
The GET_LOB_COMPR_RATIO function has a COMPTYPE parameter that specifies the SecureFiles compression level to be evaluated:
1: LOW
2: MEDIUM
3: HIGH
The following example uses MEDIUM compression and samples 1,000 LOBs:
SET SERVEROUTPUT ON; DECLARE l_return_value NUMBER; l_comp_ratio NUMBER; l_block_comp_ratio NUMBER; l_total_time NUMBER; l_blkcnt_uncmp BINARY_INTEGER; l_blkcnt_cmp BINARY_INTEGER; l_lobcnt BINARY_INTEGER; BEGIN l_return_value := DBMS_SECUREFILES.GET_LOB_COMPR_RATIO( tablespacename => 'USERS', tabowner => 'VAHID', tabname => 'DOCUMENT_STORE', lobcolumnname => 'DOCUMENT_CONTENT', partname => NULL, comp_ratio => l_comp_ratio, subset_numrows => 1000, block_compr_ratio => l_block_comp_ratio, total_time => l_total_time, comptype => 2, blkcnt_uncmp => l_blkcnt_uncmp, blkcnt_cmp => l_blkcnt_cmp, lobcnt => l_lobcnt ); DBMS_OUTPUT.PUT_LINE('Compression Ratio : ' || l_comp_ratio); DBMS_OUTPUT.PUT_LINE('Block Compression Ratio: ' || l_block_comp_ratio); DBMS_OUTPUT.PUT_LINE('Estimated Time (Hours) : ' || l_total_time); DBMS_OUTPUT.PUT_LINE('Uncompressed Blocks : ' || l_blkcnt_uncmp); DBMS_OUTPUT.PUT_LINE('Compressed Blocks : ' || l_blkcnt_cmp); DBMS_OUTPUT.PUT_LINE('Sampled LOBs : ' || l_lobcnt); DBMS_OUTPUT.PUT_LINE('Function Return Value : ' || l_return_value); END; / Compression Ratio : 167.73787241866 Block Compression Ratio: 9 Estimated Time (Hours) : .003915217434509905109984739086395400202222 Uncompressed Blocks : 731769 Compressed Blocks : 81308 Sampled LOBs : 1000 Function Return Value : 167.73787241866 PL/SQL procedure successfully completed. The output provides several useful metrics:
Compression Ratio (167.74): The ratio of the original data size in bytes to the compressed data size in bytes. The sampled data is estimated to be about 167.74 times larger than its compressed form, or about 99.4% estimated space savings.
Block Compression Ratio (9): The number of blocks used by the uncompressed sample divided by the number of blocks used by the compressed sample. It is much lower than the byte-level ratio because space is allocated in whole blocks, so the block-level figure is the more conservative of the two.
Estimated Time (0.0039 hours): An estimate, in hours, of the time needed to compress the LOB data in the table. This is about 14.1 seconds. Treat it as a rough indication only.
Sampled LOBs (1,000): The number of LOBs actually sampled to estimate the compression ratio.
Function Return Value (167.74): In this run it was identical to comp_ratio.
The unusually high compression ratio comes from the test data, not from typical behavior. Each CLOB is a short text followed by tens of thousands of identical padding characters.
After obtaining the estimate, apply MEDIUM compression to the LOB column:
SQL> ALTER TABLE VAHID.DOCUMENT_STORE MOVE LOB (DOCUMENT_CONTENT) STORE AS SECUREFILE (COMPRESS MEDIUM); Table altered. Elapsed: 00:00:29.95 After the operation, the LOB segment occupied:
SQL> select blocks,round(bytes/1024/1024) SIZE_MB from dba_segments where segment_name='SYS_LOB0000073958C00002$$'; BLOCKS SIZE_MB ---------- ---------- 32 0 The segment size was less than 1 MB. This avoids displaying a rounded size of zero for a segment that still occupies storage.
