Pages

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;

Tuesday, August 25, 2009

Enterprice manager configurationhapter

Getting Started with Oracle Enterprise Manager

Purpose

The Oracle Universal Installer installs Oracle Enterprise Manager Database Control when you install the Oracle software. Enterprise Manager Database Control provides a Web-based interface that you can use to manage your Oracle instance and database.

Topics

This chapter discusses the following:

Starting the Enterprise Manager dbconsole Process
Accessing Enterprise Manager Database Control
Granting EM Administrative Privileges to Other Users
Defining Blackout Periods
Setting Preferred Credentials

Starting the Enterprise Manager dbconsole Process


The dbconsole process must be started for you to access Oracle Enterprise Manager Database Control from a client browser. The dbconsole process is automatically started after installation. If the process is not started, you can manually start it at the command line as follows:

1.

Log on to the operating system as the oracle user. Issue the following command to start the dbconsole process:


emctl start dbconsole

Move your mouse over this icon to see the image

2.

You can check the status of the dbconsole process by issuing the following command:


emctl status dbconsole

Move your mouse over this icon to see the image



How to correct known errors

Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
Updating /u01/app/oracle/product/10.2.0/db/localhost.localdomain_dpg/sysman/config/emd.properties...resetTZ failed.
The agentTZRegion in:
/u01/app/oracle/product/10.2.0/db/localhost.localdomain_dpg/sysman/config/emd.properties
is not in agreement with what the agent thinks it should be.
Fix your environment.

Pick a TZ value that corresponds to time zone settings listed in:
/u01/app/oracle/product/10.2.0/db/sysman/admin/supportedtzs.lst

Saturday, August 22, 2009

Oracle Installation RHEL 4

In Oracle Database 10g (10.1.0.2) Installation.

this article I'll describe the installation of Oracle Database 10g (10.1.0.2) on Red Hat Enterprise Linux 4 (RHEL4). The article is based on a server installation with a minimum of 2G swap, secure Linux disabled and the following package groups installed:

  • X Window System
  • GNOME Desktop Environment
  • Editors
  • Graphical Internet
  • Text-based Internet
  • Server Configuration Tools
  • Development Tools
  • Administration Tools
  • System Tools
Alternative installations may require more packages to be loaded, in addition to the ones listed below.

Download Software

Download the following software:

Unpack Files

First unzip the files:
gunzip ship.db.cpio.gz
Next unpack the contents of the files:
cpio -idmv <>
You should now have a single directory (Disk1) containing installation files.

Hosts File

The /etc/hosts file must contain a fully qualified name for the server:
    

Set Kernel Parameters

Add the following lines to the /etc/sysctl.conf file:
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
# semaphores: semmsl, semmns, semopm, semmni
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
Run the following command to change the current kernel parameters:
/sbin/sysctl -p
Add the following lines to the /etc/security/limits.conf file:
*               soft    nproc   2047
* hard nproc 16384
* soft nofile 1024
* hard nofile 65536
Add the following line to the /etc/pam.d/login file, if it does not already exist:
session    required     /lib/security/pam_limits.so
Note by Kent Anderson: In the event that pam_limits.so cannot set privilidged limit settings see Bug 115442.

Disable secure linux by editing the /etc/selinux/config file, making sure the SELINUX flag is set as follows:
SELINUX=disabled
Alternatively, this alteration can be done using the GUI tool (Applications > System Settings > Security Level). Click on the SELinux tab and disable the feature.

Setup

Install the following packages:
# From RedHat AS4 Disk 2
cd /media/cdrom/RedHat/RPMS
rpm -Uvh setarch-1*
rpm -Uvh compat-libstdc++-33-3*

# From RedHat AS4 Disk 3
cd /media/cdrom/RedHat/RPMS
rpm -Uvh openmotif-2*
rpm -Uvh compat-db-4*

# From RedHat AS4 Disk 4
cd /media/cdrom/RedHat/RPMS
rpm -Uvh compat-gcc-32-3*
rpm -Uvh compat-gcc-32-c++-3*
Create the new groups and users:
groupadd oinstall
groupadd dba
groupadd oper

useradd -g oinstall -G dba oracle
passwd oracle
Create the directories in which the Oracle software will be installed:
mkdir -p /u01/app/oracle/product/10.1.0/db_1
chown -R oracle.oinstall /u01
Login as root and issue the following command:
xhost +
Edit the /etc/redhat-release file replacing the current release information (Red Hat Enterprise Linux AS release 4 (Nahant)) with the following:
redhat-3
Login as the oracle user and add the following lines at the end of the .bash_profile file:
# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR

ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/10.1.0/db_1; export ORACLE_HOME
ORACLE_SID=TSH1; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
#LD_ASSUME_KERNEL=2.4.1; export LD_ASSUME_KERNEL

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

Installation

Log into the oracle user. If you are using X emulation then set the DISPLAY environmental variable:
DISPLAY=:0.0; export DISPLAY
Start the Oracle Universal Installer (OUI) by issuing the following command in the Disk1 directory:
./runInstaller
During the installation enter the appropriate ORACLE_HOME and name then continue with a "software only" installation.

Post Installation

Create a new instance using the DBCA. If you get the "ORA-27125: unable to create shared memory segment" error when using the DBCA issue the following commands as the oracle user then try again:
cd $ORACLE_HOME/bin

mv oracle oracle.bin

cat >oracle <<"EOF" #!/bin/bash export DISABLE_HUGETLBFS=1 exec $ORACLE_HOME/bin/oracle.bin $@ EOF chmod +x oracle
I didn't encounter the previous issue myself, so hopefully you won't either.

Edit the /etc/redhat-release file restoring the original release information:
Red Hat Enterprise Linux AS release 4 (Nahant)
Finally edit the /etc/oratab file setting the restart flag for each instance to 'Y':
TSH1:/u01/app/oracle/product/10.1.0/db_1:Y

Sunday, August 16, 2009

My DataWarehouse Project



DataWarehouse

Many companies are investing huge amounts of money to create an enterprise data warehouse. A data warehouse is a centralized database that stores data from often autonomous information sources distributed in an enterprise. For instance, Toyota's data warehouse may collect information from its regional inventory and sales databases. Once the data warehouse is built, it is used to answer analytical or decision support queries. For instance, the Toyota data warehouse may be used to answer queries such as: "Which country and for what months were Alion and Yaris in high demand but short in supply?"

Business intelligence and data warehousing turn data into information, allowing organizations to deploy resources more effectively, increase operational efficiency, determine a campaign’s effectiveness, and identify new streams of revenue.

Building data warehouse is the best way to consolidate and organize all your data so it can be easily managed, accessed, and analyzed. Business intelligence (BI) is a broad category of applications and technologies for gathering, storing, analyzing, and providing access to data to help enterprise users make better business decisions using BI applications include the activities of decision support systems, query and reporting, online analytical processing (OLAP), statistical analysis, forecasting, and data mining.