Oracle Database File System (DBFS) 11gR2

References:
https://oracle-base.com/articles/11g/dbfs-11gr2
DBFS resource not starting as crs resource (Doc ID 1908868.1)
https://oracle-base.com/articles/11g/dbfs-11gr2#creating_a_file_system
https://docs.oracle.com/cd/E11882_01/appdev.112/e18294/adlob_client.htm#ADLOB45998

Tested on:
Oracle Database 11g Enterprise Edition Release 2

x86_64 GNU/Linux

1.) Install Package on Linux as Root

yum install kernel-devel
yum install fuse fuse-libs

[root@lnx01 ~]# rpm -qa | grep kernel-devel
kernel-devel-2.6.32-573.22.1.el6.x86_64

root@lnx01 ~]# rpm -qa | grep fuse
fuse-libs-2.8.3-4.0.2.el6.x86_64
fuse-2.8.3-4.0.2.el6.x86_6

2.) Setup Database

sqlplus / as sysdba

create tablespace ts_dbfs datafile '/data03/db11//ts_dbfs_01.dbf' size 10m autoextend on next 10m;

create user dbfs_owner identified by dbfs default tablespace ts_dbfs;
alter user dbfs_owner quota unlimited on ts_dbfs;

GRANT CREATE SESSION, RESOURCE, CREATE VIEW, DBFS_ROLE TO dbfs_owner;

cd $ORACLE_HOME
cd rdbms
cd admin

sqlplus dbfs_owner/dbfs

@dbfs_create_filesystem.sql ts_dbfs FS_DBFS

3.) Mount

- As root:

mkdir -p /mnt/dbfs
chown oracle:oinstall /mnt/dbfs

usermod -a -G fuse oracle
id oracle
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),499(fuse)

export ORACLE_HOME=/oracle/product/11.2/db_1
echo "/usr/local/lib" >> /etc/ld.so.conf.d/usr_local_lib.conf
ln -s $ORACLE_HOME/lib/libclntsh.so.11.1 /usr/local/lib/libclntsh.so.11.1
ln -s $ORACLE_HOME/lib/libnnz11.so /usr/local/lib/libnnz11.so
ln -s /lib64/libfuse.so.2 /usr/local/lib/libfuse.so.2
ldconfig
ln -s $ORACLE_HOME/bin/dbfs_client /sbin/mount.dbfs
chmod +x /bin/fusermount

- As Oracle:
dbfs_client dbfs_owner@DB11 /mnt/dbfs

- In another session as Oracle User:

[oracle@lnx01 dbfs]$ pwd
/mnt/dbfs
[oracle@lnx01 dbfs]$ ls -ltra
total 4
drwxrwxrwx 3 root root 0 Apr 20 04:33 FS_DBFS
drwxr-xr-x. 3 root root 4096 Apr 20 05:08 ..
drwxr-xr-x 3 root root 0 Apr 20 05:28 .

- umount

fusermount -u /mnt/dbfs

4.) Using the DBFS (Password):

dbfs_client dbfs_owner@DB11 --command ls -a -l dbfs:/FS_DBFS/
Password:
drwxr-xr-x root root 0 Apr 20 04:33 .sfs

dbfs_client dbfs_owner@DB11 --command mkdir dbfs:/FS_DBFS/test1

dbfs_client dbfs_owner@DB11 --command ls -a -l dbfs:/FS_DBFS/
Password:
drwx------ oracle oinstall 0 Apr 20 05:34 dbfs:/FS_DBFS/test1
drwxr-xr-x root root 0 Apr 20 04:33 .sf

5.) Wallet

As you can see, every time the dbfs_client ask for password and to start the DBFS the session is in HOLD.
So, to avoid this problem let's use WALLET;

- Stop the session in HOLD, with CTRL+C, the filesystem will be stoped;

As Oracle user:

mkdir -p $HOME/oracle/wallet

$ORACLE_HOME/bin/mkstore -wrl $HOME/oracle/wallet -create
--> Passwords must have a minimum length of eight characters 
 and contain alphabetic characters combined with numbers 
 or special characters.

--> DB11 here is my TNS entry
mkstore -wrl $HOME/oracle/wallet -createCredential DB11 dbfs_owner dbfs

- Mounting the File System:

nohup dbfs_client -o wallet /@db11 /mnt/dbfs &

[oracle@lnx01 dbfs]$ ls -ltr
total 0
drwxrwxrwx 4 root root 0 Apr 20 05:34 FS_DBFS
[oracle@lnx01 dbfs]$ pwd
/mnt/dbfs

dbfs_client /@DB11 --command ls -a -l dbfs:/FS_DBFS/

drwx------ oracle oinstall 0 Apr 20 05:34 dbfs:/FS_DBFS/test1
drwxr-xr-x root root 0 Apr 20 04:33 .sfs

6.) MOUNT with FSTAB

- to umount: 
fusermount -u /mnt/dbfs

- Add on FSTAB:

/sbin/mount.dbfs#dbfs_owner@db11 /mnt/dbfs fuse rw,user,noauto,direct_io 0 0

- Create File:

cat /sbin/mount.dbfs

#!/bin/bash
export ORACLE_HOME=/oracle/product/11.2/db_1
nohup $ORACLE_HOME/bin/dbfs_client $@ << FEEDPWD &
dbfs
FEEDPWD

chmod 775 /sbin/mount.dbfs
chgrp fuse /sbin/mount.dbfs

- As ORACLE user
mount /mnt/dbfs
 
[oracle@lnx01 db_1]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 11G 7.2G 2.5G 75% /
tmpfs 2.9G 1.2G 1.8G 40% /dev/shm
/dev/sda1 479M 54M 396M 12% /boot
/dev/sdb1 30G 25G 3.4G 88% /oracle
/dev/sdd1 4.8G 3.2G 1.4G 71% /data01
/dev/sde1 9.8G 5.4G 3.9G 59% /data02
/dev/sdf1 20G 6.6G 13G 36% /data03
dbfs 5.3M 136K 5.2M 3% /mnt/dbfs <<-- DBFS

[oracle@lnx01 FS_DBFS]$ pwd
/mnt/dbfs/FS_DBFS
[oracle@lnx01 FS_DBFS]$ ls -ltr
total 0
drwx------ 2 oracle oinstall 0 Apr 20 05:34 test1
[oracle@lnx01 FS_DBFS]$

[oracle@lnx01 test1]$ touch myDBFS.txt
[oracle@lnx01 test1]$ ls -ltr
total 0
-rw-r--r-- 1 oracle oinstall 0 Apr 20 06:04 myDBFS.txt
[oracle@lnx01 test1]$ pwd
/mnt/dbfs/FS_DBFS/test1
[oracle@lnx01 test1]$

-- Now is possible use dbfs_client without password:

dbfs_client /@DB11 --command ls -a -l dbfs:/FS_DBFS/
drwx------ oracle oinstall 0 Apr 20 06:04 dbfs:/FS_DBFS/test1
drwxr-xr-x root root 0 Apr 20 04:33 .sfs
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s