18 Using DBFS

The DBFS File System implementation includes creating and accessing the file system and managing it.

18.1 Enabling Advanced SecureFiles LOB Features for DBFS

Using the @dbfs_create_filesystem.sql command, you can create a partitioned or non-partitioned file system with the compression and deduplicate options. If you want to specify additional options while creating the file system, use the DBMS_DBFS_SFS.CREATEFILESYSTEM procedure.

For information about all the additional options that you can use with the DBMS_DBFS_SFS.CREATEFILESYSTEM procedure, see CREATEFILESYSTEM Procedure in PL/SQL Packages and Types Reference.

Use the @dbfs_create_filesystem.sql command to quickly create, register, and mount a file system. When you use the DBMS_DBFS_SFS.CREATEFILESYSTEM procedure to enable additional options while creating a file system, you must additionally run commands to register and mount the file system that you create.

Let's use the DBMS_DBFS_SFS.CREATEFILESYSTEM procedure to create a file system with the encryption option.

Before you begin, ensure that you have created a wallet with the encryption key. See Administer Key Management in SQL Language Reference.

To create a file system with the encryption option:

  1. Run the following command.

    Syntax

    exec dbms_dbfs_sfs.createFilesystem('store_name',tbl_tbs=>'tablespace_name',do_encrypt=> true | false,encryption=> encryption_type, do_dedup=> true | false,do_compress=>true | false);

    For reference information about the command options, see CREATEFILESYSTEM Procedure in PL/SQL Packages and Types Reference.

    Example

    For example, to create a file system in Test3 store in the test_fs1 tablespace with the default encryption, compression, and deduplicate options:

    exec dbms_dbfs_sfs.createFilesystem('test_fs1', tbl_tbs=>'Test3', do_encrypt=>true, encryption=>dbms_dbfs_sfs.ENCRYPTION_DEFAULT, do_dedup=>true, do_compress=>true);

    The file system is created with the option you have specified.

  2. Run the following command to register the file system that you have created.

    Syntax

    dbms_dbfs_content.registerStore(store_name => 'filesystem_name', provider_name => 'posix',provider_package => 'dbms_dbfs_sfs') ;

    Example

    For example, run the following command to register the test_fs1 file system.

    dbms_dbfs_content.registerStore(store_name => 'test_fs1', provider_name => 'posix', provider_package => 'dbms_dbfs_sfs') ;
  3. Run the following command to mount the file system that you have created.

    Syntax

    dbms_dbfs_content.mountStore(store_name  => 'filesystem_name', store_mount => 'filesystem_name');

    Example

    For example, run the following command to mount the test_fs1 file system.

    dbms_dbfs_content.mountStore(store_name  => 'test_fs1', store_mount => 'test_fs1');

18.2 Dropping a File System

You can drop a file system by running DBFS_DROP_FILESYSTEM.SQL.

Caution:

When you drop a file system, it deletes all the files and associated metadata. You won't be able to access the files.
  1. Log in to the database instance:
    $ sqlplus dbfs_user/@db_server
    
  2. Enter the following command:
    @$ORACLE_HOME/rdbms/admin/dbfs_drop_filesystem.sql file_system_name
    

When you drop a file system, it deletes all the files and associated metadata. You won't be able to access the files. If you want to access the file system after dropping a DBFS, you can restore the file system from a database backup or file system backup.

Depending on the backup policy in your organization, you may have a database backup or file system backup. To restore from a database backup, you'll have to restore the entire database and then use the restored file system. To restore the file system from a file system backup, create a new DBFS and restore the file system from the file system backup.