One big long Oracle post

Originally posted on my older blog in October of 2012:

ORACLE_UNQNAME not defined

Common mistake when installing Oracle database is to not have all of your variables set correctly in your .bash_profile. If you come across this error when you try to start up the EMCTL console then here is what you do:
[oracle@localhost bin]$ emctl start dbconsole
Environment variable ORACLE_UNQNAME not defined. Please set ORACLE_UNQNAME to database unique name.

Do:
vi ~/.bash_profile
Add this line:
export ORACLE_UNQNAME=orcl

Install Oracle Java JDK/JRE 7u7 on CentOS

First you will need to download the JDK in PM format from here.

Change to your root user…


su -i

Install the package…


JRE 32-bit
rpm -Uvh /path/to/binary/jre-7u7-linux-i586.rpm

Install Sun/Oracle JDK java, javaws, libjavaplugin.so (for Firefox/Mozilla) and javac with alternatives –install command


-java
alternatives --install /usr/bin/java java /usr/java/latest/jre/bin/java 20000
-javaws
alternatives --install /usr/bin/javaws javaws /usr/java/latest/jre/bin/javaws 20000

-Java Browser (Mozilla) Plugin 32-bit
alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/latest/jre/lib/i386/libnpjp2.so 20000

-Java Browser (Mozilla) Plugin 64-bit
alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/latest/jre/lib/amd64/libnpjp2.so 20000

-Install javac only if you installed JDK (Java Development Kit) package
alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 20000
alternatives --install /usr/bin/jar jar /usr/java/latest/bin/jar 20000

Check current java, javac, javaws and libjavaplugin.so versions


java -version
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b04)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)

javaws
Java(TM) Web Start 10.0.0.4-fcs
[...]

javac -version
javac 1.7.0_07

Install guide for Oracle 11g R2 on Centos 6

1. Install some packages

yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel glibc glibc-common glibc-devel gcc gcc-c++ libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel

2. Edit Kernel parameter.

# vi /etc/sysctl.conf
# comment out
#net.bridge.bridge-nf-call-ip6tables = 0
#net.bridge.bridge-nf-call-iptables = 0
#net.bridge.bridge-nf-call-arptables = 0

# add at the last line
net.ipv4.ip_local_port_range = 9000 65500
fs.file-max = 6815744
kernel.shmall = 10523004
kernel.shmmax = 6465333657
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.core.rmem_default=262144
net.core.wmem_default=262144
net.core.rmem_max=4194304
net.core.wmem_max=1048576
fs.aio-max-nr = 1048576

# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.ip_local_port_range = 9000 65500
fs.file-max = 65536
kernel.shmall = 10523004
kernel.shmmax = 6465333657
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576

3. Create a user for Oracle.


groupadd -g 200 oinstall
groupadd -g 201 dba
useradd -u 440 -g oinstall -G dba -d /usr/oracle oracle

vi /etc/pam.d/login
near line 14: add
session required pam_limits.so


vi /etc/security/limits.conf
# add at the last line
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536


vi /etc/profile
# add at the last line

if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi

4.  Switch to a user “Oracle” and configure some settings.

chmod 755 /usr/oracle
mkdir /usr/oracle/app
chmod 775 /usr/oracle/app
mkdir /usr/oracle/oradata
chmod 775 /usr/oracle/oradata

vi ~/.bash_profile
# add at the last line
umask 022
export ORACLE_BASE=/usr/oracle/app

$ mkdir tmp # create a temporary dir for installation

ORA-00845: MEMORY_TARGET

First of all thanks to Dude over at the OTN Discussion forums for this. Im reblogging since Oracle doesnt like you to post links to blogs in the forum for some reason. You can find his full how-to for Oracle on Ubuntu here:

https://forums.oracle.com/forums/thread.jspa?threadID=2301639

Here is the issue I was having after I moved from Ubuntu 10 to 11.10. Following this how-to worked for me just fine and only took a few minutes. Good luck!

ORA-00845: MEMORY_TARGET

Oracle 11gR2 XE, or any other edition, under Ubuntu 11.10 will result in “ORA-00845: MEMORY_TARGET not support on this system” either at Oracle database startup or during the initial installation. Ubuntu 11.10 uses a new version of the “systemd” system and session manager and has migrated away from /dev/shm and other common directories in favor of /run.

Starting with the release version of Oracle 11gR2 Express Edition, Oracle uses Automatic Memory Management. Oracle 11g AMM under Linux requires shared memory using /dev/shm. Although Ubuntu 11.10 installs a /dev/shm symbolic link automatically at system startup to address compatibility, the solution is not sufficient for Oracle 11g.

