不停機處理oracle超過最大processes數故障

   在做oracle數據庫管理的時候,經常會有用戶遇到超過最大進程數的錯誤,表現爲新的連接無法登入數據庫。一致提示超過最大的process數 。其實這個問題,如果用戶是測試環境,好解決。直接關閉數據庫或者直接kill掉所有的“LOCAL=NO”的進程。

   但是很多情況是,用戶無法接受停機,或者kill掉所有的遠端連接。基於以上情況,寫了如下腳本

#!/usr/bin/perl
#write by wulei

#get the first parameter
$arg1="";
chomp($arg1);
while($arg1 eq "")
{
  print "please input your first parameter:";
  $arg1=<STDIN>;
  chomp($arg1);
  if($arg1 ne ""){
    @temp1=`ps -eo lstart,pid,args | grep '$arg1' | grep -v grep`;
    $process_count=`ps -eo lstart,pid,args | grep '$arg1' | grep -v grep | wc -l`;
    chomp($process_count);
    if($process_count eq "0")
    { 
      $arg1="";
      print "we got 0 processes,please retry!\n";
      next;
    }
    print "We will kill $process_count(count) processes\n";
    print "All the processes list below!!!!!!!!!!!!!!!!!\n";
    print "#############################################################\n";
    print @temp1;
  }
  chomp($arg1);
}

#get the second parameter
$arg2="";
chomp($arg2);
while($arg2 eq "")
{
print "\n";
print "\n";
print "############################################################\n";
print "#[null] kill all the process we had got                    #\n";
print "#[num ] kill the process start at before sysdate-number    #\n";
print "if you want exit,enter 'ctrl+c'                            #\n";
print "############################################################\n";
print "please input your second parameter:";
$arg2=<STDIN>;
chomp($arg2);
if($arg2 eq "")
{
   print "Are you sure,to kill all the process above:[y/n]";
   $confirm=<STDIN>;
   chomp($confirm);
   if($confirm eq "Y" or $confirm eq "y")
   {
   #kill all the process ,we got it
   @result=`ps -eo pid,args | grep '$arg1' | grep -v grep`;
    print "Kill List !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
    print "###################################################################\n";
     foreach $result (@result)
     {
     @result1=split(/\s+/,$result);
     chomp($result1[0]);
     if($result1[0] ne ""){
       #`kill -9 '$result1[0]'`;
       print $result1[0]." ".$result1[1]." ".$result1[2]."\n";
       push(@kill_Queue,$result1[0]);
       }
     }
    $killQueueLen=@kill_Queue;
    print "###################################################################\n";
    print "We will kill '$killQueueLen' processes!!\n";
    print "Are you sure about kill the processes above?[y/n]";
    $yesorno=<STDIN>;
    chomp($yesorno);
    if($yesorno eq "Y" or $yesorno eq "y")
     {
    print "###################################################################\n";
        foreach $kill_Queue (@kill_Queue)
        {
         print $kill_Queue;
         chomp($kill_Queue);
         if($kill_Queue ne "")
         {
          `kill -9 '$kill_Queue'`;
         }
        }
     }
    elsif($yesorno eq "N" or $yesorno eq "n")
     {
        @kill_Queue=();
        $arg2="";
        next;
     }
    else
     {
     print "###################################################################\n";
     print "JUEST  Y   or   N!!!!\n";
     print "###################################################################\n";
     next;
   }
     print "OK\n";
     exit;
    }
    elsif($confirm eq "N" or $confirm eq "n")
    {
    exit 0;
    }
    else
    {
      print "Please input [y/n]:";
      next;
    }
}
else
{
   if($arg2 =~ /^[+-]?\d+$/)
   {
    @result=`ps -eo lstart,pid,args | grep $arg1 | grep -v grep`;
    my @kill_Queue="";
    print "killed list\n";
    print "###################################################################\n";
    foreach $result ( @result) 
    {
     if($result ne "")
      {
      @result1 =split(/\s+/,$result);
      $time_start=$result1[1]." ".$result1[2]." ".$result1[3]." ".$result1[4];
      $format_time=`date -d '$time_start' '+%Y/%m/%d %T'`;
      chomp($format_time);
      $pro_st_time=`date +%s -d '$format_time'`;
      $a1=`date`;
      chomp($a1);
      chomp($pro_st_time);
      chomp($kill_time);
      $cur_time=`date +%s -d '$a1'`; 
      $kill_time=$cur_time-$arg2;
      if($pro_st_time > $kill_time)
      {
         print $result1[5]." ".$result1[6]." ".$result1[7]."\n";
         push(@kill_Queue,$result1[5]);
      }
    }
    else
    {
    next;
    }
}
    $killQueueLen=@kill_Queue-1;
    print "###################################################################\n";
    print "We will kill '$killQueueLen' processes!!\n";
    print "Are you sure about kill the processes above?[y/n]";
    $yesorno=<STDIN>;
    chomp($yesorno);
    if($yesorno eq "Y" or $yesorno eq "y")
     {
        foreach $kill_Queue (@kill_Queue)
        {
         chomp($kill_Queue);
         if($kill_Queue ne "")
         {
          `kill -9 '$kill_Queue'`;
         }
        }
     }
    elsif($yesorno eq "N" or $yesorno eq "n")
     {
        $arg2="";
        next;
     }

   }
}
print "retry";
}

print "End of the script\n";
print "================================================================\n";

    腳本的基本功能就是,可以數據要過濾的進程例如"LOCAL=NO“,然後獲得所有匹配進程的開始時間和進程內容。然後,需要數據要kill的進程是在當前時間點之前多少秒開始的進程。如果輸入null的話。就是kill掉所有匹配的進程。如果輸入1000的話,就是kill掉所有在過去1000秒鐘開始的標記爲”LOCAL=NO“的所有的進程。

    執行完過程之後,就應該可以連接到數據庫中。調整process參數。保證系統正常運行,然後再查詢導致此錯誤的原因。

    這樣的話,我們就可以儘可能的減少對系統的影響。

當前腳本知識在linux上測試過,沒有在其他類unix系統測試。


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章