不停机处理oracle超过最大processes数故障
admin
2023-05-15 07:22:13
0次

   在做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=;
  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=;
chomp($arg2);
if($arg2 eq "")
{
   print "Are you sure,to kill all the process above:[y/n]";
   $confirm=;
   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=;
    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=;
    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系统测试。


 

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...