RSS

Setup DBFS and mount DBFS

For those who don’t know what DBFS (DataBase FileSystem) is, here’s a little snippet:

The Oracle Database File System (DBFS) enables the database to be used as a POSIX-compatible file system on Linux. This feature includes a PL/SQL package on the database server that enables the DBFS server functionality and a Linux client for DBFS (dbfs_client). The dbfs_client client is a utility that enables mounting of a DBFS file system as a mount point on Linux. It provides the mapping from file system operations to database operations. The dbfs_client client runs completely in user space and interacts with the kernel through the FUSE library infrastructure.

DBFS Hierarchical Store provides an easy and application-transparent way to archive SecureFiles data that is stored in DBFS file systems to secondary storage tiers such as tape and storage clouds, using DBFS Links. It also allows archived data to be dearchived and brought back into the database on demand.

DBFS makes it easy for files to be accessed by database applications, and for file-based tools to access files stored in the database. With DBFS, all important file data can be seamlessly stored in an Oracle database, providing the benefits of security, backup, performance, and scalability that are standard with the Oracle Database.

SecureFiles is a high performance solution for storing files or unstructured data in Oracle Database. Customers often need to store these files for long periods of time for business or compliance reasons. Consequently, customers are looking to transfer files to cheaper forms of storage in an application-transparent manner to reduce manageability and administration overhead. DBFS Hierarchical Store provides a seamless, automatic, and transparent way to archive cold file data to inexpensive storage.

Got all that..? Good…let’s set it up…

Set up DBFS … I assume you’re using ASM

#!/bin/bash
#set up dbfs
#make_dbfs.sh
echo "Create DBFS "
export DBNAME=dbfs
export NODE1=db01
export NODE2=db02
export ORACLE_HOME=$ORACLE_HOME
export PATH=$PATH:$ORACLE_HOME/bin:
 
dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbName $DBNAME -sid $DBNAME -sysPassword oracle -systemPassword oracle -emConfiguration NONE -storageType ASM -diskGroupName DATA -nodelist $NODE1,$NODE2 -characterSet WE8IS08859P15 -listeners $DBNAME -memoryPercentage 5 -initParams compatible=11.2.0.2.0 -continueOnNonFatalErrors true
 
 
echo "Set up Tablespace & User for DBFS in new database"
sqlplus "sys/oracle@${NODE1}:1521/dbfs as sysdba"  <<EOF
spool /tmp/dbfs_setup.log
create bigfile tablespace dbfsts datafile '+DATA' size 400g autoextend on next 8g NOLOGGING EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO ;
create user dbfs identified by dbfs default tablespace dbfsts quota unlimited on dbfsts;
grant create session, create table, create procedure, dbfs_role to dbfs;
exit;
EOF
 
cd $ORACLE_HOME/rdbms/admin
 
echo "Set up DBFS"
sqlplus "dbfs/dbfs@${NODE1}:1521/dbfs" <<EOF
start dbfs_create_filesystem_advanced dbfsts stage nocompress nodeduplicate noencrypt non-partition
exit;
EOF
 

Now…mount DBFS

#!/bin/bash
# 
# mount_dbfs.sh
#

export DBNAME=dbfs
export DBFS_PATH=/u01/dbfs
export DBFS_PASSWORD=dbfs
export HOST=`hostname`
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.3/dbhome_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
 
mkdir -p $DBFS_PATH
  if [ ! -d $DBFS_PATH ] ; then
    echo "There was an error creating $DBFS_PATH."
    echo "Please check the permissions of the directory tree to ensure"
    echo "that this directory can be created and then re-run this script."
    exit 1
  fi
 
echo $DBFS_PASSWORD > .passwordfile.f
 
#sudo chmod a+rwx /etc/fuse.conf
 
echo "Here's the mount cmd "
echo "dbfs_client dbfs@${HOST}:1521/${DBNAME} $DBFS_PATH"
 
sleep 2
 
# sudo modprobe fuse
 
nohup dbfs_client -o direct_io -o allow_other  dbfs@${HOST}:1521/${DBNAME} /home/oracle/dbfs < .passwordfile.f &
 
echo "Mounted filesystems"
mount | grep dbfs
 
echo "Directory listing"
ls -halt $DBFS_PATH
 


There you go…all done…

That was easy…wasn’t it?

- Matt

 
Leave a comment

Posted by on May 22, 2012 in ASM, bash, database, dbfs, script, shell

 

Tags: , ,

Start DBConsole

Quick little script to get DBConsole up and running


#!/bin/bash


export DBCONSOLE_STATUS=`emctl status dbconsole | grep running | awk '{ print $6 }'`


if [ -z "${DBCONSOLE_STATUS}" ]
then 
	echo "Not running"
	export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
	export ORACLE_BASE=/u01/app/oracle
	export ORACLE_SID=orcl
	export ORACLE_UNQNAME=orcl
	export ORACLE_DB=orcl
	export PATH=$PATH:$ORACLE_HOME/bin
	# Start DBConsole
	emctl start dbconsole

else
	echo "DBConsole is ${DBCONSOLE_STATUS}"
	exit 1
fi

 
Leave a comment

Posted by on May 18, 2012 in Uncategorized

 

Tags: , ,

My oracle user bash_profile

Use it…abuse it…don’t lose it…

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:/sbin:$HOME/bin


export PATH
  #ORACLE_SID=grid;export ORACLE_SID
  ORACLE_BASE=/u01/app ; export ORACLE_BASE
  ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1/;export ORACLE_HOME
  GRID_HOME=/u01/app/oracle/grid; export GRID_HOME
  LD_LIBRARY_PATH=$ORACLE_HOME/lib; export LD_LIBRARY_PATH
  PATH=$PATH:$ORACLE_HOME/bin; export PATH


function sid() {        
export ORACLE_SID=$1 
export ORACLE_UNQNAME=$1        
}
  
function sql() {        
export ORACLE_SID=$1         
$ORACLE_HOME/bin/sqlplus "sys/oracle@localhost:1521/${1} as sysdba"         
}
  

function alert () {        
export ORACLE_SID=$1         
tail -f $ORACLE_BASE/diag/rdbms/$1/$1/trace/alert_$1.log         
}

# Archives
# Extract about anything
extract () 
{
    if [ -f $1 ] ; then
        case $1 in
            *.tar.bz2)   tar xvjf $1        ;;
            *.tar.gz)    tar xvzf $1     ;;
            *.bz2)       bunzip2 $1       ;;
            *.rar)       unrar x $1     ;;
            *.gz)        gunzip $1     ;;
            *.tar)       tar xvf $1        ;;
            *.tbz2)      tar xvjf $1      ;;
            *.tgz)       tar xvzf $1       ;;
            *.zip)       unzip $1     ;;
            *.Z)         uncompress $1  ;;
            *.7z)        7z x $1    ;;
            *)           echo "'$1' cannot be extracted via >extract<" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}

encrypt_zip()
{ 

	zip -ejr $1 $2

}

## Alias Section
alias ll='ls -haltr'
alias ipconfig='ifconfig'
alias ip='ifconfig'
alias dir='ls -alth'
alias rm='rm -rvdf'
alias killit='killall -v'
alias cls='clear'
alias cl='clear'
alias rmdir='rm -rdvf'
alias kp='ps auxwww'
alias hosts='sudo vi /etc/hosts'



# History Settings
export HISTSIZE=10000
export HISTCONTROL=erasedups
export HISTCONTROL=ignoredups
shopt -s histappend

# Start VNCserver...
# yeah...I don't want it in /etc/sysconfig/vncservers
vncserver :2

# Increase Shared Memory
sudo mount -o remount,size=8G /dev/shm

echo "#############################"
echo                            uptime                                                                  
echo "#############################"
uptime


echo "#############################"
echo                            disk use
echo "#############################"
df -h /

echo "#############################"
echo                              who is on       
echo "#############################"
w

echo "#############################"
echo				Oracle 
echo "#############################"
ps -ef | grep pmon

 
export PATH LD_LIBRARY_PATH ORACLE_BASE ORACLE_HOME ORACLE_SID ORA_CRS_HOME GRID_HOME
PS1='[\u@\h][${ORACLE_SID}][\w]\$ '






 
Leave a comment

Posted by on May 17, 2012 in bash, oracle, shell

 

Tags: , ,

Add ASM Disks to VirtualBox

Thought I’d share some VBox goodness.

Adding additional disks to VBox is simple with the following scripts

From the VBox host:

#!/bin/bash

#
# Add ASM storage to a VBox Image
#


echo "How many ASM disks would you like to add? > "
read ASMDISK

echo "What is the name of the VBox would you like to add the storage to? >"
vboxmanage list vms
read VBOXNAME

for (( i = 1 ; i <= ${ASMDISK} ; i++ ))
do
VBoxManage createhd --filename asm$i.vdi --size 5120 --format VDI --variant Fixed 
VBoxManage storageattach ${VBOXNAME} --storagectl "SATA Controller" --port ${i} --device 0 --type hdd --medium asm${i}.vdi
done



# Start the VM and fdisk the new ASM disks
vboxmanage startvm ${VBOXNAME}

echo "Sleeping for 20 seconds"
sleep 20

Once the VBox guest is fired up ssh into the guest via port forwarding (you’re port forwarding aren’t you? )

#!/bin/bash


sudo fdisk /dev/sdb < fdisk_cmds
sudo fdisk /dev/sdc < fdisk_cmds
sudo fdisk /dev/sdd < fdisk_cmds
sudo fdisk /dev/sde < fdisk_cmds
sudo fdisk /dev/sdf < fdisk_cmds


sudo /etc/init.d/oracleasm configure < asm_config 

sudo /etc/init.d/oracleasm createdisk ASM1 /dev/sdb1
sudo /etc/init.d/oracleasm createdisk ASM2 /dev/sdc1
sudo /etc/init.d/oracleasm createdisk ASM3 /dev/sdd1
sudo /etc/init.d/oracleasm createdisk ASM4 /dev/sde1
sudo /etc/init.d/oracleasm createdisk ASM5 /dev/sdf1



sudo /etc/init.d/oracleasm listdisks

Here’s the fdisk_cmds that worked for me…

n
p
1


w

Here’s the ASM commands that worked (you’re using ASM right…?)

oracle
dba
y
y

Now you’re all set to start installing your Grid Infrastructure on your VBox guest.

BTW…you might need to change the disk discovery path in the ASM config wizard to either “ORCL:*” or “/dev/oracleasm/disks/*”

Cheers,
Matt

Credit:
I basically bastardized this great HOW-TO

 
Leave a comment

Posted by on May 16, 2012 in ASM, database, linux, oracle, shell, vbox, VirtualBox

 

Tags: , , ,

Oracle Install Linux Quickstart Script — updated May 2, 2012


#!/bin/bash 
   #===================================================================================
   #
   #         FILE: linux_install_quickstart
   #
   #        USAGE: select an option or do all
   #
   #  DESCRIPTION:
   #      OPTIONS:  
   # REQUIREMENTS: 
   #       AUTHOR: Matt Dee
   #      CREATED: March 8, 2012
   #      UPDATED: May 2, 2012
   #      VERSION: 2.0
   #
   #
   #
   #
   #
   #
   #===================================================================================



# Functions for various stuff
function start_up()
{
	clear screen
	echo "#########################################################"
	echo "# This will setup your linux system for Oracle Database #"
	echo "#########################################################"

	echo
	echo
	echo 

	echo "################################################"
	echo "#                                              #"
	echo "#    What would you like to do ?               #"
	echo "#                                              #"
	echo "#          1 ==   Create Oracle user & Groups  #"
	echo "#                                              #"
	echo "#          2 ==   Change kernel settings       #"
	echo "#                                              #"
	echo "#          3 ==   Change security settings     #"
	echo "#                                              #"
	echo "#          4 ==   Set up YUM                   #"
	echo "#                                              #"
	echo "#          5 ==   Update YUM                   #"
	echo "#                                              #"
	echo "#          6 ==   Install required packages    #"
	echo "#                                              #"
	echo "#          7 ==   Do EVERYTHING                #"
	echo "#                                              #"
	echo "#          8 ==   Do NOTHING                   #"
	echo "#                                              #"
	echo "################################################"
	echo 
	echo "Please enter in your choice:> "
	read whatwhat

#	if [ $whatwhat -gt 9 ]
#		then
#		echo "Please enter a valid choice"
#		sleep 3
#		start_up
#	fi
	
}

function oracle_user_groups()
{
	echo "################################################"
	echo "Set up Oracle user & Groups"
	echo "Would you like to continue? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		# Create oracle groups
		/usr/sbin/groupadd oinstall
		/usr/sbin/groupadd  dba

		# Create oracle user
		/usr/sbin/useradd oracle -g oinstall -G dba
		/usr/sbin/usermod -g oinstall -G dba oracle

		# Change oracle passwd
		#export ORAPASS=oracle
		#passwd oracle $ORAPASS

		# Create directory for oracle stuff
		mkdir /u01
		chown -Rv oracle.oinstall /u01
		#start_up
	else
		echo "No"
		work_time
	fi
	
}


function kernel_settings()
{
	echo "################################################"
	echo "Set up kernel for Oracle"
	echo "Would you like to continue? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		echo kernel.shmmax=2147483648 >>/etc/sysctl.conf
		echo kernel.sem=250 32000 100 128 >>/etc/sysctl.conf
		echo fs.file-max=65536 >>/etc/sysctl.conf
		echo net.ipv4.ip_local_port_range=1024 65000 >>/etc/sysctl.conf
		echo fs.aio-max-nr = 1048576 >>/etc/sysctl.conf
		echo fs.file-max = 6815744 >>/etc/sysctl.conf
		echo kernel.shmall = 2097152 >>/etc/sysctl.conf
		echo kernel.shmmax = 536870912 >>/etc/sysctl.conf
		echo kernel.shmmni = 4096 >>/etc/sysctl.conf
		echo kernel.sem = 250 32000 100 128 >>/etc/sysctl.conf
		echo net.ipv4.ip_local_port_range = 1024 65500 >>/etc/sysctl.conf
		echo net.core.rmem_default = 262144 >>/etc/sysctl.conf
		echo net.core.rmem_max = 4194304 >>/etc/sysctl.conf
		echo net.core.wmem_default = 262144 >>/etc/sysctl.conf
		echo net.core.wmem_max = 1048586 >>/etc/sysctl.conf

		/sbin/sysctl -p
		#start_up
		
	else
		echo "No"
		work_time
	fi
	
}


function security_settings()
{
	echo "################################################"
	echo "Set up sercurity for Oracle"
	echo "Would you like to continue? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		echo oracle           soft    nproc   2047 >>/etc/security/limits.conf
		echo oracle           hard    nproc   16384 >>/etc/security/limits.conf
		echo oracle           soft    nofile  4096 >>/etc/security/limits.conf
		echo oracle           hard    nofile  65536 >>/etc/security/limits.conf
		# Set PAM
		# /etc/pam.d/login
		echo session    required     pam_limits.so >> /etc/pam.d/login
		#start_up
		
	else
		echo "No"
		work_time
	fi
	
}


function setup_yum()
{
	echo "################################################"
	echo "Add public-yum.oracle.com to YUM"
	echo "Would you like to continue? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		linux_release=`cat /etc/redhat-release | awk '{print $7}'`
		echo $linux_release
		case $linux_release in
		5*)
		cd /tmp
		rm -fv public-yum*
		wget http://public-yum.oracle.com/public-yum-el5.repo
		mv public-yum-el5.repo public-yum-el5.old
		cat public-yum-el5.old | sed "s/enabled=0/enabled=1/g" >public-yum-el5.repo
		cp public-yum-el5.repo /etc/yum.repos.d/
		;;
		6*)
		cd /tmp
		rm -fv public-yum*
		wget http://public-yum.oracle.com/public-yum-ol6.repo 
		mv public-yum-ol6.repo public-yum-ol6.old
		cat public-yum-ol6.old | sed "s/enabled=0/enabled=1/g" >public-yum-ol6.repo 
		cp public-yum-ol6.repo /etc/yum.repos.d/
		;;
		esac
		#start_up
		
	else
		echo "No"
		work_time
	fi
	
	
}

function update_yum()
{
	echo "################################################"
	echo "Update Yum...this can be a lengthly operation"
	echo "Would you like to continue? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		yum -y update 
		#start_up
		
	else
		echo "No"
		work_time
	fi
	
}


function install_stuff()
{
	echo "################################################"
	echo "Install required software for Oracle"
	echo "Would you like to continue? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		sudo yum -y install kernel-deve* binutils-* compat-libstdc++-* elfutils-libelf-* elfutils-libelf-devel-* elfutils-libelf-devel-static-* gcc-* gcc-c++-* glibc-* glibc-common-* glibc-devel-* glibc-headers-* kernel-headers-* ksh-* libaio-* libaio-devel-*  libgcc-* libgomp-* libstdc++-* libstdc++-devel-* make-* sysstat-* unixODBC-* unixODBC-devel-* oracleasm-`uname -r`
		#start_up
		
	else
		echo "No"
		work_time
	fi
	
}


function do_everything()
{
	echo "################################################"
	echo "Do it all...NOW "
	echo "Would you like to continue? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		oracle_user_groups
		kernel_settings
		security_settings
		setup_yum
		update_yum
		install_stuff
		#start_up
		
	else
		echo "No"
		work_time
	fi
	
}


function do_nothing()
{
	echo "################################################"
	echo "You don't want to do nothing...lazy..."
	echo "So...you want to quit...yes? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		exit 1
	else
		echo "No"
		work_time
	fi
	
}


function work_time()
{
start_up
case $whatwhat in
	1) 
		oracle_user_groups
		;;
	2) 
		kernel_settings
		;;
	3)
		security_settings
		;;
	4) 
		setup_yum
		;;
	5)
		update_yum
		;;
	6)
	 	install_stuff
		;;
	7)
		do_everything
		;;
	8)
		do_nothing
		;;
esac
}



# Script must be run by root user
# Let's go to work

clear screen
if [[ `whoami` != "root" ]]
	then
		echo "This script must be run as the root user."
		exit 1
	else 
		work_time
fi



 
1 Comment

Posted by on May 2, 2012 in database, linux, script, shell

 

Tags: , , ,

Script to set the db parameters for OEM 12c

#!/bin/bash
   #===================================================================================
   #
   #         FILE: OEM_DB_Setup.sh
   #
   #        USAGE: Run it...
   #
   #  DESCRIPTION: Script to set the db parameters for OEM 12c
   #      OPTIONS:  
   # REQUIREMENTS: 
   #       AUTHOR: Matt Dee
   #      CREATED: May 2, 2012
   #      VERSION: 1.0
   #
   #
   #
   #
   #
   #
   #===================================================================================


clear screen

function start_up()
{
	clear screen
	echo "#########################################################"
	echo "# This will setup your Oracle Database for OEM 12c       #"
	echo "#########################################################"

	echo
	echo

	echo "################################################"
	echo "#                                              #"
	echo "#    What would you like to do ?               #"
	echo "#                                              #"
	echo "#          1 ==   Change Database Settings     #"
	echo "#                                              #"
	echo "#          2 ==   Rollback Database Settings   #"
	echo "#                                              #"
	echo "#          3 ==   QUIT                         #"
	echo "#                                              #"
	echo "################################################"
	echo 
	echo "Please enter in your choice:&gt; "
	read whatwhat
}

function oracle_home_set()
{
	# Test for Oracle Home setting
	if test "${ORACLE_HOME+set}" != set ; then
 		echo "ORACLE_HOME is not set"
 		echo "Please set your ORACLE_HOME and rerun"
	else
 		echo "$ORACLE_HOME is set"
	fi
}


function change_db()
{
	oracle_home_set
	
	echo "What is the SID of the Oracle database"
	echo "Currently runnging Databases"
	ps -ef | grep -v grep | grep pmon | cut -d _ -f3
	echo "Enter the SID: "
	read ORASID
	
	export ORACLE_SID=${ORASID}

	sqlplus '/ AS SYSDBA' &lt;&lt;EOF

	create pfile='/tmp/init_backup.ora' from spfile;

	ALTER SYSTEM SET processes=300 SCOPE=SPFILE;
	ALTER SYSTEM SET session_cached_cursors=200 SCOPE=SPFILE;
	ALTER SYSTEM SET sga_target=2G SCOPE=SPFILE;
	ALTER SYSTEM SET shared_pool_size=600M SCOPE=SPFILE;
	ALTER SYSTEM SET pga_aggregate_target=1G SCOPE=SPFILE;
	ALTER SYSTEM SET job_queue_processes=20 SCOPE=SPFILE;
	ALTER SYSTEM SET open_cursors=300 SCOPE=SPFILE;
	-- Restart the instance.
	SHUTDOWN ABORT
	STARTUP
	exit
EOF
}

function rollback_changes()
{
	oracle_home_set
	
if test ! -f /tmp/init_backup.ora
	then 	
		echo &quot;No /tmp/init_backup.ora exists&quot;
		echo &quot;Exiting&quot;
		exit 1
	else
		echo &quot;What is the SID of the Oracle database&quot;
		echo &quot;Currently runnging Databases&quot;
		ps -ef | grep -v grep | grep pmon | cut -d _ -f3
		echo &quot;Enter the SID: &quot;
		read ORASID

	export ORACLE_SID=${ORASID}
	
	sqlplus '/ AS SYSDBA' &lt;&lt;EOF
	shutdown abort
	startup pfile='/tmp/init_backup.ora'
	create spfile from pfile='/tmp/init_backup.ora'
	shutdown abort
	startup
	exit
EOF
fi	
}

function do_nothing()
{
	echo &quot;################################################&quot;
	echo &quot;You don't want to do nothing...lazy...&quot;
	echo &quot;So...you want to quit...yes? &quot;
	echo &quot;Enter yes or no&quot;
	echo &quot;################################################&quot;
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo &quot;Yes&quot;
		exit 1
	else
		echo &quot;No&quot;
		work_time
	fi
	
}

function work_time()
{
start_up
case $whatwhat in
	1)
		change_db
		;;
	2)
		rollback_changes
		;;
	3) 
		do_nothing
		;;
esac
}


# Work time!!!
work_time

 

Tags: , , , , , , ,

Get the Owner, Object Name, Size, Tablespace & Filename for Oracle objects


/* Get the Owner, Object Name, Size, Tablespace &amp; Filename for Oracle objects */

set linesize 120
col "Object Name" format a30

select 
	distinct 
    o.owner "Owner",
    o.object_name "Object Name", 
    (s.bytes/1024/1024)"MB",
    f.tablespace_name "Tablespace",
    f.file_name "File Name"
from 
	dba_data_files f, 
	dba_segments s, 
	dba_objects o 
where 
	f.tablespace_name = s.tablespace_name and s.segment_name = o.object_name and o.owner not in ('SYSTEM','SYSAUX','SYS','SYSMAN')
order by "MB" desc;
	

 
Leave a comment

Posted by on April 6, 2012 in database, sql

 

Tags: ,

Bulk Collect speeds

Quick example


--------------------------------------------------------
--  Quick test on insert rates Oracle DB
--------------------------------------------------------

SET TIMING ON;
SET ECHO ON;
SET LINES 200;

--------------------------------------------------------
--  DDL for Table LOG_DATA
--------------------------------------------------------

  CREATE TABLE "LOG_DATA" 
   (	
	"ID" NUMBER, 
	"DATA1" VARCHAR2(255 ), 
	"DATA2" VARCHAR2(255 ), 
	"SENSOR_NAME" VARCHAR2(50 ), 
	"ANGLE_INFO" VARCHAR2(50 ), 
	"INDATE" DATE
   )
