Pages

Tuesday, April 13, 2010

Oracle on ubuntu

1 Why Ubuntu?

Ubuntu is a recent distribution that continualy evolve. Its based on another distribution: Debian. So we have for example the packet system that have made it famous: apt-get. Ubuntu's advantage is it capacity to evolve quickly, a new stable version is released every 6 months, it « user-friendly » orientation, it philosophy (I let you discover more on this distribution to this address: http://www.ubuntulinux.org), and more generaly the GNU/Linux philosophy that we don't detail here.

The actual stable version is the 5.10 « Breezy Badger » version.This distribution is Desktop orientated. You could use it as a server distribution too, it's not a problem. The next version will be the 6.06 « Dapper Drake » and it'll have a professionnal and a server version.

But you'll ask me something: If Ubuntu is easy as I said, why create a How To on it? As a matter of fact, Oracle have modify it installer for unallowed some distribution. So Oracle cannot be installed, but there is a tips.

2 Before the installation
2.1 Downloading, libraries installation

First, we have to get the Oracle 10g RC2 installer for Linux. You have to go on the Oracle site: http://www.oracle.com and download it (you'll have to register) Then type this line to install the necessary libraries :

sudo apt-get install gcc, make, binutils,libmotif3,lesstif2,rpm,libaio,zip

After the download, we have to unzip the archive file that we have download:

unzip fichier_d'installation_oracle.zip

2.2 Red Hat simulation

The first thing to do in the system's preparation is to simulate a Red Hat distribution. Don't worry, it's not difficult when you follow the guide. The Red Hat is differenciated by Ubuntu in the directory architecture. So we'll create some symbolic link to simulate the Red Hat architecture:

sudo ln -s /usr/bin/awk /bin/awk
sudo ln -s /usr/bin/rpm /bin/rpm
sudo ln -s /usr/bin/basename /bin/basename
sudo ln -s /etc /etc/rc.d

To finish with this step, we have to create a file /etc/redhat-release that countain the information of the Red Hat system, this file is scanned by the installer and if it doesn't exist or if the information countained are wrong, the installer will not work:

sudo gedit /etc/redhat-release

Copy/Paste the following text:

Red Hat Linux release 3.0 (drupal)

2.3 Users / groups Oracle's creation and some modification

This will simply create the system requirement:


sudo userdel nobody
sudo groupadd oinstall
sudo groupadd dba
sudo groupadd nobody
sudo useradd -g oinstall -G dba -p passwd -d /home/oracle oracle -s /bin/bash
sudo useradd -g nobody nobody

Now, we create the directory where Oracle will be installed

sudo mkdir -p /u01/app/oracle
sudo mkdir -p /u02/oradata
sudo chown -R oracle:oinstall /u01 /u02
sudo chmod -R 775 /u01 /u02

At the end of /etc/security/limits.conf add the following:


* soft nproc 2047
* hard nproc 16384
* soft nofile 1024
* hard nofile 65536

In the file /etc/pam.d/login, /etc/pam.d/su uncomment the following:

session required /lib/security/pam_limits.so

Add this line to /etc/profile

if [ $USER = "oracle" ]; then
ulimit -u 16384 -n 65536
fi

Add the following lines to the end of /home/oracle/.bashrc (open it in root or oracle user):


umask 022
PATH=${PATH}:/u01/app/oracle/oracle/product/10.2.0/db_1/bin/

ORACLE_HOME=/u01/app/oracle/oracle/product/10.2.0/db_1/
ORACLE_SID=orcl
ORATAB=/etc/oratab
ORACLE_HOME_LISTNER=$ORACLE_BASE
ORACLE_BASE=$ORACLE_HOME

export ORACLE_BASE ORACLE_SID ORATAB ORACLE_HOME ORACLE_HOME_LISTNER

The system is now correctly configurated. Well going to the next step.

Launch a terminal and execute the following:

cd your_database_dir
xhost +
sudo su
su oracle
ORACLE_BASE=/u01/app/oracle
ORACLE_SID=orcl
export ORACLE_BASE ORACLE_SID
unset ORACLE_HOME
unset TNS_ADMIN
ORATAB=/etc/oratab
umask 022
./runInstaller

Open a terminal and do (in our case)

sudo /u01/app/oracle/oracle/product/10.2.0/db_1/oraInventory/orainstRoot.sh
sudo /u01/app/oracle/oracle/product/10.2.0/db_1/root.sh

