Monday, January 30, 2006

Meaning of Oracle Release Numbers

Have you know what is the meaning of oracle 9.2.0.1.0 or 9.2.0.4.0?

Oracle release numbers consist of 5 digits - for example Oracle9i.9.2.0.1.0 means First digit is the major version number (8), second is the release number (1), third is the maintenance release number (7), fourth is the generic patch number (3) and fifth is the platform specific patch set number (2).

Sunday, January 29, 2006

Report changes from alert.log file (unix server only)

In the morning yo want to check the alert.log file, but only for the changes. There is some work required to determine when udid you last time look at the file, where to start reading etc. Also on Monday you want to report since Friday etc.

The following commands will extract only the changes since the last time you have run the report:

# get the log filename
log=$ORACLE_BASE/admin/$ORACLE_SID/bdump/alert_${ORACLE_SID}.log

if [[ -f $log.last ]] then
#get the last reported line
today=`cat $log.last`
else
#find the last date in the file
lastdt=`tail $log|grep :|grep 200|tail -1|cut -c-11`

#get the first occurrence of that date
today=`grep -n "$lastdt" $log|head -1|tr ':' '\012'|head -1`
fi

#remember the last line:

echo `wc -l $log`>$log.last


#today's file
newlog=/tmp/mon_alert_${ORACLE_SID}.log

#extract only today's data
sed -n $today,'$'p $log|tr '\09' ' '>$newlog

# the rest is up to you.



Alternatively, you could run a cron job to get the number of lines:

# get the log filename
log=$ORACLE_BASE/admin/$ORACLE_SID/bdump/alert_${ORACLE_SID}.log
echo `wc -l $log`>$log.last


#In the morning you just report data from the file:
#today's file
newlog=/tmp/mon_alert_${ORACLE_SID}.log

#extract only today's data
sed -n $today,'$'p $log|tr '\09' ' '>$newlog

Look for anything of interest in the $newlog file

Friday, January 20, 2006

Unix Core Files

When you are running a program on a UNIX machine that terminates abnormally, possibly because it crashed, the operating system creates a core file in the current working directory. The system dumps information into the core file about what the program was doing at the time it crashed, e.g., which subroutine it was calling or what memory address it was accessing. The format of the information in this file is pretty cryptic, but the file can be post-processed by an appropriate debugging tool to give application developers useful information. If you are not trying to diagnose a bug in an application, the file contains no other useful information and can be safely deleted. In fact, it should be deleted because often it is quite large (>100 MB).

How can you prevent the core file from getting so large? One option is to create a directory named core in your current working directory. When the application crashes, the operating system cannot write the core file because a directory with the name already exists. A second option is to set a limit on how big the core file is allowed to grow using the command

limit coredumpize xxxx

xxxx is the maximum size in kB that the core file is allowed to be. In theory, the core file will never exceed the limit. However, in practice, some operating systems ignore it. This command has been incorporated into the standard NML .cshrc file.

Tuesday, January 17, 2006

oraenv and coraenv Utilities

The oraenv and coraenv utilities both aid in setting the Oracle environment on UNIX systems (other utilities exist on Windows platform that enable the Oracle Home to be set.) The coraenv utility is appropriate for the UNIX C Shell; oraenv should be used with either the Bourne or Korn shells.

Database operations require the ORACLE_HOME to be set before the user may access the database. If ORACLE_HOME is not set, commands such as sqlplus, exp, or any other utility for that matter, will not be found.

Both utilities are shell scripts that do the same thing in the different UNIX shells. They will prompt for a SID of the database unless ORAENV_ASK is set to N. The utility will also append the ORACLE_HOME value to the path, marking the location of the utility.

The oraenv command will prompt for the SID of the database that you wish $ORACLE_HOME to access.

$ . oraenv
ORACLE_SID = [] ? ASG920

The dbhome utility can now be used to verify that $ORACLE_HOME is correct.

$ dbhome
/usr/oracle/9.2.0

The “dot space” part of the command is required to make the environment change with the parent shell, as opposed to entering a command without it which would only affect the subshell running that process.

These commands can be used to avoid specifying the network service name when issuing commands. For instance, without using oraenv, an sqlplus command would look like:

