Oracle 21c New Feature - Automatic SecureFiles Defragmentation

This blog post explores a new feature in Oracle 21c related to SecureFiles LOB objects.  

As you know, Oracle provides the BLOB and CLOB data types to store large objects inside the database, and the BFILE data type to reference large objects stored outside the database.  Oracle's BLOB and CLOB data types support two formats: BasicFiles and SecureFiles.  Each format also has its own driver within the Oracle stack.  The primary API for working with either BasicFiles or SecureFiles LOBs is DBMS_LOB.

The BasicFiles format was first introduced in Oracle 8.0 and is still supported today but is not the preferred format.  The SecureFiles format was introduced in Oracle 11g and is the preferred format today because it is more efficient, more performant, and offers high-end features like compression, deduplication, and encryption. 

Starting with Oracle 12c R1, all new BLOB and CLOB columns are created as SecureFiles unless you specifically request the BasicFiles format.  This behavior is controlled by parameter DB_SECUREFILE.

SecureFiles have always supported compression, deduplication, and encryption.  These are generally considered to be extra-cost features since compression and deduplication of LOBs requires a license for the Oracle Advanced Compression Option, and encryption of LOBs requires a license for the Oracle Advanced Security Option.  Using SecureFiles LOBs is otherwise free.

LOB data can get fragmented over time.  Gaps open between fragments of the data, and fragments can also be stored out-of-order.  This can have a serious negative impact on LOB performance.

Defragmenting a LOB prior to Oracle 21c required moving the LOB.  A complete re-write of the LOB in a new location ensured it would be defragmented.  However, that was an expensive operation in terms of time and I/O, and the LOB was offline to users during the entire operation.

Starting with Oracle 21c, Automatic SecureFiles Defragmentation provides online defragmentation of allocated and freed space in SecureFiles segments.  The work occurs automatically using a background process that is transparent to users.  The only thing you should notice when it is running is the allocation of temp segments, and these temp segments are released once the operation completes.

Automatic SecureFiles Defragmentation uses the Oracle Segment Advisor to determine when a LOB segment needs to be defragmented.

You may also run the defrag manually.  Oracle 21c offers two newly modified SQL statements:

  • To defragment a specific LOB:

ALTER TABLE <TABLE_NAME> MODIFY LOB (<LOB_COLUMN_NAME>) (SHRINK SPACE);

  • To defragment all LOBs of a given table:

ALTER TABLE <TABLE_NAME> SHRINK SPACE CASCADE;

Automatic SecureFiles Defragmentation works with all SecureFiles LOBs including those using Oracle Partitioning, compression, de-duplication, and encryption

To monitor defrag operations, just query the view V$SECUREFILE_SHRINK.  Each defrag operation adds a row to this view.  The row is periodically updated as the defrag operation runs.

Comments

Popular posts from this blog

Using DBGen to Generate TPC-H Test Data

Oracle 21c Caching Solutions

TPC-like Database Benchmarking Tools