Start/stopnbsp;Oracleamp;nbs…

2023-10-17 03:38
文章标签 start stopnbsp oracleamp nbs

本文主要是介绍Start/stopnbsp;Oracleamp;nbs…,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

原文地址:Start/stop Oracle database as Linux Service 作者:Hello顾问
[root@emsrv init.d]# cat dbora
#!/bin/sh
#
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.

ORA_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
ORA_OWNER=oracle

if [ ! -f $ORA_HOME/bin/dbstart ]
then
      echo "Oracle startup: cannot start"
      exit
fi

case "$1" in
      'start')
              # Start the Oracle databases:
              # The following command assumes that the oracle login
              # will not prompt the user for any values
              su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
              su - $ORA_OWNER -c ~${ORA_OWNER}/bin/orastart
              ;;
      'stop')
              # Stop the Oracle databases:
              # The following command assumes that the oracle login
              # will not prompt the user for any values
              su - $ORA_OWNER -c ~${ORA_OWNER}/bin/orashut
              su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
              ;;
esac



[root@emsrv init.d]# cat /u01/app/oracle/product/12.1.0/dbhome_1/bin/dbstart
#!/bin/sh
#
# $Id: dbstart.sh 22-may-2008.05:05:45 arogers Exp $
# Copyright (c) 1991, 2008, Oracle. All rights reserved.  
#

###################################
#
# usage: dbstart $ORACLE_HOME
#
# This script is used to start ORACLE from /etc/rc(.local).
# It should ONLY be executed as part of the system boot procedure.
#
# This script will start all databases listed in the oratab file
# whose third field is a "Y".  If the third field is set to "Y" and
# there is no ORACLE_SID for an entry (the first field is a *),
# then this script will ignore that entry.
#
# This script requires that ASM ORACLE_SID's start with a +, and
# that non-ASM instance ORACLE_SID's do not start with a +.
#
# If ASM instances are to be started with this script, it cannot
# be used inside an rc*.d directory, and should be invoked from
# rc.local only. Otherwise, the CSS service may not be available
# yet, and this script will block init from completing the boot
# cycle.
#
# If you want dbstart to auto-start a single-instance database that uses
# an ASM server that is auto-started by CRS (this is the default behavior
# for an ASM cluster), you must change the database's ORATAB entry to use
# a third field of "W" and the ASM's ORATAB entry to use a third field of "N".
# These values specify that dbstart auto-starts the database only after
# the ASM instance is up and running.
#
# Note:
# Use ORACLE_TRACE=T for tracing this script.
#
# The progress log for each instance bringup plus Error and Warning message[s]
# are logged in file $ORACLE_HOME/startup.log. The error messages related to
# instance bringup are also logged to syslog (system log module).
# The Listener log is located at $ORACLE_HOME_LISTNER/listener.log
#
# On all UNIX platforms except SOLARIS
# ORATAB=/etc/oratab
#
# To configure, update ORATAB with Instances that need to be started up
    Entries are of the form:
    $ORACLE_SID:$ORACLE_HOME::
    An example entry:
    main:/usr/lib/oracle/emagent_10g:Y
#
# Overall algorithm:
# 1) Bring up all ASM instances with 'Y' entry in status field in oratab entry
# 2) Bring up all Database instances with 'Y' entry in status field in
    oratab entry
# 3) If there are Database instances with 'W' entry in status field
    then
        iterate over all ASM instances (irrespective of 'Y' or 'N') AND
        wait for all of them to be started
    fi
# 4) Bring up all Database instances with 'W' entry in status field in
    oratab entry
#
#####################################

LOGMSG="logger -puser.alert -s "

trap 'exit' 1 2 3

# for script tracing
case $ORACLE_TRACE in
  T) set -x ;;
esac
     
# Set path if path not set (if called from /etc/rc)
SAVE_PATH=/bin:/usr/bin:/etc:${PATH} ; export PATH
SAVE_LLP=$LD_LIBRARY_PATH

# First argument is used to bring up Oracle Net Listener
ORACLE_HOME_LISTNER=$1
if [ ! $ORACLE_HOME_LISTNER ] ; then
  echo "ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener"
  echo "Usage: $0 ORACLE_HOME"
else
  LOG=$ORACLE_HOME_LISTNER/listener.log

  # Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to
  # a different ORACLE_HOME for each entry in the oratab.
  export ORACLE_HOME=$ORACLE_HOME_LISTNER

  # Start Oracle Net Listener
  if [ -x $ORACLE_HOME_LISTNER/bin/tnslsnr ] ; then
      echo "$0: Starting Oracle Net Listener" >> $LOG 2>&1
      $ORACLE_HOME_LISTNER/bin/lsnrctl start >> $LOG 2>&1 &
      VER10LIST=`$ORACLE_HOME_LISTNER/bin/lsnrctl version | grep "LSNRCTL for " | cut -d' ' -f5 | cut -d'.' -f1`
      export VER10LIST
  else
      echo "Failed to auto-start Oracle Net Listener using $ORACLE_HOME_LISTNER/bin/tnslsnr"
  fi
fi

# Set this in accordance with the platform
ORATAB=/etc/oratab
if [ ! $ORATAB ] ; then
  echo "$ORATAB not found"
  exit 1;
fi

# Checks Version Mismatch between Listener and Database Instance.
# A version 10 listener is required for an Oracle Database 10g database.
# Previous versions of the listener are not supported for use with an Oracle
# Database 10g database. However, it is possible to use a version 10 listener
# with previous versions of the Oracle database.
checkversionmismatch() {
  if [ $VER10LIST ] ; then
      VER10INST=`sqlplus -V | grep "Release " | cut -d' ' -f3 | cut -d'.' -f1`
      if [ $VER10LIST -lt $VER10INST ] ; then
          $LOGMSG "Listener version $VER10LIST NOT supported with Database version $VER10INST"
          $LOGMSG "Restart Oracle Net Listener using an alternate ORACLE_HOME_LISTNER:"
          $LOGMSG "lsnrctl start"
      fi
  fi
}

# Starts a Database Instance
startinst() {
  # Called programs use same database ID
  export ORACLE_SID

  # Put $ORACLE_HOME/bin into PATH and export.
  PATH=$ORACLE_HOME/bin:${SAVE_PATH} ; export PATH
  # add for bug # 652997
  LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${SAVE_LLP} ; export LD_LIBRARY_PATH
  PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora
  SPFILE=${ORACLE_HOME}/dbs/spfile${ORACLE_SID}.ora
  SPFILE1=${ORACLE_HOME}/dbs/spfile.ora

  echo ""
  echo "$0: Starting up database "$ORACLE_SID""
  date
  echo ""

  checkversionmismatch

  # See if it is a V6 or V7 database
  VERSION=undef
  if [ -f $ORACLE_HOME/bin/sqldba ] ; then
      SQLDBA=sqldba
      VERSION=`$ORACLE_HOME/bin/sqldba command=exit | awk '
          /SQL*DBA: (Release|Version)/ {split($3, V, ".") ;
          print V[1]}'`
      case $VERSION in
          "6") ;;
          *) VERSION="internal" ;;
      esac
  else
      if [ -f $ORACLE_HOME/bin/svrmgrl ] ; then
          SQLDBA=svrmgrl
          VERSION="internal"
      else
          SQLDBA="sqlplus /nolog"
      fi
  fi

  STATUS=1
  if [ -f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.dbf ] ; then
      STATUS="-1"
  fi
  if [ -f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.ora ] ; then
      STATUS="-1"
  fi
  pmon=`ps -ef | grep -w "ora_pmon_$ORACLE_SID"  | grep -v grep`
  if [ "$pmon" != "" ] ; then
      STATUS="-1"
      $LOGMSG "Warning: ${INST} "${ORACLE_SID}" already started."
  fi

  if [ $STATUS -eq -1 ] ; then
      $LOGMSG "Warning: ${INST} "${ORACLE_SID}" possibly left running when system went down (system crash?)."
      $LOGMSG "Action: Notify Database Administrator."
      case $VERSION in
          "6")  sqldba "command=shutdown abort" ;;
          "internal")  $SQLDBA $args <<EOF
connect internal
shutdown abort
EOF
              ;;
          *)  $SQLDBA $args <<EOF
connect / as sysdba
shutdown abort
quit
EOF
              ;;
      esac

      if [ $? -eq 0 ] ; then
          STATUS=1
      else
          $LOGMSG "Error: ${INST} "${ORACLE_SID}" NOT started."
      fi
  fi

  if [ $STATUS -eq 1 ] ; then
      if [ -e $SPFILE -o -e $SPFILE1 -o -e $PFILE ] ; then
          case $VERSION in
              "6")  sqldba command=startup ;;
              "internal")  $SQLDBA <<EOF
connect internal
startup
EOF
                  ;;
              *)  $SQLDBA <<EOF
connect / as sysdba
startup
quit
EOF
                  ;;
          esac

          if [ $? -eq 0 ] ; then
              echo ""
              echo "$0: ${INST} "${ORACLE_SID}" warm started."
          else
              $LOGMSG ""
              $LOGMSG "Error: ${INST} "${ORACLE_SID}" NOT started."
          fi
      else
          $LOGMSG ""
          $LOGMSG "No init file found for ${INST} "${ORACLE_SID}"."
          $LOGMSG "Error: ${INST} "${ORACLE_SID}" NOT started."
      fi
  fi
}

# Starts an ASM Instance
startasminst() {
  # Called programs use same database ID
  export ORACLE_SID
  ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
  # Called scripts use same home directory
  export ORACLE_HOME

  # For ASM instances, we have a dependency on the CSS service.
  # Wait here for it to become available before instance startup.

  # Is the 10g install intact? Are all necessary binaries present?
  if [ ! -x $ORACLE_HOME/bin/crsctl ]; then
      $LOGMSG "$ORACLE_HOME/bin/crsctl not found when attempting to start"
      $LOGMSG "  ASM instance $ORACLE_SID."

  else
      COUNT=0
      $ORACLE_HOME/bin/crsctl check css
      RC=$?
      while [ "$RC" != "0" ];
          do
          COUNT=`expr $COUNT + 1`
          if [ $COUNT = 15 ] ; then
              # 15 tries with 20 sec interval => 5 minutes timeout
              $LOGMSG "Timed out waiting to start ASM instance $ORACLE_SID"               
              $LOGMSG "  CSS service is NOT available."
              exit $COUNT
          fi
          $LOGMSG "Waiting for Oracle CSS service to be available before starting "
          $LOGMSG " ASM instance $ORACLE_SID. Wait $COUNT."
          sleep 20
          $ORACLE_HOME/bin/crsctl check css
          RC=$?
      done
  fi
  startinst
}

# Start of dbstartup script
#
# Loop for every entry in oratab file and and try to start
# that ORACLE.
#
# ASM instances need to be started before 'Database instances'
# ASM instance is identified with '+' prefix in ORACLE_SID
# Following loop brings up ASM instance[s]

cat $ORATAB | while read LINE
do
case $LINE in
  #*)                              ;;              #comment-line in oratab
  *)
  ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
  if [ "$ORACLE_SID" = '*' ] ; then
      # same as NULL SID - ignore this entry
      ORACLE_SID=""
      continue
  fi
  # Proceed only if last field is 'Y'.
  if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then
      # If ASM instances
      if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then
          INST="ASM instance"
          ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
          # Called scripts use same home directory
          export ORACLE_HOME
          # file for logging script's output
          LOG=$ORACLE_HOME/startup.log
          touch $LOG
          chmod a+r $LOG
          echo "Processing $INST "$ORACLE_SID": log file $ORACLE_HOME/startup.log"
          startasminst >> $LOG 2>&1
      fi
  fi
  ;;
esac
done

# exit if there was any trouble bringing up ASM instance[s]
if [ "$?" != "0" ] ; then
  exit 2
fi

#
# Following loop brings up 'Database instances'
#
cat $ORATAB | while read LINE
do
case $LINE in
  #*)                              ;;              #comment-line in oratab
  *)
  ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
  if [ "$ORACLE_SID" = '*' ] ; then
      # same as NULL SID - ignore this entry
      ORACLE_SID=""
      continue
  fi
  # Proceed only if last field is 'Y'.
  if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then
      # If non-ASM instances
      if [ `echo $ORACLE_SID | cut -b 1` != '+' ]; then
          INST="Database instance"
          ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
          # Called scripts use same home directory
          export ORACLE_HOME
          # file for logging script's output
          LOG=$ORACLE_HOME/startup.log
          touch $LOG
          chmod a+r $LOG
          echo "Processing $INST "$ORACLE_SID": log file $ORACLE_HOME/startup.log"
          startinst >> $LOG 2>&1
      fi
  fi
  ;;
esac
done

#
# Following loop brings up 'Database instances' that have wait state 'W'
#
cat $ORATAB | while read LINE
do
case $LINE in
  #*)                              ;;              #comment-line in oratab
  *)
  ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
  if [ "$ORACLE_SID" = '*' ] ; then
      # same as NULL SID - ignore this entry
      ORACLE_SID=""
      continue
  fi
  # Proceed only if last field is 'W'.
  if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "W" ] ; then
      W_ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
      # DB instances with 'W' (wait state) have a dependency on ASM instances via CRS.
      # Wait here for 'all' ASM instances to become available.
      cat $ORATAB | while read LINE
      do
      case $LINE in
          #*)                              ;;              #comment-line in oratab
          *)
          ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
          if [ "$ORACLE_SID" = '*' ] ; then
              # same as NULL SID - ignore this entry
              ORACLE_SID=""
              continue
          fi
          if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then
              INST="ASM instance"
              ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
              if [ -x $ORACLE_HOME/bin/srvctl ] ; then
                  COUNT=0
                  NODE=`olsnodes -l`
                  RNODE=`srvctl status asm -n $NODE | grep "$ORACLE_SID is running"`
                  RC=$?
                  while [ "$RC" != "0" ]; # wait until this comes up!
                  do
                      COUNT=$((COUNT+1))
                      if [ $COUNT = 5 ] ; then
                          # 5 tries with 60 sec interval => 5 minutes timeout
                          $LOGMSG "Error: Timed out waiting on CRS to start ASM instance $ORACLE_SID"               
                          exit $COUNT
                      fi
                      $LOGMSG "Waiting for Oracle CRS service to start ASM instance $ORACLE_SID"
                      $LOGMSG "Wait $COUNT."
                      sleep 60
                      RNODE=`srvctl status asm -n $NODE | grep "$ORACLE_SID is running"`
                      RC=$?
                  done
              else
                  $LOGMSG "Error: "${W_ORACLE_SID}" has dependency on ASM instance "${ORACLE_SID}""
                  $LOGMSG "Error: Need $ORACLE_HOME/bin/srvctl to check this dependency"
              fi
          fi        # asm instance
          ;;
      esac
      done # innner while
  fi
  ;;
esac
done # outer while

# by now all the ASM instances have come up and we can proceed to bring up
# DB instance with 'W' wait status

cat $ORATAB | while read LINE
do
case $LINE in
  #*)                              ;;              #comment-line in oratab
  *)
  ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
  if [ "$ORACLE_SID" = '*' ] ; then
      # same as NULL SID - ignore this entry
      ORACLE_SID=""
      continue
  fi
  # Proceed only if last field is 'W'.
  if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "W" ] ; then
      INST="Database instance"
      if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then
          $LOGMSG "Error: ${INST} "${ORACLE_SID}" NOT started"
          $LOGMSG "Error: incorrect usage: 'W' not allowed for ASM instances"
          continue
      fi
      ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
      # Called scripts use same home directory
      export ORACLE_HOME
      # file for logging script's output
      LOG=$ORACLE_HOME/startup.log
      touch $LOG
      chmod a+r $LOG
      echo "Processing $INST "$ORACLE_SID": log file $ORACLE_HOME/startup.log"
      startinst >> $LOG 2>&1
  fi
  ;;
esac
done


orashut  orastart
oracle@emsrv:~/bin$ cat orashut
#!/bin/sh

export ORACLE_SID=cdb1
export ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
export PATH=${PATH}:$ORACLE_HOME/bin

sqlplus / as sysdba << EOF
shutdown immediate
exit
EOF
oracle@emsrv:~/bin$ pwd
/home/oracle/bin
oracle@emsrv:~/bin$ cat orashut
#!/bin/sh

