在postgresql中,不推荐使用Kill -9直接杀掉异常连接,因为直接使用kill -9会引起整个数据库核心进程的重启,同时其他正常程序连接也会被杀掉。

  现开启两个psql连接,然后使用Kill -9杀掉其中一个:

session1: 

swrd=# select pg_backend_pid();
pg_backend_pid
----------------
26965
(1 row) swrd=# select pg_backend_pid();
WARNING: terminating connection because of crash of another server process
DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit,
because another server process exited abnormally and possibly corrupted shared memory.
HINT: In a moment you should be able to reconnect to the database and repeat your command.
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.
swrd=# select pg_backend_pid();
pg_backend_pid
----------------
833
(1 row)
session2:

postgres=# select pg_backend_pid();
pg_backend_pid
----------------
25975
(1 row) postgres=# select pg_backend_pid();
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.
postgres=# select pg_backend_pid();
pg_backend_pid
----------------
835
(1 row)

观察上面的日志信息,可以看到session2是被杀掉的会话,但同时session1也被杀掉了。

下面是有关postgre的进程信息,发现除了守护进程和logger进程外,其他进程都重启了。

[root@db~]# ps auxwwf |grep postgres
root 0.0 0.0 pts/ S : : | \_ su - postgres
postgres 0.0 0.0 pts/ S : : | \_ -bash
postgres 0.0 0.0 pts/ S+ : : | \_ psql
root 0.0 0.0 pts/ S : : | \_ su - postgres
postgres 0.0 0.0 pts/ S : : | \_ -bash
postgres 0.0 0.0 pts/ S+ : : | \_ psql
root 0.0 0.0 pts/ S+ : : \_ grep postgres
postgres 0.0 0.0 ? S : /opt/pg96/bin/postgres
postgres 0.0 0.0 ? Ss : \_ postgres: logger process
postgres 0.0 0.0 ? Ss : : \_ postgres: checkpointer process
postgres 0.0 0.0 ? Ss : : \_ postgres: writer process
postgres 0.0 0.0 ? Ss : : \_ postgres: wal writer process
postgres 0.0 0.0 ? Ss : : \_ postgres: autovacuum launcher process
postgres 0.0 0.0 ? Ss : : \_ postgres: archiver process
postgres 0.0 0.0 ? Ss : : \_ postgres: stats collector process
postgres 0.0 0.0 ? Ss : : \_ postgres: postgres postgres [local] idle
postgres 0.0 0.0 ? Ss : : \_ postgres: swrd swrd [local] idle
[root@db~]# kill -
[root@db~]# ps auxwwf |grep postgres
root 0.0 0.0 pts/ S : : | \_ su - postgres
postgres 0.0 0.0 pts/ S : : | \_ -bash
postgres 0.0 0.0 pts/ S+ : : | \_ psql
root 0.0 0.0 pts/ S : : | \_ su - postgres
postgres 0.0 0.0 pts/ S : : | \_ -bash
postgres 0.0 0.0 pts/ S+ : : | \_ psql
root 0.0 0.0 pts/ S+ : : \_ grep postgres
postgres 0.0 0.0 ? S : /opt/pg96/bin/postgres
postgres 0.0 0.0 ? Ss : \_ postgres: logger process
postgres 0.0 0.0 ? Ss : : \_ postgres: checkpointer process
postgres 0.0 0.0 ? Ss : : \_ postgres: writer process
postgres 0.0 0.0 ? Ss : : \_ postgres: wal writer process
postgres 0.0 0.0 ? Ss : : \_ postgres: autovacuum launcher process
postgres 0.0 0.0 ? Ss : : \_ postgres: archiver process
postgres 0.0 0.0 ? Ss : : \_ postgres: stats collector process

  postgres之所以这么做是因为使用kill -9杀掉的进程,是没有机会做好清理工作的,因为kill -9是SIGKILL信号,程序不属于正常退出,杀掉的进程可能由于正在进行写入或修改的操作,从而造成内存页的损坏,为了保证数据库的正常故会重启内部进程。

  如果不使用kill -9,而使用普通的kill操作是不会引起postgres内部进程的重启的。对于中断操作或杀掉会话,建议使用pg自带的pg_cancel_backend()和pg_terminate_backend()。

参考:

https://serverfault.com/questions/415188/kill-9-a-postgres-process