$ sqlplus system/manager@nameofservice as sysdba

whereas after oraenv has been executed, the following command would work:

$ sqlplus system/manager as sysdba

Saturday, January 14, 2006

Starting and Stopping on Windows

The dbstart and dbstop shell scripts do not exist on Windows platforms. Consequently Oracle database startup and shutdown is implemented completely differently. The oradim utility is used on the Windows platform to perform these tasks.

C:\oracle9i\bin\oradim -startup -sid ORCL92 –usrpwd manager
-starttype SRVC,INST -pfile C:\oracle9i\admin\ORCL92\pfile\init.ora

  • startup — Indicates that the specified instance should be started.
  • sid — The SID of the database to start.
  • usrpwd — The password for the database user.
  • starttype — Specifies whether to start the instance, the service, or both (SRVC, INST).

The following command can be used to shutdown the instance with oradim:

C:\oracle9i\bin\oradim -shutdown -sid ORCL92 -shutttype SRVC,INST
–shutmode A

Notice that no password is needed to perform this task.

The shuttype parameter specifies what is to be stopped – the service (SRVC), the instance (INST), or both (SRVC, INST). The shutmode specifies the method that should perform the shutdown – (A)bort, (I)mmediate, or (N)ormal.

Each operation, regardless of success, is logged in the oradim log file (ORACLE_HOME\database\OraDim.Log). This file should be checked for errors after each oradim command is executed.

The oradim utility provides more than just the ability to start and stop Windows databases. oradim can create and edit databases. It also allows DBAs to configure script-based installation mechanisms, bypassing the Oracle Database Configuration Assistant’s graphical user interface (GUI).

For a reference of all oradim commands, use the oradim–help command.

Thursday, January 12, 2006

Automatic Startup & Shutdown

The following list summarizes the functions performed by the different Oracle startup and shutdown scripts (which are invoked during system startup and shutdown, respectively).

Script

Description

$ORACLE_HOME/bin/dbstart

Ensures a clean startup of database instance(s), even after system failure

$ORACLE_HOME/bin/dbshut

Ensures a clean shutdown for database instances

/var/opt/oracle/oratab

Contains a field that specifies whether a particular database instance should be brought up/down at system startup /shutdown time by specifying "Y" in this field, the "dbstart" and "dbshut" scripts bring this database and instance up or down.

/etc/inittab

Controls the initialization process




Relevant Files

Description

/etc/init.d/dbstart

Script to call $ORACLE_HOME/bin/dbstart

/etc/init.d/dbshut

Script to call $ORACLE_HOME/bin/dbshut

/etc/rc2.d/S99dbstart

Link to the script /etc/init.d/dbstart

/etc/rc0.d/K01dbshut

Link to the script /etc/init.d/dbshut

$ORACLE_HOME/lsnr_start.sh

Script to start listener

$ORACLE_HOME/lsnr_stop.sh

Script to stop listener

System V initialization scripts are contained in /etc/rc.d directories where "n" is the run-level value of the script. A run-level of 0 usually signifies power shutdown mode, while a run-level of 2 signifies multi-user mode. The directories contain initialization scripts such as "S75cron" and "K30tcp". These scripts are named using the following method:

[K or S][two-digit number][descriptive filename]

Names starting with "S" indicate scripts that are called at startup; names starting with "K" indicate scripts that are called at shutdown time.

Scripts containing larger numbers in their names are executed after those with lower numbers. Oracle startup scripts typically contain larger numbers in their names, such as "S99oracle", indicating that the script should be run after the system has been started up. Oracle shutdown script names, on the other hand, usually contain smaller numbers, such as "K01oracle" indicating that the script should be run before system shutdown.

Every Oracle installation has an 'oratab' file which contains an entry for every database in the system. You will need 'root' privileges to accomplish the following:

STEPS

1. Edit the 'oratab' file (/var/opt/oracle/oratab):

mlive:/export/home/app/oracle/product/8.1.6:Y

2. As oracle user, create the following shell script files “lsnr_start.sh” and “lsnr_stop.sh” in the $ORACLE_HOME directory and ensure that both files are executable by the oracle userid. Since all files “lsnrctl” needs are not in the default directory, those scripts that include the needed information have to be used to start listener:

lsnr_start :

PATH=/export/home/app/oracle/product/9.2.0.1.0/bin:.;

export PATH

ORATAB=/var/opt/oracle/oratab;

export ORATAB

ORACLE_HOME=/export/home/app/oracle/product/9.2.0.1.0;

export ORACLE_HOME

lsnrctl start

lsnr_stop :

PATH=/export/home/app/oracle/product/9.2.0.1.0/bin:.;

export PATH

ORATAB=/var/opt/oracle/oratab;

export ORATAB

ORACLE_HOME=/export/home/app/oracle/product/9.2.0.1.0;

export ORACLE_HOME

lsnrctl stop

3. As root, create the following OS script files dbstart and dbshut in the /etc/init.d directory and ensure that both files are executable by the oracle userid:

dbstart :

su oracle -c /export/home/app/oracle/product/9.2.0.1.0/bin/dbstart

su oracle -c /export/home/app/oracle/product/9.2.0.1.0/lsnr_start.sh

dbshut :

su oracle -c /export/home/app/oracle/product/9.2.0.1.0/bin/dbshut

su oracle -c /export/home/app/oracle/product/9.2.0.1.0/lsnr_stop.sh

4. As a root, link the dbshut and dbstart to /etc/rc*.d directory:

# ln -s /etc/init.d/dbshut /etc/rc0.d/K01dbshut

# ln -s /etc/init.d/dbstart /etc/rc2.d/S99dbstart


Relevant Oracle Metalink Documents

1005041.6 How to Automatically Start the Listener On UNIX

61333.1 Automatic startup and shutdown of oracle instances

105957.1 How to setup Oracle to startup automatically if system is restarted

1068670.6 Listener will not start autostart at boot time

1031930.6 Solaris RC&RC.D startup&shutdown scripts

91815.1 The Annotated dbstart Script

Thursday, January 05, 2006

Availability of the DB and listener

Under the “/export/tmscs/db_cron” folder, “db_check.sh” script seen below is created.

db_check.sh

#!/bin/sh
#
############################
# FUNCTION: IsListenerRunning
############################
#
IsListenerRunning()
{
ps -ef | egrep '/bin/tnslsnr' | egrep -v 'grep' > /dev/null 2>&1
}

############################

# FUNCTION: IsListenerUp

############################

#

IsListenerUp()

{

lsnrctl status > /dev/null 2>&1

}

############################

# MAIN PROGRAM

############################

#

CHECK_LISTENER=1

CHECK_LISTENER_IS_UP=1

SPOOLFILE=/export/tmscs/db_cron/db.log

#

# check if database is running

#

if [ `echo "select dummy||'OK' from dual;" | sqlplus -s system/manager | grep XOK` ]

then

IS_OK="XOK"

else

IS_OK="FALSE"

fi

#

# check if listener is running

#

IsListenerRunning || CHECK_LISTENER=0

#

# check if listener is up#

IsListenerUp || CHECK_LISTENER_IS_UP=0

date +"Date is %D %nTime is %T" > $SPOOLFILE



if [ $IS_OK = "XOK" ]

then

echo "SELECT 'Database has been up and running for '|| round(24*(SYSDATE-logon_time),1) || ' hour(s)' FROM sys.V_\$SESSION WHERE sid=1;" | sqlplus

-s system/manager | grep running >> $SPOOLFILE

else

echo "Database is down" >> $SPOOLFILE

fi

if [ $CHECK_LISTENER = 0 ]

then

echo "Listener is not Running" >> $SPOOLFILE

fi

if [ $CHECK_LISTENER_IS_UP = 0 ]

then

echo "Listener is down" >> $SPOOLFILE

lsnrctl start && echo "Listener is started succesfully" >> $SPOOLFILE

else

echo "Listener is up" >> $SPOOLFILE

fi
If listener is not running, script will start it. But if database is down, script will do nothing.

The crontab jobs executing this script is created under the user ROOT, and since ROOT user has already several crontab jobs, the new job line is added to the crontab file and then this file is submitted to the system (/var/spool/cron/crontabs/root);

15,30,45,01 * * * * su - oracle -c "/export/tmscs/db_cron/db_check.sh" > "/export/tmscs/db_cron/err.log"