There are several ways how to address the problem, which basically mean to either enable Oracle 11g to recognize /dev/shm shared memory, or to to change from the default Oracle 11g Automatic Memory Management (AMM) to Oracle 10g Automatic Shared Memory Management (ASMM). This section has been updated from the previous version of this document to reduce the instructions by removing the content related to ASMM and changing the strategy to fix /dev/shm without modifying files that could be subject to change by automatic OS updates, i.e. /etc/init/mounted-dev.conf and /etc/fstab. To enable Oracle 11g AMM, enter the following commands:

Login as root:

sudo su –

Cut & paste the following into the command prompt (not a text editor):

cat > /etc/init.d/oracle-shm <<-EOF
#! /bin/sh
# /etc/init.d/oracle-shm
#
#
case “$1” in
start)
echo “Starting script /etc/init.d/oracle-shm”
# Run only once at system startup
if [ -e /dev/shm/.oracle-shm ]; then
echo “/dev/shm is already mounted, nothing to do”
else
rm -f /dev/shm
mkdir /dev/shm
mount -B /run/shm /dev/shm
touch /dev/shm/.oracle-shm
fi
;;
stop)
echo “Stopping script /etc/init.d/oracle-shm”
echo “Nothing to do”
;;
*)
echo “Usage: /etc/init.d/oracle-shm {start|stop}”
exit 1
;;
esac
#
### BEGIN INIT INFO
# Provides:          oracle-shm
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Bind /run/shm to /dev/shm at system startup.
# Description:       Fix to allow Oracle 11g use AMM.
### END INIT INFO
EOF

Install the oracle-shm init script:

chmod 755 /etc/init.d/oracle-shm
update-rc.d oracle-shm defaults 01 99

Restart the system:

shutdown -r now (This is the way to do it if you are doing this remotely. Using this will tell your machine to restart itself. Its handy when you are working remotely.)

Verify the success:

sudo cat /etc/mtab | grep shm
Results you are looking for:
none /run/shm tmpfs rw,nosuid,nodev 0 0
/run/shm /dev/shm none rw,bind 0 0

The upper limit of shared memory under Linux is set to 50 % of the installed RAM by default. If your system has less than 2 GB of RAM installed, there is still a chance to run into ORA-00845 error if your shared memory is used by other software.

The verify available shared memory, type the following commands:

sudo df -h /run/shm

Advertisements

ORA-12162

Originally posted from older blog on: Sep 27, 2012

ORA-12162 "TNS:net service name is incorrectly specified" results from improperly setting your ORACLE_SID value.

In Linux, these commands sets ORACLE_HOME and $ORACLE_SID as follows:

ORACLE_HOME=/u01/oracle; export ORACLE_HOME

ORACLE_SID=asdb; export ORACLE_SID

To set these values permanently do this:

As Oracle user…
vi ~/.bash_profile
Add the following at the bottom of the file or append what you have. Paths might need to be altered to match your systm…


PATH=$PATH:$HOME/bin:$ORACLE_HOME:$ORACLE_BIN

export PATH

umask 022
export ORACLE_BASE=/opt/Oracle/app
export ORACLE_BIN=/opt/Oracle/app/product/11.2.0/dbhome_1/bin
export ORACLE_HOME=/opt/Oracle/app/product/11.2.0/dbhome_1/
export ORACLE_UNQNAME=orcl
export ORACLE_SID=orcl

MongoDB Admin Commands

Originally posted from older blog on October 8th 2012

DBA Operations from the Shell

This page lists common DBA-class operations that one might perform from the MongoDB shell.Note one may also create .js scripts to run in the shell for administrative purposes.

help                         show help

show dbs                     show database names

show collections             show collections in current database

show users                   show users in current database

show profile                 show most recent system.profile entries with time >= 1ms

use <db name>                set curent database to <db name>

db.addUser (username, password)

db.removeUser(username)

db.cloneDatabase(fromhost)

db.copyDatabase(fromdb, todb, fromhost)

db.createCollection(name, { size : …, capped : …, max : … } )

db.getName()

db.dropDatabase()

// runs the collstats] command on each collection in the database

db.printCollectionStats()

db.currentOp() displays the current operation in the db

db.killOp() kills the current operation in the db

db.getProfilingLevel()

db.setProfilingLevel(level) 0=off 1=slow 2=all

db.getReplicationInfo()

db.printReplicationInfo()

db.printSlaveReplicationInfo()

db.repairDatabase()

db.version() current version of the server

db.shutdownServer()

Commands for manipulating and inspecting a collection:

db.foo.drop() drop the collection

db.foo.dropIndex(name)

db.foo.dropIndexes()

db.foo.getIndexes()

db.foo.ensureIndex(keypattern,options) – options object has these possible

fields: name, unique, dropDups

db.foo.find( [query] , [fields])       – first parameter is an optional

query filter. second parameter

is optional

set of fields to return.

e.g. db.foo.find(

{ x : 77 } ,

{ name : 1 , x : 1 } )

db.foo.find(…).count()

db.foo.find(…).limit(n)

db.foo.find(…).skip(n)

db.foo.find(…).sort(…)

db.foo.findOne([query])

db.foo.getDB() get DB object associated with collection

db.foo.count()

db.foo.group( { key : …, initial: …, reduce : …[, cond: …] } )

db.foo.renameCollection( newName ) renames the collection

db.foo.stats()

db.foo.dataSize()

db.foo.storageSize() – includes free space allocated to this collection

db.foo.totalIndexSize() – size in bytes of all the indexes

db.foo.totalSize() – storage allocated for all data and indexes

db.foo.validate() (slow)

db.foo.insert(obj)

db.foo.update(query, object[, upsert_bool])

db.foo.save(obj)

db.foo.remove(query)                   – remove objects matching query

remove({}) will remove all

Getting setup with MongoDB and Python, Pymongo, and Bottle on Centos 6

From my older blog. Originally posted Oct 26th 2012

I had to walk through all of this to get setup for my Mongo Developer and Administrator certification classes. I figured I might help you out and put it all together instead of you having to hunt all over the place for this info.

Lets get started…

Step 1: Install MongoDB

To install MongoDB on your fedora system, issue the following commands in your terminal:

su -

Lets make sure that mongo hasnt already been installed while you were playing around with it…

yum -y remove libmongodb mongodb mongodb-server

Setup the mongodb repo…

vi /etc/yum.repos.d/10gen.repo

For 32 Bit, place the following code on that file:
http://gist.github.com/3949816#file_32bit.repo

and for 64 Bit this one:
http://gist.github.com/3949816#file_64bit.repo

Installation…
Run these two commands.

yum install mongo-10gen mongo-10gen-server
mongod -f /etc/mongod.conf

Then open your Mongo Shell in terminal (to ensure it’s functional) with:

mongo

and close it by pressing Ctrl+C; Then add the mongo service to the system’s startup with:

chkconfig --levels 235 mongod on

Reboot and reopen the Mongo Shell with the command:

mongod -f /etc/mongod.conf && mongo

Close it with Ctrl+C and then go to:
http://localhost:27017/
In your web browser, you should see something like this:

“You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number”

If you see this then you have it installed and setup correctly.

Step2. Installing Python, Pymongo, and Python-Bottle

First a little background…

Python – Python is a general-purpose, interpreted high-level programming language whose design philosophy emphasizes code readability. Its syntax is said to be clear and expressive.Python has a large and comprehensive standard library. More info can be found here: http://www.python.org/

Pymongo – PyMongo is a Python distribution containing tools for working with MongoDB, and is the recommended way to work with MongoDB from Python. More info can be found here: http://api.mongodb.org/python/current/

Bottle – Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module and has no dependencies other than the Python Standard Library. More info is here: http://bottlepy.org/docs/dev/

If you haven’t already you need to install the EPEL repo for Centos 6

Check to see if you already have it installed or not…

yum repolist

You will see something similar to this:

repo id      repo name              status
base         CentOS-6 - Base        6,294
extras       CentOS-6 - Extras      4
updates      CentOS-6 - Updates     830
repolist:                           7,128

Since you dont see it above you need to grab the package…
http://mirror.us.leaseweb.net/epel/6/i386/repoview/epel-release.html

-OR-

wget "http://mirror.us.leaseweb.net/epel/6/i386/epel-release-6-7.noarch.rpm"

Note… the version number in the rpm name…if you are looking at this very late after the pub date of this post then you likely need to grab a more current version. Just follow the link above and you should see it.

do this next to test the rpm…

rpm -ivh epel-release-6-5.noarch.rpm --test

You will get back a NO KEY message.

You now need to download and install the key from FedoraProject and install on your system…

wget https://fedoraproject.org/static/0608B895.txt
mv 0608B895.txt /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

Verify that the key got installed successfully…

rpm -qa gpg*
gpg-pubkey-0608b895-4bd22942

Now install the epel-release-6-6.noarch package, which will enable EPEL repository on your system…

rpm -ivh epel-release-6-5.noarch.rpm

Now verify that the EPEL repo is working correctly…

yum repolist

You should see a line that looks similar to this:

epel      Extra Packages for Enterprise Linux 6 - x86_64      7,345

Now lets get Python, Pymongo and Bottle setup…

Pretty simple and straight forward…

sudo yum -y install python python-setuptools python-setuptools-devel
sudo yum -y install python-bson pymongo pymongo-gridfs

To install bottle you may need to install PIP first…
You can do this using curl and python…

curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python

Then install bottle…

pip install bottle