kill -9 a postgres process的更多相关文章

  1. kill tomcat process in window

    1.通过命令netstat -ano | findstr 8080找到tomcat所占用的process,如下图   2.执行ntsd -c q -p 7944 kill刚刚找到的process,然后 ...

  2. mysql kill process解决死锁

    mysql使用myisam的时候锁表比较多,尤其有慢查询的时候,造成死锁.这时需要手动kill掉locked的process.使他释放. (以前我都是重起服务)..惭愧啊.. 演示:(id 7是我用p ...

  3. Process Node.js 进程

    Process 进程 process.argv 是命令行参数数组,第一个元素是node,第二个元素是脚本文件名,从第三个元素开始每个元素是一个运行参数. process.stdout 标准输出流 co ...

  4. A discussion of Dead Connection Detection, Resource Limits, V$SESSION, V$PROCESS and OS processes

    A discussion of Dead Connection Detection, Resource Limits, V$SESSION, V$PROCESS and OS processes (文 ...

  5. System.Diagnostics.Process 测试案例

    1.System.Diagnostics.Process 执行exe文件 创建项目,编译成功后,然后把要运行的exe文件拷贝到该项目的运行工作目录下即可,代码如下: using System; usi ...

  6. kill、killall、pkill杀手三人组

    1.1 kill.killall.pkill杀手三人组 1.利用kill 进程号 方式杀掉rsync进程 [root@backup ~]# ps -ef |grep rsync root 3500 1 ...

  7. check process id exists

    kill -0 pid sending the signal 0 to a given PID just checks if any process with the given PID is run ...

  8. Linux kill/pkill/killall命令详解

    kill kill(terminate a process)命令用来终止指定的进程, 对于一个后台进程就须用kill命令来终止,我们就需要先使用ps/pidof/pstree/top等工具获取进程PI ...

  9. jenkins Process leaked file descriptors

    https://stackoverflow.com/questions/17024441/process-leaked-file-descriptors-error-on-jenkins 1. BUI ...

随机推荐

  1. 爬虫2.5-scrapy框架-下载中间件

    目录 scrapy框架-下载中间件 scrapy框架-下载中间件 middlewares.py中有两个类,一个是xxSpiderMiddleware类 一个是xxDownloaderMiddlewar ...

  2. Action Required: Listings Deactivated for Potential Pricing Error

    Dear Seller, We are contacting you because we have detected potential pricing errors in your Amazon. ...

  3. how to update product listing price sale price and sale date using mobile App

    Greetings from Amazon Seller Support, Thank you for writing back to us. I have reviewed our previous ...

  4. linux 性能分析命令及其解释

    很多时候,我们需要对linux上运行的环境大体有一个了解,那么久需要大体知道当前系统的相关资源的使用情况,那么可以用一些linux提供的丰富的命令来查看 性能分析 vmstat 虚拟内存统计 用法 U ...

  5. Scrum立会报告+燃尽图(十一月二十五日总第三十三次):展示博客

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2413 项目地址:https://git.coding.net/zhang ...

  6. 咱们的team1序章

    之前都参加了好多组织,这是第一次参加变成组织.首先要介绍团队名称了,为什么叫“咱们的team”呢,因为,我们需要每个人都认真的参与进来,只有每个人都十分投入地参与进来,这个team才能称之为一个tea ...

  7. our team

    今天向大家介绍一下我们的团队,首先我们的团队叫“吉祥三宝”当然我们的三宝不是亲子关系,我们是兄弟关系,对,就是这样 下面来介绍一下我们的团队成团吧: 李奇原: 性格开朗.积极乐观.有责任心,擅长团队协 ...

  8. Python:字典操作总结

     字典是Python中唯一的映射类型 [注]:字典中数据是无序排放的 一.字典的创建方法 方法1:用大括号包裹键值对从而创建字典 addict={}#创建一个空字典 addict={key1:valu ...

  9. lintcode-402-连续子数组求和

    [402-连续子数组求和(http://www.lintcode.com/zh-cn/problem/continuous-subarray-sum/) 给定一个整数数组,请找出一个连续子数组,使得该 ...

  10. jQuery之数组处理函数

    摘要:$.each,$.grep,$.map,$.merge,$.inArray,$.unique,$.makeArray 1. $.each(array, [callback]) 遍历[常用] 解释 ...