export ORACLE_SID=cdb1
export ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
export PATH=${PATH}:$ORACLE_HOME/bin

sqlplus / as sysdba << EOF
shutdown immediate
exit
EOF

这篇关于Start/stopnbsp;Oracleamp;nbs…的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/222686

相关文章

GNSS CTS GNSS Start and Location Flow of Android15

目录 1. 本文概述2.CTS 测试3.Gnss Flow3.1 Gnss Start Flow3.2 Gnss Location Output Flow 1. 本文概述 本来是为了做Android 14 Gnss CTS 的相关环境的搭建和测试,然后在测试中遇到了一些问题,去寻找CTS源码(/cts/tests/tests/location/src/android/locat

Oracle Start With关键字

Oracle Start With关键字 前言 旨在记录一些Oracle使用中遇到的各种各样的问题. 同时希望能帮到和我遇到同样问题的人. Start With (树查询) 问题描述: 在数据库中, 有一种比较常见得 设计模式, 层级结构 设计模式, 具体到 Oracle table中, 字段特点如下: ID, DSC, PID; 三个字段, 分别表示 当前标识的 ID(主键), DSC 当

笔记整理—内核!启动!—kernel部分(2)从汇编阶段到start_kernel

kernel起始与ENTRY(stext),和uboot一样,都是从汇编阶段开始的,因为对于kernel而言,还没进行栈的维护,所以无法使用c语言。_HEAD定义了后面代码属于段名为.head .text的段。         内核起始部分代码被解压代码调用,前面关于uboot的文章中有提到过(eg:zImage)。uboot启动是无条件的,只要代码的位置对,上电就工作,kern

Oracle start with connect BY 死循环

解决办法 检查start with前有没有where条件, 如果有的话,套一层select,再 Oracle start with connect BY

MemSQL Start[c]UP 2.0 - Round 1A(构造)

题目链接:http://codeforces.com/problemset/problem/452/A 解题思路: 打个表暴力查找匹配。 完整代码: #include <algorithm>#include <iostream>#include <cstring>#include <complex>#include <cstdio>#include <strin

QT教程:start()和startTimer()的区别

start() - QTimer 类的成员函数         start() 是 QTimer 类的成员函数,用于启动一个基于 QTimer 对象的定时器。QTimer 是 Qt 中常用的定时器类,它会在设定的时间间隔后发出 timeout() 信号。 用法 QTimer timer;timer.start(1000); // 每隔 1000 毫秒触发一次 timeout() 信号

【Android studio】 unable to start the daemon process

这几天在做一个安卓桌面项目时,突然发现android studio 不能用了。 提示: 网上的一些方法,要不就是: 1、删除C:\Users\<username>\.gradle 文件夹 2、File Menu - > Invalidate Caches/ Restart->Invalidate and Restart 3、C:\Users\<us

springBoot重写start run方法

Spring Boot允许开发者自定义应用程序启动过程,如果想要重写start方法,通常是在实现了CommandLineRunner, ApplicationRunner, 或者ApplicationListener<ContextRefreshedEvent>接口的类中。这些接口的目的是在Spring应用上下文初始化完成后执行一些定制的操作。 例如,如果你创建了一个类并实现了Applicati

出现 WebServerException: Unable to start embedded Tomcat 解决方法(全)

目录 1. 问题所示2. 原理分析3. 解决方法4. 彩蛋总结4.1 方式一4.2 方式二4.3 方式三4.4 方式四 1. 问题所示 原本今天早上可以执行,但是突然下午执行springboot项目的时候出现如下问题 Caused by: org.springframework.boot.web.server.WebServerException: Unable to sta

雅特力AT-START-F423开发板

文章目录 1、开箱2、硬件设计3、点灯初试4、gpio输入和中断5、定时器基本定时6、定时器输出PWM7、串口使用8、ADC和DAC测试9、IIC驱动OLED测试10、SPI驱动测试11、总结 1、开箱 最近官方给寄了板子,顺便测评一下吧,首先是开箱环节 板子是调试器+开发板的布局,接口上用了typec接口好评 默认的是个流水灯的效果,来看个图 现在来了解下这个板子,资料