溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

不停機(jī)處理oracle超過最大processes數(shù)故障

發(fā)布時(shí)間:2020-05-28 14:27:11 來源:網(wǎng)絡(luò) 閱讀:990 作者:swswfas 欄目:關(guān)系型數(shù)據(jù)庫(kù)

   在做oracle數(shù)據(jù)庫(kù)管理的時(shí)候,經(jīng)常會(huì)有用戶遇到超過最大進(jìn)程數(shù)的錯(cuò)誤,表現(xiàn)為新的連接無法登入數(shù)據(jù)庫(kù)。一致提示超過最大的process數(shù) 。其實(shí)這個(gè)問題,如果用戶是測(cè)試環(huán)境,好解決。直接關(guān)閉數(shù)據(jù)庫(kù)或者直接kill掉所有的“LOCAL=NO”的進(jìn)程。

   但是很多情況是,用戶無法接受停機(jī),或者kill掉所有的遠(yuǎn)端連接?;谝陨锨闆r,寫了如下腳本

#!/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";

    腳本的基本功能就是,可以數(shù)據(jù)要過濾的進(jìn)程例如"LOCAL=NO“,然后獲得所有匹配進(jìn)程的開始時(shí)間和進(jìn)程內(nèi)容。然后,需要數(shù)據(jù)要kill的進(jìn)程是在當(dāng)前時(shí)間點(diǎn)之前多少秒開始的進(jìn)程。如果輸入null的話。就是kill掉所有匹配的進(jìn)程。如果輸入1000的話,就是kill掉所有在過去1000秒鐘開始的標(biāo)記為”LOCAL=NO“的所有的進(jìn)程。

    執(zhí)行完過程之后,就應(yīng)該可以連接到數(shù)據(jù)庫(kù)中。調(diào)整process參數(shù)。保證系統(tǒng)正常運(yùn)行,然后再查詢導(dǎo)致此錯(cuò)誤的原因。

    這樣的話,我們就可以盡可能的減少對(duì)系統(tǒng)的影響。

當(dāng)前腳本知識(shí)在linux上測(cè)試過,沒有在其他類unix系統(tǒng)測(cè)試。


 

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI