LINUX下启动ORACLE

手动启动:
用 oracle用户登录(或su - oracle)
lsnrctl start 
sqlplus / as sysdba
  startup
  exit

自动启动,要编写一个启动脚本,用root用户拷到/etc/init.d下,取名叫oracle
然后, chkconfig oracle on,即可加入服务列表
/etc/init.d/oracle start   #启动
/etc/init.d/oracle stop  #停止
脚本的示例(里面的变量要按实际情况修改):
#!/bin/bash 
#
# chkconfig:  345 99 01
# description: This is a program that is responsible for taking care of
# configuring the Oracle Database 11g Stardard/Enterprise Edition and its associated 
# services. 
#

# Source fuction library
if [ -f /lib/lsb/init-functions ]
then
	. /lib/lsb/init-functions
elif [ -f /etc/init.d/functions ]
then
	. /etc/init.d/functions
fi

# Set path if path not set (if called from /etc/rc)
case $PATH in
    "") PATH=/bin:/usr/bin:/sbin:/etc
        export PATH ;;
esac

# Save LD_LIBRARY_PATH
SAVE_LLP=$LD_LIBRARY_PATH

RETVAL=0

ORACLE_OWNER=oracle
ORACLE_OWNER_HOME=/opt/oracle
ORACLE_BASE=$ORACLE_OWNER_HOME/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
ORACLE_SID=orcl
ORACLE_UNQNAME=$ORACLE_SID
LSNR=$ORACLE_HOME/bin/lsnrctl
SQLPLUS=$ORACLE_HOME/bin/sqlplus
STARTDB_SQL=$(mktemp /tmp/start.XXXXXX)
echo -e "startup;\nquit;\n" > $STRTDB_SQL
STOPDB_SQL=$(mktemp /tmp/stop.XXXXXX)
echo -e "shutdown immediate;\nquit;\n" > $STOPDB_SQL
SU=/bin/su
export ORACLE_HOME
export ORACLE_SID
export PATH=$ORACLE_HOME/bin:$PATH
LOG="$ORACLE_HOME_LISTNER/listener.log"

export LC_ALL=C

if [ $(id -u) != "0" ]
then
    echo "You must be root to run the configure script.  Login as root and then run the 
configure script."
    exit 1
fi

if [ -f /etc/redhat-release ]
then
    . /etc/init.d/functions

    init_status()
    {
	return 0
    }
    exit_status()
    {
	exit $?
    }
    success_status()
    {
	success
	echo
    }
    failure_status()
    {
	failure $?
	echo
    }

elif [ -f /etc/SuSE-release ]
then
    . /etc/rc.status

    init_status()
    {
	rc_reset
    }
    success_status()
    {
	echo "OK"
	return 0
    }
    failure_status()
    {
	echo "Failed"
	return 1
    }
    exit_status()
    {
	exit $?
    }

else
    if [ -d /etc/default ]
    then
        CONFIGURATION="/etc/default/$CONFIG_NAME"
    fi

    init_status()
    {
        return 0
    }

    success_status()
    {
        echo "OK"
        return 0
    }

    failure_status()
    {
        echo "Failed"
        return 0
    }

    exit_status()
    {
        exit $?
    }
fi


init_status

start() {

	status=`ps -ef | grep tns | grep oracle`
	if [ "$status" == "" ]
	then
		if [ -f $ORACLE_HOME/bin/tnslsnr ]  
	        then
		     	echo "Starting Oracle Net Listener."
        		$SU -s /bin/bash $ORACLE_OWNER -c "$LSNR  start" # > /dev/null 2>&1
		fi
	fi
	echo "Starting Oracle Database 11g Instance."
	$SU -s /bin/bash  $ORACLE_OWNER -c "$SQLPLUS -s /nolog @${STARTDB_SQL}" # > /dev/null 2>&1
    RETVAL=$?
    if [ $RETVAL -eq 0 ]
    then
        echo
    else
        echo Failed to start Oracle Net Listener using $ORACLE_HOME/bin/tnslsnr\
 	      and Oracle Database using $ORACLE_HOME/bin/sqlplus.
        RETVAL=1
	return $RETVAL
    fi
    
}

startconsole() {

    $SU -s /bin/bash  $ORACLE_OWNER -c "$ORACLE_HOME/bin/emctl start dbconsole &" # > /dev/null 2>&1
    RETVAL=$?
    return $RETVAL
}

stop() {

    # Stop Oracle 11g  Database and Listener
    $SU -s /bin/bash  $ORACLE_OWNER -c "$ORACLE_HOME/bin/emctl stop dbconsole &" # > /dev/null 2>&1

    echo Shutting down Oracle Database 11g Instance.
	$SU -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s /nolog @${STOPDB_SQL}" # > /dev/null 2>&1
	echo Stopping Oracle Net Listener.
    $SU -s /bin/bash  $ORACLE_OWNER -c "$LSNR stop" # > /dev/null 2>&1
    RETVAL=$?
    echo 
    if [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$LSNR
    then
        return $RETVAL
    fi
}

stopconsole() {
    # Stop Oracle 11g  Database and Listener
    $SU -s /bin/bash  $ORACLE_OWNER -c "$ORACLE_HOME/bin/emctl stop dbconsole &" # > /dev/null 2>&1
    RETVAL=$?
    return $RETVAL
}

# See how we were called
case "$1" in
  start)
	start
       ;;
  startconsole)
	startconsole
       ;;
  stop)
	stop
        ;;
  stopconsole)
	stopconsole
        ;;
  restart|reload|force-reload)
        stop
        start
        RETVAL=$?
        ;;
	*)
        echo $"Usage: $0 {start|stop|restart|reload|force-reload}"
        exit 1
esac

你可能感兴趣的:(oracle)