And then to submit the file;

crontab crontab_filename

Essentially, root is the super user and can thus impersonate oracle without a password. su oracle will enable root to become oracle. The -c means 'execute the following command as oracle'. The extra '-' between su and oracle is crucial - because of this, the script is being executed as if the user oracle had logged in himself. In other words all environment variables like $ORACLE_HOME, $ORACLE_SID and $PATH are set correctly.

This job runs every fifteen minutes.

After running the script, the crontab job will produce 2 files (db.log and err.log) under the folder “/export/tmscs/db_cron”

db.log

It gives information about database and listener.

If database and listener are running;

Date is 01/07/03

Time is 10:12:57

Database has been up and running for 119.4 hour(s)

Listener is up

If database is down and listener is running;

Date is 01/07/03

Time is 13:53:43

Database is down

Listener is up

If database is up and listener is down;

Date is 01/07/03

Time is 13:54:37

Database has been up and running for 0 hour(s)

Listener is up

If both database and listener is down;

Date is 01/07/03

Time is 13:45:01

Database is down

Listener is not Running

Listener is down

err.log

$ more err.log

PATH is /usr/bin:

PATH is

/export/home/app/oracle/product/

9.2.0.1.0/bin:.:/usr/bin:.:/usr/local/bin

Sun Microsystems Inc. SunOS 5.7 Generic October 1998

You have mail.

Running Oracle .login ...

It shows the log of last process and if an error occurs, what the error is can be seen in this file;

Note that when the folder (/export/tmscs/db_cron) is changed both crontab and db_check.sh script files must be corrected.

Configuration :

  • Variable SPOOLFILE in db_check.sh file must be configured (now SPOOLFILE=/export/tmscs/db_cron/db.log)
  • Given Password for system user in db_check.sh file must be corrected (now system/manager)
  • Given path for db_clean.sql and err.log files must be corrected (now /export/tmscs/db_cron/)
  • All created scripts and folders must be owned by oracle:dba with the rights of “711”

Server and Database Naming

As servers and databases are deployed for global applications, it becomes critical that server and database names are standardized globally. This document provides the guidelines that should be followed to name servers and databases for global applications. The naming conventions detailed in this document are provided as a formula. Certain components of the formula have been standardized so that they can be utilized very easily. However, there will be exceptions where the naming convention cannot be applied to a global application. It is then up to the GEOs to get together and agree on a naming convention that works for the specific application and that can be implemented on a global basis.

Server Naming Formula: application + function . domain

Database Naming Formula: application + function + geo specification

The following tables provide the recommended abbreviation standards to be used in naming servers and databases for global applications.

Examples :

FUNCTION ABBREVIATION
Disaster Recovery database DR
Disaster Recovery server DR or DBDR
Test database TST
Test server TST or TEST
Development DEV
Training TRN
Release REL
Test Reporting TRP
DBnet (off SWAN) DBX
Middle tier MT Middle tier (partner) MTP
Web server WS

GEO DOMAIN
APAC singapore; japan
EMEA holland; turkey
Americas central; east

Notes:

  1. Oracle database names (SIDs) typically should be uppercase.

  2. There is no hard limit to the length of a server name. It is recommended that server names no more than 8-14 characters, if possible.

  3. Server names typically should be lower case.

  4. Server names can include a hyphen to separate the application and function components of the server name. However, it has been discovered that a hyphen in the server name causes a problem when the Oracle database init.ora parameter global_names is set to TRUE and the db_domain parameter is set to the server name. To avoid this problem, do not use a hyphen in the server name.

  5. The domain component of the server name will always be separated with a period ('.') from the application and function components.

  6. In applications where there will be multiple servers of the same function, sequence numbers can be used. As an example, Radiance has 3 different servers hosting the middle tier. They are named rad-mt01.domain, rad-mt02.domain, rad-mt03.domain.

  7. Oracle database names (SIDs) are limited to 8 charactersApplication component of Oracle database name can be up to 3 characters

    1. Application component of Oracle database name can be up to 3 characters
    2. Function component of Oracle database name can be up to 3 characters
    3. GEO specification is limited to 2 characters