Saturday, November 14, 2009

To start up the ASM instance

To start up the ASM instance, I then simply issue the STARTUP MOUNT command. Here is how a successful ASM instance startup appears in the Linux environment:

$> export ORACLE_SID=+ASM

$> sqlplus "sys as sysdba"
SQL*Plus: Release 10.1.0.2.0 - Production on Tue Dec 13 16:58:17 2005
Copyright (c) 1982, 2004, Oracle. All rights reserved.
Enter password: ********

Connected to an idle instance.

SQL> startup mount;
ASM instance started

Total System Global Area 100663296 bytes
Fixed Size 787648 bytes
Variable Size 99875648 bytes
Database Buffers 0 bytes
Redo Buffers 0 bytes

ASM diskgroups mounted

Waiting for Oracle CSS service to be available before starting

Despite knowing the problem, I wasn't able to find a solution until I came across Jeff Hunter's Oracle blog. In it, he correctly noted that due to a known bug, the /etc/inittab file must be manually modified to support Oracle ASM auto-start on RHEL.
Specifically, the respawn line for the init.cssd process must fall between the wait for runlevel 2 and runlevel 3

l2:2:wait:/etc/rc.d/rc 2
h1:35:respawn:/etc/init.d/init.cssd run >/dev/null 2>&1 l3:3:wait:/etc/rc.d/rc 3


comment eny like
h1:35:respawn:/etc/init.d/init.cssd run >/dev/null 2>&1

Thursday, October 1, 2009

ASM Installation.

http://www.oracle-base.com/articles/10g/ASMUsingASMLibAndRawDevices.php

Sunday, August 30, 2009

Automating Database Startup and Shutdown on Linux

Automating Database Startup and Shutdown on Linux

With Oracle 10g, Oracle switched from recommending the "su" command to the "rsh" command. In Oracle 10g release 2, the dbstart command includes an automatic start of the listener, so there are some differences between the two versions, but the following represents the preferred method for Oracle 10g.

Once the instance is created, edit the "/etc/oratab" file setting the restart flag for each instance to 'Y'.
TSH1:/u01/app/oracle/product/9.2.0:Y
Next, create a file called "/etc/init.d/dbora" as the root user, containing the following.
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Change the value of ORACLE_HOME to specify the correct Oracle home
# directory for your installation.

ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
#
# Change the value of ORACLE to the login name of the
# oracle owner at your site.
#
ORACLE=oracle

PATH=${PATH}:$ORACLE_HOME/bin
HOST=`hostname`
PLATFORM=`uname`
export ORACLE_HOME PATH
#
if [ ! "$2" = "ORA_DB" ] ; then
if [ "$PLATFORM" = "HP-UX" ] ; then
remsh $HOST -l $ORACLE -n "$0 $1 ORA_DB"
exit
else
rsh $HOST -l $ORACLE $0 $1 ORA_DB
exit
fi
fi
#
case $1 in
'start')
$ORACLE_HOME/bin/dbstart $ORACLE_HOME
;;
'stop')
$ORACLE_HOME/bin/dbshut $ORACLE_HOME
;;
*)
echo "usage: $0 {start|stop}"
exit
;;
esac
#
exit
Use the chmod command to set the privileges to 750.
chmod 750 /etc/init.d/dbora
Associate the dbora service with the appropriate run levels and set it to auto-start using the following command.
chkconfig --level 345 dbora on
The relevant instances should now startup/shutdown automatically at system startup/shutdown.

This method relies on the presence of an RSH server, which requires additional packages and configuration.
# Install the rhs and rsh-server packages from the OS CD/DVD.
rpm -Uvh --force rsh-*

# Enable rsh and rlogin.
chkconfig rsh on
chkconfig rlogin on
service xinetd reload
This can be quite problematic when attempting to use this method under FC5 and FC6, where rsh is deprecated. As a result, I prefer to use the "su" command method.

su $ORACLE $0 $1 ORA_DB

This method can also be used for 11g databases that are not using ASM or RAC.

Known Issues
When using Oracle 10g Release 2, calling dbstart might result in the following error message:

Failed to auto-start Oracle Net Listener using /ade/vikrkuma_new/oracle/bin/tnslsnr

This is due to a hard coded path in the dbstart script. To correct this, edit the "$ORACLE_HOME/bin/dbstart" script and replace the following line (approximately line 78):
ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle
With this:
ORACLE_HOME_LISTNER=$ORACLE_HOME
The dbstart script shold now start the listener as expected.

