不停机处理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系统测试。


 

相关内容

热门资讯

联合国安理会审议叙利亚局势,中... 当地时间5月15日,安理会举行叙利亚问题公开会,聚焦该国政治和人道局势。中方代表指出,维护叙利亚形势...
特朗普在中国破例喝酒了?白宫回... 美国总统特朗普日前访华敬酒的画面在社交媒体广泛流传,许多人称,他这是破例了,因为他此前滴酒不沾。白宫...
英国绿党领袖:部长们应该做正确... 据凤凰卫视报道,英国工党首相斯塔默仍然面临严峻的党内逼宫压力。当地媒体指,超过半数工党下院议员希望他...
全民围观某君半蹲合影:我们崇拜... 马斯克打卡点:半蹲的不是膝盖,是整个科技行业的想象力 ——当某君半蹲合影、库克排队等待,科技大佬们的...
深圳第二类医疗器械备案所需材料... 办理深圳第二类医疗器械经营备案,最耗时间的就是材料准备。很多企业因为资料漏项、盖章错误、扫描模糊、填...
直击杭州人形机器人展:文旅物流... 《科创板日报》5月15日讯(记者 王耐)2026年第二届杭州国际人形机器人展,有600家上下游企业参...
“前半生是恶霸,后半生是学霸”... 一个人的逆袭叫传奇。一群人的集体转行,叫世道变了。文|张雪莹出品|Vista天下知识局提到日本黑帮,...
若不想成7年来第五个被赶下台的... 【文/观察者网 张菁娟】“这是自2022年保守党前首相特拉斯上任仅数周便仓促辞职以来,英国政局最动荡...
产学研各界代表齐聚一堂,共议A... 封面新闻记者 易弋力 20支战队4小时巅峰对决;三位大咖三个不同视角解读“技术打法+产业路径+数据洞...
评论丨香蕉复仇、蓝莓出轨?警惕... AI技术降低了创作门槛,不等于降低了质量门槛和责任门槛;可以利用AI“手搓”短剧,但不应没下限地制造...