kill -9 a postgres process
在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的更多相关文章
- kill tomcat process in window
1.通过命令netstat -ano | findstr 8080找到tomcat所占用的process,如下图 2.执行ntsd -c q -p 7944 kill刚刚找到的process,然后 ...
- mysql kill process解决死锁
mysql使用myisam的时候锁表比较多,尤其有慢查询的时候,造成死锁.这时需要手动kill掉locked的process.使他释放. (以前我都是重起服务)..惭愧啊.. 演示:(id 7是我用p ...
- Process Node.js 进程
Process 进程 process.argv 是命令行参数数组,第一个元素是node,第二个元素是脚本文件名,从第三个元素开始每个元素是一个运行参数. process.stdout 标准输出流 co ...
- 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 (文 ...
- System.Diagnostics.Process 测试案例
1.System.Diagnostics.Process 执行exe文件 创建项目,编译成功后,然后把要运行的exe文件拷贝到该项目的运行工作目录下即可,代码如下: using System; usi ...
- kill、killall、pkill杀手三人组
1.1 kill.killall.pkill杀手三人组 1.利用kill 进程号 方式杀掉rsync进程 [root@backup ~]# ps -ef |grep rsync root 3500 1 ...
- 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 ...
- Linux kill/pkill/killall命令详解
kill kill(terminate a process)命令用来终止指定的进程, 对于一个后台进程就须用kill命令来终止,我们就需要先使用ps/pidof/pstree/top等工具获取进程PI ...
- jenkins Process leaked file descriptors
https://stackoverflow.com/questions/17024441/process-leaked-file-descriptors-error-on-jenkins 1. BUI ...
随机推荐
- 算法工程师进化-NLP之主题模型
1 引言 主题模型是文本挖掘的重要工具,近年来在学术界和工业届都获得了非常多的关注.学术界的工作主要集中在建模层面,即提出各种各样的主题模型来适应不同的场景,因此缺乏指导主题模型在工业场景落地的资源和 ...
- Javascript 初学笔记
变量作用域 自 ES2015 起,JS 引入let 和 const 关键词定义变量的块作用域(Block Scope). var 仅支持全局作用域(Global Scope)和函数作用域(Functi ...
- NO.1:自学python之路------Hello world、判断、循环
引言 人工智能如今越来越贴近生活,在这里将记录我自学python与tensorflow的过程.编程使用IDE:visual studio 2017,python版本3.6.4,tensorflow版本 ...
- PRML学习笔记第一章
[转] PRML笔记 - 1.1介绍 模式识别的目标 自动从数据中发现潜在规律,以利用这些规律做后续操作,如数据分类等. 模型选择和参数调节 类似的一族规律通常可以以一种模型的形式为表达,选择合适模型 ...
- 算法笔记(c++)--回文
算法笔记(c++)--回文 #include<iostream> #include<algorithm> #include<vector> using namesp ...
- 亚马逊:PS4和Xbox One实在太火
圣诞节刚刚结束,当实体零售商在抱怨坑爹的天气让自己节日生意变得冷清的同时,在线零售商们却依旧赚的盆满钵满. 亚马逊近日表示,今年节日期间的零售工作非常不错,新一代游戏机更是最大的亮点.据销售统计,在圣 ...
- 获取文件夹下某个类型的文件名---基于python
方法1:import osclass flist_name(): def __init__(self,path): self.flist_name=os.listdir(path) def pcap_ ...
- 《JavaScript》JS中的常用方法attr(),splice()
1.jquery中用attr()方法来获取和设置元素属性,attr是attribute(属性)的缩写,在jQuery DOM操作中会经常用到attr(),attr()有4个表达式. attr(属性名) ...
- C语言的问卷调查
1.你对自己的未来有什么规划?做了哪些准备? 未来想当一个网络工程师,为了这个目标我正在努力学习网络.网页及相关的知识. 2.你认为什么是学习?学习有什么用?现在学习动力如何?为什么? 学习就是不断尝 ...
- Visual C++ 8.0对象布局
哈哈,从M$ Visual C++ Team的Andy Rich那里又偷学到一招:VC8的隐含编译项/d1reportSingleClassLayout和/d1reportAllClassLayout ...