Friday, December 13, 2024

Overview of DBMS_FS package To Managing File Systems into Oracle

 Overview of DBMS_FS package :

The DBMS_FS package for performing operations on an Oracle file system (make, mount, unmount and destroy operations) in an Oracle database.


              Alireza Kamrani 

                12/14/2024


This chapter contains the following topics:

  • DBMS_FS Overview
  • DBMS_FS Security Model
  • Summary of DBMS_FS Subprograms


DBMS_FS Overview

The DBMS_FS package contains Oracle file system (OFS) procedures that you can use to create, mount, unmount, and destroy an Oracle file system.

Starting 19c release, the file systems are supported by PDB. 


Oracle Database supports maximum 5 file systems per PDB and 1000 file systems in total.


The DBMS_FS package enables applications to access database objects from a universal client such as an NFS server. 

This feature interfaces with Oracle SecureFiles to provide the file system access. 


DBMS_FS Security Model

You must have the SYSDBA administrative privilege to use the DBMS_FS package. 

The operations that you perform using the DBMS_FS package are equivalent to the file system operations that are performed in an operating system by the root user. 


Access to the individual file system that is created and mounted by this package is enforced using Access Control Lists (ACLs) and the permissions on the mounted directories to the operating system user.


Example:

The following sample code shows how to check if a file system exists with the specified file system name, data.


SQL> declare

     fsname varchar2(64) := 'data';

     fsexists integer;

     

 begin

 fs_exists := dbms_fs.fs_exists(fsname);

 dbms_output.put_line('fs exists: ' || fsexists);

 end;

     /


SQL> select dbms_fs.fs_exists('data') from dual; 


The following sample code shows how to list all the files within a specified directory in a file system.


SQL> select * from DBMS_FS.LIST_FILES ('data', '/') from dual;


Where, the path to the directory ('/') is relative to the mount path.


Usage Notes:

If you want to create a database file system (DBFS), then you must run the dbfs_create_filesystem.sql script, which in turn calls the dbfs_create_filesystem_advanced.sql script. 

By default, this script is in the $ORACLE_HOME/rdbms/admindirectory. 


When you run this script, provide the name of an existing tablespace and a name for the file system that will be stored in the database. The size of the file system will be the same as the table size.


For example, to create a file system in the dbfs_ts tablespace, in the file system dbfs_tab:

@/$ORACLE_HOME/rdbms/admin/dbfs_create_filesystem.sql dbfs_ts dbfs_tab

After you run this script, you can use the other procedures in the DBMS_FS package to mount, unmount, and destroy the file system. 

Note:

Staring Oracle Database 19.3.1.0 release, the DBMS_FS.MAKE_ORACLE_FS is used to create a DBFS filesystem; hence no auxiliary SQL script is needed to create a DBFS filesystem.


Running the DBMS_FS.MAKE_ORACLE_FS procedure on the database instance is equivalent to running the mkfs command by root in an operating system. 


The tablespace that you specified in the fsoptions parameter must already exist before you execute the DBMS_FS.MAKE_ORACLE_FS procedure. 

To find existing tablespaces, query the DBA_TABLESPACES data dictionary view.


The size of the file system is the same size as this tablespace. 


Example:

The following example shows how to create a DBFS file system named dbfs_fs1 in the tablespace dbfs_fs1_tbspc.


BEGIN

 DBMS_FS.MAKE_ORACLE_FS (

  fstype           => 'dbfs',

  fsname           => 'dbfs_fs1',

  fsoptions        => 'TABLESPACE=dbfs_fs1_tbspc');

END;

/


MOUNT_ORACLE_FS Procedure

Use the dbms_fs.mount_oracle_fs() procedure to mount an Oracle file system or OFS managed file system on the specified mount point.

Before you begin, complete the following checks to ensure that:

  • You have created the file system using the dbms_fs.make_oracle_fs()procedure.
  • The mount point that you specify exists in the local node.
  • The Oracle user has access permissions.
  • The mount path is empty, which means that the directory specified by the mount point does not have any files.

Oracle supports an extensive list of mount options that you can use to have better control on resources and achieve good performance. When you use the persist mount option, file systems are automatically remounted every time instance restarts. 


Since OFSD is a non-fatal background process, it gets automatically restarted after the death of a process. 