For more information see:


my testing result for ORHEL4

#!/bin/sh
#kconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Change the value of ORACLE_HOME to specify the correct Oracle home
# directory for your installation.

ORACLE_HOME=/u01/app/oracle/product/10.2.0/db
#
# Change the value of ORACLE to the login name of the
# oracle owner at your site.
#
ORACLE=oracle

PATH=${PATH}:$ORACLE_HOME/bin
HOST=`hostname`
PLATFORM=`uname`
export ORACLE_HOME PATH

# set the asm device permission

chown oracle:dba /dev/hdb5
chown oracle:dba /dev/hdb6

case $1 in
'start')
su - oracle -c dbstart $ORACLE_HOME
;;
'stop')
su - oracle -c dbshut $ORACLE_HOME
;;
*)
echo "usage: $0 {start|stop}"
exit
;;
esac

exit

Create the Database Control Repository and setup the OC4J Application Server

Create the Database Control Repository and setup the OC4J Application Server

Make sure, that you can connect to the Repository Database (Test it with SQL*Plus). Examples for Setup Files can be found here:

Windows

Linux

LISTENER.ORA listener.ora
SQLNET.ORA sqlnet.ora
TNSNAMES.ORA tnsnames.ora

Now start the Oracle EM dbconsole Build Script ($ORACLE_HOME/bin/emca for Linux and $ORACLE_HOME\Bin\emca.bat for Windows).

$ emca -repos create
$ emca -config dbcontrol db

STARTED EMCA at Fri May 14 10:43:22 MEST 2004
Enter the following information about the database
to be configured.


Listener port number: 1521
Database SID:
AKI1
Service name:
AKI1.WORLD
Email address for notification:
martin dot zahn at akadia dot ch
Email gateway for notification:
mailhost
Password for dbsnmp:
xxxxxxx
Password for sysman:
xxxxxxx
Password for sys:
xxxxxxx

---------------------------------------------------------
You have specified the following settings

Database ORACLE_HOME: /opt/oracle/product/10.1.0
Enterprise Manager ORACLE_HOME: /opt/oracle/product/10.1.0

Database host name ..........: akira
Listener port number .........: 1521
Database SID .................: AKI1
Service name .................: AKI1
Email address for notification: martin dot zahn at akadia dot ch
Email gateway for notification: mailhost
---------------------------------------------------------
Do you wish to continue? [yes/no]: yes
AM oracle.sysman.emcp.EMConfig updateReposVars
INFO: Updating file ../config/repository.variables ...

Now wait about 10 Minutes to complete!

M oracle.sysman.emcp.EMConfig createRepository
INFO: Creating repository ...
M oracle.sysman.emcp.EMConfig perform
INFO: Repository was created successfully
M oracle.sysman.emcp.util.PortQuery findUsedPorts
INFO: Searching services file for used port
AM oracle.sysman.emcp.EMConfig getProperties
...........
...........
INFO: Starting the DBConsole ...
AM oracle.sysman.emcp.EMConfig perform
INFO: DBConsole is started successfully
INFO: >>>>>>>>>>> The Enterprise Manager URL is http://akira:5500/em <<<<<<<<<<<
Enterprise Manager configuration is completed successfully
FINISHED EMCA at Fri May 14 10:55:25 MEST 2004

Try to connect to the database Control

http://akira:5500/em

If you look at the installed schemas, you can now find the SYSMAN schema, which is the database Control Repository.

Troubleshooting

If you have troubles to connect, check your local configuration which can be found in $ORACLE_HOME/_. For Example our DbConsole Setup Directory looks as follows:

$ pwd
/opt/oracle/product/10.1.0/akira_AKI1/sysman/config

$
ls -l
-rw-r--r-- b64InternetCertificate.txt
-rw-r--r-- emagentlogging.properties
-rw-r--r-- emd.properties
-rw-r--r-- emomsintg.xml
-rw-r--r-- emomslogging.properties
-rw-r--r-- emoms.properties
-rw-r--r-- OUIinventories.add

The most important file is emoms.properties, where you can find all the configuration parameters.

