zoukankan      html  css  js  c++  java
  • 【Kill】两条Linux命令彻底杀死Oracle

    今天编写的两条极具杀伤力的命令,它可以瞬间将Oracle杀死在无形之中。后面我将给出简单注释并展示一下它的威力。
    $ ps -ef |grep $ORACLE_SID|grep -v grep|awk '{print $2}' | xargs kill -9
    $ ipcs -m | grep oracle | awk '{print $2}' | xargs ipcrm shm

    这两条命令的来由:
    今天处理了三起Oracle数据库无故无法登录的问题,无论你采取什么手段都无法登陆到Oracle的SQL*PLus中,更谈不上故障排查了。
    这种情况下有两种选择,第一种选择是经过一个较长的时间来排查故障原因,另外一种方法是不惜一切代价启动数据库以便尽快恢复生产。

    如果是测试实验环境可以使用第一种方法来完成,对于排查问题的经验积累是有意的。
    如果是生产环境,减少停机时间是最最至上的原则,所以我们只有不惜一切代价让数据库尽快恢复使用。

    对于尽快恢复生产的方法主要也有两种。
    第一种不惜代价的方法是重启服务器主机,彻底释放一切资源,重新来过,这种方法是有效的,不过停机时间还是有点长,而且技术含量比较低,所以不是很推荐使用这种超级“简单粗暴”的方法。
    第二种方法就是我将要给大家展示的方法。

    1.第一步:使用Linux的kill命令杀死所有与oracle有关的进程。
    1)查询到与ORACLE_SID相关的oracle进程
    $ ps -ef |grep $ORACLE_SID
    oracle    7776     1  0 22:51 ?        00:00:00 ora_pmon_ora10g
    oracle    7778     1  0 22:51 ?        00:00:00 ora_psp0_ora10g
    oracle    7780     1  0 22:51 ?        00:00:00 ora_mman_ora10g
    oracle    7782     1  0 22:51 ?        00:00:00 ora_dbw0_ora10g
    oracle    7784     1  0 22:51 ?        00:00:00 ora_dbw1_ora10g
    oracle    7786     1  0 22:51 ?        00:00:00 ora_lgwr_ora10g
    oracle    7788     1  0 22:51 ?        00:00:00 ora_ckpt_ora10g
    oracle    7790     1  0 22:51 ?        00:00:00 ora_smon_ora10g
    oracle    7792     1  0 22:51 ?        00:00:00 ora_reco_ora10g
    oracle    7794     1  0 22:51 ?        00:00:00 ora_cjq0_ora10g
    oracle    7796     1  0 22:51 ?        00:00:00 ora_mmon_ora10g
    oracle    7798     1  0 22:51 ?        00:00:00 ora_mmnl_ora10g
    oracle    7832     1  0 22:51 ?        00:00:00 ora_arc0_ora10g
    oracle    7834     1  0 22:51 ?        00:00:00 ora_arc1_ora10g
    oracle    7836     1  0 22:51 ?        00:00:00 ora_qmnc_ora10g
    oracle    7842     1  0 22:51 ?        00:00:00 ora_q000_ora10g
    oracle    7847     1  0 22:52 ?        00:00:00 ora_q001_ora10g
    oracle    7951  7592  0 23:11 pts/2    00:00:00 grep ora10g

    2)去除掉包含grep命令本身的记录
    $ ps -ef |grep $ORACLE_SID |grep -v grep
    oracle    7776     1  0 22:51 ?        00:00:00 ora_pmon_ora10g
    oracle    7778     1  0 22:51 ?        00:00:00 ora_psp0_ora10g
    oracle    7780     1  0 22:51 ?        00:00:00 ora_mman_ora10g
    oracle    7782     1  0 22:51 ?        00:00:00 ora_dbw0_ora10g
    oracle    7784     1  0 22:51 ?        00:00:00 ora_dbw1_ora10g
    oracle    7786     1  0 22:51 ?        00:00:00 ora_lgwr_ora10g
    oracle    7788     1  0 22:51 ?        00:00:00 ora_ckpt_ora10g
    oracle    7790     1  0 22:51 ?        00:00:00 ora_smon_ora10g
    oracle    7792     1  0 22:51 ?        00:00:00 ora_reco_ora10g
    oracle    7794     1  0 22:51 ?        00:00:00 ora_cjq0_ora10g
    oracle    7796     1  0 22:51 ?        00:00:00 ora_mmon_ora10g
    oracle    7798     1  0 22:51 ?        00:00:00 ora_mmnl_ora10g
    oracle    7832     1  0 22:51 ?        00:00:00 ora_arc0_ora10g
    oracle    7834     1  0 22:51 ?        00:00:00 ora_arc1_ora10g
    oracle    7836     1  0 22:51 ?        00:00:00 ora_qmnc_ora10g
    oracle    7842     1  0 22:51 ?        00:00:00 ora_q000_ora10g
    oracle    7847     1  0 22:52 ?        00:00:00 ora_q001_ora10g

    3)使用awk命令得到我们关心的进程号
    $ ps -ef |grep $ORACLE_SID |grep -v grep|awk '{print $2}'
    7776
    7778
    7780
    7782
    7784
    7786
    7788
    7790
    7792
    7794
    7796
    7798
    7832
    7834
    7836
    7842
    7847

    4)万事俱备,我们最后使用kill命令将oracle的进程杀死,因此得到了下面完整的命令
    $ ps -ef |grep $ORACLE_SID |grep -v grep|awk '{print $2}' | xargs kill -9

    2.第二步:使用Linux的ipcs和ipcsrm命令释放oracle占用的共享内存。
    1)使用ipcs命令查看系统中共享内存使用情况
    $ ipcs -m

    ------ Shared Memory Segments --------
    key        shmid      owner      perms      bytes      nattch     status
    0x00000000 32768      root      644        72         2          dest
    0x00000000 65537      root      644        16384      2          dest
    0x00000000 98306      root      644        280        2          dest
    0x00000000 131075     root      644        790528     2          dest
    0x00000000 163844     root      644        790528     2          dest
    0x00000000 196613     root      644        790528     2          dest
    0x00000000 327689     oracle    644        790528     2          dest
    0x00000000 360458     oracle    644        790528     2          dest
    0x00000000 393227     oracle    644        790528     2          dest
    0xecc5fba0 786447     oracle    640        5370806272 30

    2)使用grep命令过滤后得到与oracle相关的内容
    $ ipcs -m | grep oracle
    0x00000000 327689     oracle    644        790528     2          dest
    0x00000000 360458     oracle    644        790528     2          dest
    0x00000000 393227     oracle    644        790528     2          dest
    0xecc5fba0 786447     oracle    640        5370806272 31

    2)使用awk命令获得上面我们关心的shmid字段内容
    $ $ ipcs -m | grep oracle | awk '{print $2}'
    327689
    360458
    393227
    786447

    3)最后使用ipcsrm命令释放共享内存
    $ ipcs -m | grep oracle | awk '{print $2}' | xargs ipcrm shm
    resource(s) deleted

    再次查看一下,此时共享内存已经被释放。
    $ ipcs -m | grep oracle
    0x00000000 327689     oracle    644        790528     2          dest
    0x00000000 360458     oracle    644        790528     2          dest
    0x00000000 393227     oracle    644        790528     2          dest
    0x00000000 786447     oracle    640        5370806272 31         dest

    3.此时,我们便可以登录到数据库,最后启动数据库恢复生产。

    4.小结
    这种方法相对也是比较“粗暴”的。不过在危难之时还是可以派上用场。
    重点强调:
    手工杀掉oracle进程和手工释放共享内存是非常危险的,不到万不得已,千万不要使用;
    这里我给出的两条极具杀伤力的命令,请不要轻易尝试。

  • 相关阅读:
    Lua中的loadfile、dofile、require详解
    100GB以上超大文件上传和断点续传服务器的实现
    50GB以上超大文件上传和断点续传服务器的实现
    20GB以上超大文件上传和断点续传服务器的实现
    10GB以上超大文件上传和断点续传服务器的实现
    Flash 以上超大文件上传和断点续传服务器的实现
    WebUploader 以上超大文件上传和断点续传服务器的实现
    HTML5 以上超大文件上传和断点续传服务器的实现
    VUE 以上超大文件上传和断点续传服务器的实现
    B/S 以上超大文件上传和断点续传服务器的实现
  • 原文地址:https://www.cnblogs.com/lcword/p/5771187.html
Copyright © 2011-2022 走看看