File systems that are mounted at the time of the death of the OFSD process are automatically remounted after starting a new OFSD process. 


This ensures continuous availability of the mounted file systems even in the case of an error.


To improve the throughput, OFSD has its own local cache for writes and reads. 


The write cache uses 8 (1 MB) buffers per file connection, and it can use up to 256 MB per file system. 

You can modify this value through the mount option, wcache_size


A read-ahead algorithm is implemented for read operation and it uses 2 (1 MB) per file connection and it can use up to 256 MB per file system. Use the mount option, rcache_size, to modify this value. 


The read-write cache is maintained per node, so this provides local cache consistency. 


In an RAC environment, consistency is guaranteed only after the flush() or close() operation is performed on the file. 


When two different processes on two different RAC nodes modify a single file and write to the same offset, then the first process that performs the close() operation on the file will have its data written into the file. 


Syntax:


Mounts a DBFS file system

Mounts a DBFS file system at /oracle/dbfs/testfs.


BEGIN

 DBMS_FS.MOUNT_ORACLE_FS (

  fstype           => 'dbfs',                              

  fsname           => 'dbfs_fs1',                              

  mount_point      => '/oracle/dbfs/testfs',                              

  mount_options    => 'default_permissions, allow_other, db_access'); 

END;


Example

Persist mount a DBFS file system

Persist mounts a DBFS file system at /oracle/dbfs/testfs.


BEGIN

 DBMS_FS.MOUNT_ORACLE_FS (

  fstype           => 'dbfs',                              

  fsname           => 'dbfs_fs1',                              

  mount_point      => '/oracle/dbfs/testfs',                              

  mount_options    => 'default_permissions, allow_other, persist, db_access'); 

END;


UNMOUNT_ORACLE_FS Procedure

This procedure unmounts an Oracle file system on the specified mount point. 

File systems that are mounted in a PDB are automatically unmounted when the PDB is closed. 


You can also use dbms_fs.unmount_oracle_fs() to explicitly unmount an Oracle file system that you have mounted through OFS.


Usage Notes:

  • Before you unmount the file system, ensure that all applications that use this file system are shut down. Also ensure that no processes reference the mounting file system.
  • You can find information about the currently mounted file systems by querying the V$OFSMOUNT dynamic view.
  • After unmounting the file system, the write permissions are removed from the mount point to prevent applications from writing to the underlying file system instead of the OFS supported file systems.
  • When an Oracle instance is shut down in normal immediate mode, then all the mounted file systems are automatically unmounted.
  • If a file system is mounted with the MOUNT_ORACLE_FS procedure with the persist option, it will be automatically mounted again when the database instance starts or the PDB is plugged. If this file system is unmounted by executing DBMS_FS.UNMOUNT_ORACLE_FS, it will remain unmounted even if the persistoption was used to mount it.
  • If you perform a SHUTDOWN ABORT, then the file system may still show as mounted but it may not be accessible. In this case, you can unmount the system manually by calling the unmountcommand at the operating system level or the fusermount procedure on Linux systems.
  • Do not use fusermount -u to unmount a running file system as it causes inconsistency in Oracle views, such as v$ofsmount.
  • You can export the local mount point of an Oracle file system to point to the remote system, and then NFS mount the file system from the remote system by using the operating system mountcommand. The DBMS_FS.MOUNT_ORACLE_FS procedure is similar to mount commands that are used for other local file systems.
  • For better security, Oracle recommends that you use access control lists (ACLs) and Kerberos to control access to sensitive data.
  • Do not attempt to unmount the file system from the operating system level. Doing so can leave the Oracle Database-created file system internal tables in an inconsistent state.


Example:

The following sample code unmounts a DBFS mounted file system at /oracle/dbfs/testfs.


BEGIN

 DBMS_FS.UNMOUNT_ORACLE_FS (

  fsname           => 'dbfs_fs1',                              

  mount_point      => '/oracle/dbfs/testfs',

  mount_options    => 'force'); 

END;

IMG_7957.jpeg

Alireza Kamrani 

No comments:

Post a Comment

Apply multiple Oracle patches Simultaneously

Apply multiple Oracle patches Simultaneously ♠️ Alireza Kamrani ♠️         16 Jan 2025 Step 1. Download all patches and unzip them in a co...