;
--------------------------------------------------------
--  Create the SOME_DATA Table with a CTAS
--------------------------------------------------------
CREATE TABLE SOME_DATA AS SELECT * FROM LOG_DATA WHERE 1 = 2;


--------------------------------------------------------
--   Generate some random data into the SOME_DATA table 
--------------------------------------------------------
BEGIN 
FOR I IN 1..50000 LOOP
INSERT INTO SOME_DATA 
	(ID,DATA1,DATA2,SENSOR_NAME,ANGLE_INFO,INDATE)
VALUES
	((SELECT DBMS_RANDOM.VALUE(50000000, 999999999) FROM DUAL),(SELECT DBMS_RANDOM.VALUE(50000000, 999999999) FROM DUAL),(SELECT DBMS_RANDOM.VALUE(50000000, 999999999) FROM DUAL),(SELECT DBMS_RANDOM.VALUE(50000000, 999999999) FROM DUAL),(SELECT DBMS_RANDOM.VALUE(50000000, 999999999) FROM DUAL),SYSDATE)
;
COMMIT;
END LOOP;
END;
/



--------------------------------------------------------
-- Do a quick insert...no primary key constraint
-- I average about .35 seconds on my VirtualBox Linux image
--------------------------------------------------------
DECLARE
 CURSOR C_SOME_DATA IS
	SELECT /*+ PARALLEL */ * FROM SOME_DATA;
	
