18.6 Shrinking and Reorganizing DBFS Filesystems

DBFS uses Online File system Reorganization to shrink itself, enabling the release of allocated space back to the containing tablespace.

18.6.1 About Changing DBFS File Systems

DBFS file systems, like other database segments, grow dynamically with the addition or enlargement of files and directories.

Growth occurs with the allocation of space from the tablespace that holds the DBFS file system to the various segments that make up the file system.

However, even if files and directories in the DBFS file system are deleted, the allocated space is not released back to the containing tablespace, but continues to exist and be available for other DBFS entities. A process called Online Filesystem Reorganization solves this problem by shrinking the DBFS Filesystem.

The DBFS Online Filesystem Reorganization utility internally uses the Oracle Database online redefinition facility, with the original file system and a temporary placeholder corresponding to the base and interim objects in the online redefinition model.

See Also:

Oracle Database Administrator's Guide for further information about online redefinition

18.6.2 Advantages of Online Filesystem Reorganization

DBFS Online Filesystem Reorganization is a powerful data movement facility with these certain advantages.

These are:

  • It is online: When reorganization is taking place, the filesystem remains fully available for read and write operations for all applications.

  • It can reorganize the structure: The underlying physical structure and organization of the DBFS filesystem can be changed in many ways, such as:

    • A non-partitioned filesystem can be converted to a partitioned filesystem and vice-versa.

    • Special SecureFiles LOB properties can be selectively enabled or disabled in any combination, including the compression, encryption, and deduplication properties.

    • The data in the filesystem can be moved across tablespaces or within the same tablespace.

  • It can reorganize multiple filesystems concurrently: Multiple different filesystems can be reorganized at the same time, if no temporary filesystems have the same name and the tablespaces have enough free space, typically, twice the space requirement for each filesystem being reorganized.

18.6.3 Determining Availability of Online Filesystem Reorganization

DBFS for Oracle Database 12c and later supports online filesystem reorganization. Some earlier versions also support the facility.

To determine if your version does, query for a specific function in the DBFS PL/SQL packages, as shown below:

  • Query for a specific function in the DBFS PL/SQL packages.

$ sqlplus / as sysdba
SELECT * FROM dba_procedures
WHERE   owner = 'SYS'
    and object_name = 'DBMS_DBFS_SFS'
    and procedure_name = 'REORGANIZEFS';

If this query returns a single row similar to the one in this output, the DBFS installation supports Online Filesystem Reorganization. If the query does not return any rows, then the DBFS installation should either be upgraded or requires a patch for bug-10051996.

 
OWNER
----------------------------------------------------------------------------------
OBJECT_NAME
----------------------------------------------------------------------------------
PROCEDURE_NAME
----------------------------------------------------------------------------------
OBJECT_ID|SUBPROGRAM_ID|OVERLOAD                                |OBJECT_TYPE  |AGG|PIP
----------|-------------|-----------------------------------|-------------|---|---
IMPLTYPEOWNER
----------------------------------------------------------------------------------
IMPLTYPENAME
----------------------------------------------------------------------------------
PAR|INT|DET|AUTHID
---|---|---|------------
SYS
DBMS_DBFS_SFS
REORGANIZEFS
     11424|           52|(null)                                  |PACKAGE      |NO |NO
(null)
(null)
NO |NO |NO |CURRENT_USER

18.6.4 Required Permissions for Online Filesystem Reorganization

Database users must have the following set of privileges for Online Filesystem Reorganizaton.

Users must have these privileges:

  • ALTER ANY TABLE
  • DROP ANY TABLE
  • LOCK ANY TABLE
  • CREATE ANY TABLE
  • SELECT ANY TABLE
  • REDEFINE ANY TABLE
  • CREATE ANY TRIGGER
  • CREATE ANY INDEX
  • CREATE TABLE
  • CREATE MATERIALIZED VIEW
  • CREATE TRIGGER

18.6.5 Invoking Online Filesystem Reorganization

You can perform an Online Filesystem Reorganization by creating a temporary DBFS filesystem.

Note:

Ensure that you don't create the temporary DBFS filesystem in the SYS schema. DBFS Online Filesystem Reorganization will not work if you create the temporary DBFS filesystem in the SYS schema.
  1. Create a temporary DBFS filesystem with the desired new organization and structure: including the desired target tablespace (which may be the same tablespace as the filesystem being reorganized), desired target SecureFiles LOB storage properties (compression, encryption, or deduplication), and so on.
  2. Invoke the PL/SQL procedure to reorganize the DBFS filesystem using the newly-created temporary filesystem for data movement.
  3. Once the reorganization procedure completes, drop the temporary filesystem.

The example below reorganizes DBFS filesystem FS1 in tablespace TS1 into a new tablespace TS2, using a temporary filesystem named TMP_FS, where all filesystems belong to database user dbfs_user:

$ cd $ORACLE_HOME/rdbms/admin
$ sqlplus dbfs_user/***
 
@dbfs_create_filesystem TS2 TMP_FS
EXEC DBMS_DBFS_SFS.REORGANIZEFS('FS1', 'TMP_FS');
@dbfs_drop_filesystem TMP_FS
QUIT;

where:

  • TMP_FS can have any valid name. It is intended as a temporary placeholder and can be dropped (as shown in the example above) or retained as a fully materialized point-in-time snapshot of the original filesystem.

  • FS1 is the original filesystem and is unaffected by the attempted reorganization. It remains usable for all DBFS operations, including SQL, PL/SQL, and dbfs_client mounts and commandline, during the reorganization. At the end of the reorganization, FS1 has the new structure and organization used to create TMP_FS and vice versa (TMP_FS will have the structure and organization originally used for FS1). If the reorganization fails for any reason, DBFS attempts to clean up the internal state of FS1.

  • TS2 needs enough space to accommodate all active (non-deleted) files and directories in FS1.

  • TS1 needs at least twice the amount of space being used by FS1 if the filesystem is moved within the same tablespace as part of a shrink.