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 ...
随机推荐
- 完美的【去重留一】SQL
DELETE consum_record FROM consum_record, ( SELECT min(id) id, user_id, monetary, consume_time FROM c ...
- JAVA学习笔记--正则表达式
正则表达式是一种强大而灵活的文本处理工具.使用正则表达式,可以让我们以编程的方式构造复杂的文本,并对输入的字符串进行搜索. 一.基础正则表达式语法(表格来自J2SE6_API) 字符 x 字符 x \ ...
- mtv网站架构模式适合企业网站应用吗?
mtv网站架构模式适合企业网站应用吗?有时候在思考这样一个问题. 从开发角度来说,本来mvc的进度慢了些,如果在数据库管理方面用sql的话,管理起来也不很方便.小企业网本来数据就不很多,也没什么太多安 ...
- 基于Docker Compose构建的MySQL MHA集群
Docker MySQL MHA 基于Docker 1.13.1之上构建的MySQL MHA Docker Compose Project 可快速启动GTID模式下的MasterHA集群, 主用于My ...
- HTML页面模板代码
作者声明:本博客中所写的文章,都是博主自学过程的笔记,参考了很多的学习资料,学习资料和笔记会注明出处,所有的内容都以交流学习为主.有不正确的地方,欢迎批评指正 HTML页面模板代码 常用的页面模板 & ...
- Scrum立会报告+燃尽图(十一月二十六日总第三十四次):上传β阶段展示视频
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2413 项目地址:https://git.coding.net/zhang ...
- Alpha阶段中间产物——GUI Prototype、WBS及PSP
作业地址:https://edu.cnblogs.com/campus/nenu/SWE2017FALL/homework/1224 内容: GUI Prototype 我的书架 我的书架→添加图书 ...
- 倒计时60s 代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Matlab中TCP通讯-实现外部程序提供优化目标函数解
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Matlab中TCP通讯-实现外部程序提供优化目标函数解 本文地址:http://te ...
- mac下面安装Navicat Premium 12.0.24 for mac已破解中文亲测可用
链接:https://pan.baidu.com/s/17HQ7dsCun2cSJGRpdP9yXA 密码:hwq5 Navicat_Premium_mac 最新版 12.0.24(原版是英文的) ...