zoukankan      html  css  js  c++  java
  • 启动服务器上的所有oracle数据库

    当服务器上有多台数据库时,如何管理:

    思路通过 找文件"/bin/oracle" 确定oracle实例,列出本台服务器上所有的"/bin/oracle "文件,然后再根据此文件所有者(DB OWNER),通过sqlplus 脚本关闭和开起

    以下是代码

    #!/bin/bash
    #+++++++++++++++++++++++++++++++++++++++++++++
    # stop and start all oracle database in one server
    #
    # Param 1 : optional database owner 
    # Param 2 : -stop |start
    #+++++++++++++++++++++++++++++++++++++++++++++
    #############################################
    #
    #  Start/stop oracle database 
    #
    #############################################
    stop_db()
    {
      echo "   Database $oraid is going to stop"
      tmpfile=/tmp/"${oraid}"_start_db.$$.sql 
      echo "connect / as sysdba"  >  $tmpfile
      echo "                   "  >> $tmpfile
      echo "                  "   >> $tmpfile
      echo "shutdown immediate"   >> $tmpfile
      echo "exit"                 >> $tmpfile   
      chown $oraid:dba ${tmpfile}
      chmod 777 ${tmpfile}
    
      su - $oraid -c "sqlplus -s /NOLOG @$tmpfile" 0</dev/null | grep -v "ORA-01109"
      rm -f $tmpfile
    
      RC=$?;
      if [ $RC -eq 0 ]
        then 
          echo $(date) "DONE : STOP DB $oraid";
        else
          echo "=================================================================";
          echo 
          echo $(date) "WARNING: STOP DB $oraid RC="$RC;
          echo "=================================================================";
          echo 
      fi
    }
    
    #############################################
    #
    #  stop Database
    #
    #############################################
    start_db()
    {
      echo "   Database $oraid is going to start"
      tmpfile=/tmp/"${oraid}"_stop_db.$$.sql 
      echo "connect / as sysdba"  >  $tmpfile
      echo "                   "  >> $tmpfile
      echo "                  "   >> $tmpfile
      echo "startup;          "   >> $tmpfile
      echo "exit"                 >> $tmpfile
      chown $oraid:dba ${tmpfile}
      chmod 777 ${tmpfile}  
      su - $oraid -c "sqlplus -s /NOLOG @$tmpfile" 0</dev/null | grep -v "ORA-01109"
      rm -f $tmpfile
      
      RC=$?;
      if [ $RC -eq 0 ]
        then 
          echo $(date) "DONE : Start DB $oraid";
        else
          echo "=================================================================";
          echo 
          echo $(date) "WARNING: Start DB $oraid RC="$RC;
          echo "=================================================================";
          echo 
      fi
    }
    #############################################
    #
    #  Start Database
    #
    #############################################
    read_instance()
    {
      echo "   Trying to found database";
      instances=$(find / -name oracle|grep -i bin)
      echo "$instances"
      for instance in $instances
        do   
            oraid=`ls -ltr ${instance}|cut -d " " -f 3`
            case $action in
                -start)     start_db        ;;
                -stop)      stop_db            ;;
            esac
       done
    }
    #############################################
    #
    #  Main 
    #
    #############################################
    if [ $# -lt 1 ]
    then
      echo "##########################################################################################"
      echo 
      echo "  Syntax : stop oracle database : dboper <db name> <-start|-stop> " 1>&2
      echo "  Parm1  : optional <listener name> "
      echo "  Parm2  : -start|-stop"
      echo "##########################################################################################"
      exit 8
    fi
    
    if [ $# -eq 2 ]
      then
         oraid=$1
         action=$2
         case $action in
            -start)     start_db ;
            ;;
            -stop)      stop_db ;
            ;;
         esac
      else 
         targetdb=""
         action=$1
         read_instance
    fi
    View Code

    以下是执行效果:start  all db

    [root@wen oraoper]# PATH=$PATH:$PWD
    [root@wen oraoper]# echo $PATH
    /usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/mnt/hgfs/script/orainst:/mnt/hgfs/script/oraoper          
    [root@wen oraoper]# dbstartstop.sh -start
       Trying to found database
    /oracle/g11/111/bin/oracle
    /oracle/g13/113/bin/oracle
    /oracle/g14/114/bin/oracle
    /oracle/g12/112/bin/oracle
       Database g11 is going to start
    ORACLE instance started.
    
    Total System Global Area 3340451840 bytes
    Fixed Size            2217952 bytes
    Variable Size         1811941408 bytes
    Database Buffers     1509949440 bytes
    Redo Buffers           16343040 bytes
    Database mounted.
    Database opened.
    Thu Oct 22 18:51:41 CST 2020 DONE : Start DB g11
       Database g13 is going to start
    ORACLE instance started.
    
    Total System Global Area 1603411968 bytes
    Fixed Size            2213776 bytes
    Variable Size          402655344 bytes
    Database Buffers     1191182336 bytes
    Redo Buffers            7360512 bytes
    Database mounted.
    Database opened.
    Thu Oct 22 18:51:48 CST 2020 DONE : Start DB g13
       Database g14 is going to start
    ORACLE instance started.
    
    Total System Global Area 1603411968 bytes
    Fixed Size            2213776 bytes
    Variable Size          402655344 bytes
    Database Buffers     1191182336 bytes
    Redo Buffers            7360512 bytes
    Database mounted.
    Database opened.
    Thu Oct 22 18:51:55 CST 2020 DONE : Start DB g14
       Database g12 is going to start
    ORACLE instance started.
    
    Total System Global Area 1603411968 bytes
    Fixed Size            2213776 bytes
    Variable Size          402655344 bytes
    Database Buffers     1191182336 bytes
    Redo Buffers            7360512 bytes
    Database mounted.
    Database opened.
    Thu Oct 22 18:52:03 CST 2020 DONE : Start DB g12
    View Code

    关闭指定DB

    [root@wen oraoper]# dbstartstop.sh g14 -stop
       Database g14 is going to stop
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    Thu Oct 22 18:54:23 CST 2020 DONE : STOP DB g14
    View Code
  • 相关阅读:
    2019互联网安全城市巡回赛·西安站圆满收官
    跨域漏洞丨JSONP和CORS跨域资源共享
    浅谈URL跳转与Webview安全
    事务嵌套的问题
    小代码编写神器:LINQPad 使用入门
    重构指导之一
    视频的文件格式、压缩格式、码率、分辨率
    Asp.Net中自以为是的Encode
    Solution Explorer 和 Source Control Explorer 的 View History 异同
    借助 Resharper 和 StyleCop 让代码更整洁
  • 原文地址:https://www.cnblogs.com/tingxin/p/13855511.html
Copyright © 2011-2022 走看看