TYPE FETCH_ARRAY IS TABLE OF C_SOME_DATA%ROWTYPE;
S_ARRAY FETCH_ARRAY;

BEGIN
	OPEN C_SOME_DATA;
	LOOP
		FETCH C_SOME_DATA BULK COLLECT INTO S_ARRAY LIMIT 50000;
		
		FORALL I IN 1..S_ARRAY.COUNT 
		INSERT INTO LOG_DATA VALUES S_ARRAY(I);
			
		EXIT WHEN C_SOME_DATA%NOTFOUND;
	END LOOP;
	CLOSE C_SOME_DATA;
	COMMIT;
END;
/


--------------------------------------------------------
-- Create a simple primary key constraint on log_data 
--------------------------------------------------------
TRUNCATE TABLE LOG_DATA;
ALTER TABLE "LOG_DATA" ADD CONSTRAINT SINGLE_PK PRIMARY KEY("ID") ;

--------------------------------------------------------
-- Do a quick insert again...
-- I average about .80 seconds on my VirtualBox Linux image
--------------------------------------------------------
DECLARE
 CURSOR C_SOME_DATA IS
	SELECT /*+ PARALLEL */ * FROM SOME_DATA;
	
TYPE FETCH_ARRAY IS TABLE OF C_SOME_DATA%ROWTYPE;
S_ARRAY FETCH_ARRAY;

BEGIN
	OPEN C_SOME_DATA;
	LOOP
		FETCH C_SOME_DATA BULK COLLECT INTO S_ARRAY LIMIT 50000;
		
		FORALL I IN 1..S_ARRAY.COUNT 
		INSERT INTO LOG_DATA VALUES S_ARRAY(I);
			
		EXIT WHEN C_SOME_DATA%NOTFOUND;
	END LOOP;
	CLOSE C_SOME_DATA;
	COMMIT;
END;
/


--------------------------------------------------------
--  Create a n log_data 
--------------------------------------------------------
DROP TABLE LOG_DATA PURGE;
CREATE TABLE "LOG_DATA" 
   (	"ID" NUMBER, 
	"DATA1" VARCHAR2(255 ), 
	"DATA2" VARCHAR2(255 ), 
	"SENSOR_NAME" VARCHAR2(50 ), 
	"ANGLE_INFO" VARCHAR2(50 ), 
	"INDATE" DATE,
	CONSTRAINT MULTI_PK PRIMARY KEY (ID, DATA1,DATA2,SENSOR_NAME));
  )
;

--------------------------------------------------------
-- Do a quick insert 
-- I average about 1.5 seconds on my VirtualBox Linux image 
--------------------------------------------------------
TRUNCATE TABLE LOG_DATA;
DECLARE
 CURSOR C_SOME_DATA IS
	SELECT /*+ PARALLEL */ * FROM SOME_DATA;
	
TYPE FETCH_ARRAY IS TABLE OF C_SOME_DATA%ROWTYPE;
S_ARRAY FETCH_ARRAY;