#Fri May 14 10:54:49 CEST 2004
oracle.sysman.emSDK.svlt.ConsoleServerName=
akira_Management_Service
oracle.sysman.eml.mntr.emdRepPwd=0b878f6184e8319d
emdrep.ping.pingCommand=/bin/ping
oracle.sysman.eml.mntr.emdRepPort=1521
oracle.sysman.eml.mntr.emdRepDBName=AKI1.WORLD
oracle.sysman.emSDK.svlt.ConsoleMode=standalone
oracle.sysman.emRep.dbConn.statementCacheSize=30
oracle.sysman.db.isqlplusUrl=
http\://akira\:5560/isqlplus/dynamic
oracle.sysman.emSDK.svlt.ConsoleServerPort=5500
oracle.sysman.eml.mntr.emdRepRAC=FALSE
oracle.sysman.emSDK.emd.rt.useMonitoringCred=true
oracle.sysman.eml.mntr.emdRepPwdEncrypted=TRUE
oracle.sysman.db.isqlplusWebDBAUrl=
http\://akira\:5560/isqlplus/dba/dynamic
oracle.sysman.emSDK.svlt.ConsoleServerHost=akira
oracle.sysman.emSDK.svlt.ConsoleServerHTTPSPort=5500
oracle.sysman.eml.mntr.emdRepServer=akira
oracle.sysman.eml.mntr.emdRepSID=AKI1
oracle.sysman.emSDK.sec.ReuseLogonPassword=true
oracle.sysman.eml.mntr.emdRepConnectDescriptor=
(DESCRIPTION\=(ADDRESS_LIST\=
(ADDRESS\=(PROTOCOL\=TCP)(HOST\=akira)(PORT\
=1521)))(CONNECT_DATA\=(SERVICE_NAME\=AKI1)))
oracle.sysman.eml.mntr.emdRepUser=SYSMAN
oracle.sysman.db.adm.conn.statementCacheSize=2
oracle.sysman.db.perf.conn.statementCacheSize=30

Automatically start and stop the DB-Console

$ emctl start dbconsole
$ emctl stop dbconsole
$ emctl status dbconsole

Oracle Enterprise Manager 10g Database
Control Release 10.1.0.2.0
Copyright (c) 1996, 2004 Oracle Corporation.
All rights reserved.
http://akira:5500/em/console/aboutApplication
Oracle Enterprise Manager 10g is running.
---------------------------------------------------
Logs are generated in directory
/opt/oracle/product/10.1.0/akira_AKI1/sysman/log

Friday, August 28, 2009

E-mail sending with authentication

SMTP with authentication

PROCEDURE TEST_MAIL
is
crlf VARCHAR2(2):= UTL_TCP.CRLF;
connection utl_smtp.connection;
mailhost VARCHAR2(30) := 'XX.XX.XX.XX';
header VARCHAR2(1000);
str_user_name VARCHAR2(200);
BEGIN
connection := utl_smtp.open_connection(mailhost,25);
header:= 'Date: 'TO_CHAR(SYSDATE - 19800/86400 ,'dd Mon yyyy hh24:mi:ss')crlf
'From: ''upul@dpmco.com'crlf
'Subject: ''Pending Progress Report(s) Notification - 'initcap(str_user_name)'.'crlf
'To: ''thiranagamage@gmail.com'crlf
'CC: ''upul@dpmco.com'crlf
'CC: ''pradeepi@dpmco.com';
--
-- Handshake with the SMTP server
--
utl_smtp.ehlo(connection, mailhost);
utl_smtp.command( connection, 'AUTH LOGIN');
utl_smtp.command( connection, utl_raw.cast_to_varchar2( utl_encode.base64_encode( utl_raw.cast_to_raw( 'upul@dpmco.com' ))) );
utl_smtp.command( connection, utl_raw.cast_to_varchar2( utl_encode.base64_encode( utl_raw.cast_to_raw( 'XXXX' ))) );


utl_smtp.mail(connection, 'upul@dpmco.com');
utl_smtp.rcpt(connection, 'thiranagamage@gmail.com');
utl_smtp.rcpt(connection, 'upul@dpmco.com');
utl_smtp.rcpt(connection, 'pradeepi@dpmco.com');
utl_smtp.open_data(connection);
--
-- Write the header
--
utl_smtp.write_data(connection, header);
--
-- The crlf is required to distinguish that what comes next is not simply part of the header..
--
utl_smtp.write_data(connection, crlf 'Please do not reply to this message. This is an unmonitored address for outgoing mail notification only.');
utl_smtp.close_data(connection);
utl_smtp.quit(connection);
commit;
END;