BEGIN
	OPEN C_SOME_DATA;
	LOOP
		FETCH C_SOME_DATA BULK COLLECT INTO S_ARRAY LIMIT 50000;
		
		FORALL I IN 1..S_ARRAY.COUNT 
		INSERT INTO LOG_DATA VALUES S_ARRAY(I);
			
		EXIT WHEN C_SOME_DATA%NOTFOUND;
	END LOOP;
	CLOSE C_SOME_DATA;
	COMMIT;
END;
/

--------------------------------------------------------
-- Let's try it again with the PK Constraint disabled 
-- I average about .45 seconds on my VirtualBox Linux image 
--------------------------------------------------------
TRUNCATE TABLE LOG_DATA;

ALTER TABLE LOG_DATA DISABLE CONSTRAINT MULTI_PK;

DECLARE
 CURSOR C_SOME_DATA IS
	SELECT /*+ PARALLEL */ * FROM SOME_DATA;
	
TYPE FETCH_ARRAY IS TABLE OF C_SOME_DATA%ROWTYPE;
S_ARRAY FETCH_ARRAY;

BEGIN
	OPEN C_SOME_DATA;
	LOOP
		FETCH C_SOME_DATA BULK COLLECT INTO S_ARRAY LIMIT 50000;
		
		FORALL I IN 1..S_ARRAY.COUNT 
		INSERT INTO LOG_DATA VALUES S_ARRAY(I);
			
		EXIT WHEN C_SOME_DATA%NOTFOUND;
	END LOOP;
	CLOSE C_SOME_DATA;
	COMMIT;
END;
/













 
Leave a comment

Posted by on March 23, 2012 in database, oracle, plsql, sql

 

Tags: ,

Oracle Install Linux Quickstart Script

I can never remember all the stuff I have to do prior to an Oracle install…that’s the main reason for this script…


#!/bin/bash 
   #===================================================================================
   #
   #         FILE: linux_install_quickstart
   #
   #        USAGE: select an option or do all
   #
   #  DESCRIPTION:
   #      OPTIONS:  
   # REQUIREMENTS: 
   #       AUTHOR: Matt D
   #      CREATED: March 8, 2012
   #      VERSION: 1.0
   #
   #
   #
   #
   #
   #
   #===================================================================================



# script must be run by root user
clear screen
if [[ `whoami` != "root" ]]; then
	echo "This script must be run as the root user."
	exit 1
fi

# Functions for various stuff
function start_up()
{
	clear screen
	echo "#########################################################"
	echo "# This will setup your linux system for Oracle Database #"
	echo "#########################################################"

	echo
	echo
	echo 

	echo "################################################"
	echo "#                                              #"
	echo "#    What would you like to do ?               #"
	echo "#                                              #"
	echo "#          1 ==   Create Oracle user & Groups  #"
	echo "#                                              #"
	echo "#          2 ==   Change kernel settings       #"
	echo "#                                              #"
	echo "#          3 ==   Change security settings     #"
	echo "#                                              #"
	echo "#          4 ==   Set up YUM                   #"
	echo "#                                              #"
	echo "#          5 ==   Update YUM                   #"
	echo "#                                              #"
	echo "#          6 ==   Install required packages    #"
	echo "#                                              #"
	echo "#          7 ==   Do EVERYTHING                #"
	echo "#                                              #"
	echo "#          8 ==   Do NOTHING                   #"
	echo "#                                              #"
	echo "################################################"
	echo 
	echo "Please enter in your choice:> "
	read whatwhat

#	if [ $whatwhat -gt 9 ]
#		then
#		echo "Please enter a valid choice"
#		sleep 3
#		start_up
#	fi
	
}

function oracle_user_groups()
{
	echo "################################################"
	echo "Set up Oracle user & Groups"
	echo "Would you like to continue? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		# Create oracle groups
		/usr/sbin/groupadd oinstall
		/usr/sbin/groupadd  dba

		# Create oracle user
		/usr/sbin/useradd oracle -g oinstall -G dba
		/usr/sbin/usermod -g oinstall -G dba oracle

		# Change oracle passwd
		#export ORAPASS=oracle
		#passwd oracle $ORAPASS

		# Create directory for oracle stuff
		mkdir /u01
		chown -Rv oracle.oinstall /u01
		#start_up
	else
		echo "No"
		start_up
	fi
	
}


function kernel_settings()
{
	echo "################################################"
	echo "Set up kernel for Oracle"
	echo "Would you like to continue? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		echo kernel.shmmax=2147483648 >>/etc/sysctl.conf
		echo kernel.sem=250 32000 100 128 >>/etc/sysctl.conf
		echo fs.file-max=65536 >>/etc/sysctl.conf
		echo net.ipv4.ip_local_port_range=1024 65000 >>/etc/sysctl.conf
		echo fs.aio-max-nr = 1048576 >>/etc/sysctl.conf
		echo fs.file-max = 6815744 >>/etc/sysctl.conf
		echo kernel.shmall = 2097152 >>/etc/sysctl.conf
		echo kernel.shmmax = 536870912 >>/etc/sysctl.conf
		echo kernel.shmmni = 4096 >>/etc/sysctl.conf
		echo kernel.sem = 250 32000 100 128 >>/etc/sysctl.conf
		echo net.ipv4.ip_local_port_range = 1024 65500 >>/etc/sysctl.conf
		echo net.core.rmem_default = 262144 >>/etc/sysctl.conf
		echo net.core.rmem_max = 4194304 >>/etc/sysctl.conf
		echo net.core.wmem_default = 262144 >>/etc/sysctl.conf
		echo net.core.wmem_max = 1048586 >>/etc/sysctl.conf

		/sbin/sysctl -p
		#start_up
		
	else
		echo "No"
		start_up
	fi
	
}


function security_settings()
{
	echo "################################################"
	echo "Set up sercurity for Oracle"
	echo "Would you like to continue? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		echo oracle           soft    nproc   2047 >>/etc/security/limits.conf
		echo oracle           hard    nproc   16384 >>/etc/security/limits.conf
		echo oracle           soft    nofile  4096 >>/etc/security/limits.conf
		echo oracle           hard    nofile  65536 >>/etc/security/limits.conf
		# Set PAM
		# /etc/pam.d/login
		echo session    required     pam_limits.so >> /etc/pam.d/login
		#start_up
		
	else
		echo "No"
		start_up
	fi
	
}


function setup_yum()
{
	echo "################################################"
	echo "Add public-yum.oracle.com to YUM"
	echo "Would you like to continue? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		linux_release=`cat /etc/redhat-release | awk '{print $7}'`
		echo $linux_release
		case $linux_release in
		5.0)
		cd /tmp
		rm -fv public-yum*
		wget http://public-yum.oracle.com/public-yum-el5.repo
		mv public-yum-el5.repo public-yum-el5.old
		cat public-yum-el5.old | sed "s/enabled=0/enabled=1/g" >public-yum-el5.repo
		cp public-yum-el5.repo /etc/yum.repos.d/
		;;
		6.0)
		cd /tmp
		rm -fv public-yum*
		wget http://public-yum.oracle.com/public-yum-ol6.repo 
		mv public-yum-ol6.repo public-yum-ol6.old
		cat public-yum-ol6.old | sed "s/enabled=0/enabled=1/g" >public-yum-ol6.repo 
		cp public-yum-ol6.repo /etc/yum.repos.d/
		;;
		esac
		#start_up
		
	else
		echo "No"
		start_up
	fi
	
	
}

function update_yum()
{
	echo "################################################"
	echo "Update Yum...this can be a lengthly operation"
	echo "Would you like to continue? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		yum -y update 
		#start_up
		
	else
		echo "No"
		start_up
	fi
	
}


function install_stuff()
{
	echo "################################################"
	echo "Install required software for Oracle"
	echo "Would you like to continue? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		sudo yum -y install kernel-deve* binutils-* compat-libstdc++-* elfutils-libelf-* elfutils-libelf-devel-* elfutils-libelf-devel-static-* gcc-* gcc-c++-* glibc-* glibc-common-* glibc-devel-* glibc-headers-* kernel-headers-* ksh-* libaio-* libaio-devel-*  libgcc-* libgomp-* libstdc++-* libstdc++-devel-* make-* sysstat-* unixODBC-* unixODBC-devel-* oracleasm-`uname -r`
		#start_up
		
	else
		echo "No"
		start_up
	fi
	
}


function do_everything()
{
	echo "################################################"
	echo "Do it all...NOW "
	echo "Would you like to continue? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		oracle_user_groups
		kernel_settings
		security_settings
		setup_yum
		update_yum
		install_stuff
		#start_up
		
	else
		echo "No"
		start_up
	fi
	
}


function do_nothing()
{
	echo "################################################"
	echo "You don't want to do nothing...lazy..."
	echo "So...you want to quit...yes? "
	echo "Enter yes or no"
	echo "################################################"
	read DOWHAT
	if [[ $DOWHAT = yes ]]; then
		echo "Yes"
		exit 1
	else
		echo "No"
		start_up
	fi
	
}


# Let's go to work
start_up
case $whatwhat in
	1) 
		oracle_user_groups
		;;
	2) 
		kernel_settings
		;;
	3)
		security_settings
		;;
	4) 
		setup_yum
		;;
	5)
		update_yum
		;;
	6)
	 	install_stuff
		;;
	7)
		do_everything
		;;
	8)
		do_nothing
		;;
esac



		

 
Leave a comment

Posted by on March 9, 2012 in database, install, linux, shell

 

Tags: , , ,

 
Follow

Get every new post delivered to your Inbox.

Join 222 other followers