关闭

pg_cancel_backend() 与pg_terminate_backend()

889人阅读 评论(2) 收藏 举报
先看下两个函数的官方解释:
pg_cancel_backend() 与pg_terminate_backend() - dazuiba_008 - 魂醉的一亩二分地
 
pg_cancel_backend() 与pg_terminate_backend() - dazuiba_008 - 魂醉的一亩二分地
 
pg_cancel_backend() 取消后台操作,回滚未提交事物
pg_terminate_backend() 中断session,回滚未提交事物
这里和oracle类似kill session的操作是pg_terminate_backend()
 
pg_cancel_backend()   举例:

session A:

postgres=# create table tb1 (a int); CREATE TABLE postgres=# begin;

postgres=# insert into tb1 select generate_series(1,100000000);

session B

postgres=# select * from pg_stat_activity; datid | datname | procpid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | xact_start | query_start | waiting | current_query -------+----------+---------+----------+----------+------------------+-------------+-----------------+-------------+-------------------------------+-------------------- -----------+-------------------------------+---------+------------------------------------------------------ 12699 | postgres | 10305 | 10 | postgres | psql | | | -1 | 2013-12-03 14:38:05.887116+08 | 2013-12-03 15:12:17 .773935+08 | 2013-12-03 15:14:31.454816+08 | f | insert into tb1 select generate_series(1,100000000);

postgres=# select pg_cancel_backend(10305); pg_cancel_backend ------------------- t

session A ERROR: canceling statement due to user request postgres=# commit; ROLLBACK postgres=# select * from tb1; a --- (0 rows)

session B:

postgres=# select * from pg_stat_activity; datid | datname | procpid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | xact_start | query_start | waiting | current_query -------+----------+---------+----------+----------+------------------+-------------+-----------------+-------------+-------------------------------+-------------------- -----------+-------------------------------+---------+--------------------------------- 12699 | postgres | 10305 | 10 | postgres | psql | | | -1 | 2013-12-03 14:38:05.887116+08 |

pg_terminate_backend() 举例:

session A

postgres=# create table tb2 (a int); CREATE TABLE postgres=# begin; BEGIN postgres=# insert into tb2 select generate_series(1,100000000);

session B

postgres=# select * from pg_stat_activity; datid | datname | procpid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | xact_start | query_start | waiting | current_query -------+----------+---------+----------+----------+------------------+-------------+-----------------+-------------+-------------------------------+-------------------- -----------+-------------------------------+---------+------------------------------------------------------ 12699 | postgres | 10305 | 10 | postgres | psql | | | -1 | 2013-12-03 14:38:05.887116+08 | 2013-12-03 15:24:22 .45073+08 | 2013-12-03 15:24:33.362185+08 | f | insert into tb2 select generate_series(1,100000000);

postgres=# select pg_terminate_backend(10305); pg_terminate_backend ---------------------- t (1 row)

session A

postgres=# insert into tb2 select generate_series(1,100000000); FATAL: terminating connection due to administrator command FATAL: terminating connection due to administrator command The connection to the server was lost. Attempting reset: Succeeded. postgres=# commit; WARNING: there is no transaction in progress COMMIT postgres=# select * from tb2; a --- (0 rows)

postgres=# select * from pg_stat_activity;

datid | datname | procpid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | xact_start | query_start | waiting | current_query -------+----------+---------+----------+----------+------------------+-------------+-----------------+-------------+-------------------------------+-------------------- -----------+-------------------------------+---------+--------------------------------- 12699 | postgres | 10918 | 10 | postgres | psql | | | -1 | 2013-12-03 15:25:12.613672+08 | 2013-12-03 15:30:29 .544088+08 | 2013-12-03 15:30:29.544088+08 | f | select * from pg_stat_activity;

通过以上实验理解起来应该 很简单了,procpid=10305在pg_cancel_backend()下,session还在,事物回退,在pg_terminate_backend()操作后,session消失,事物回退。如果在某些时候pg_terminate_backend()不能杀死session,那么可以在os层面,直接kill -9  pid
1
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

QT与openCV,与PCL结合!

浏览一下例子即可!^-^ (2):详解QT 快速应用OPENCV ,图片示例 原文链接:http://mobile.51cto.com/symbian-271260.htm
  • wishchin
  • wishchin
  • 2013-10-20 13:41
  • 2662

位运算之 C 与或非异或

位运算比较易混: 位运算之 C 与或非异或   与运算:& 两者都为1为1,否则为0 1&1=1,  1&0=0,  0&1=0,  0&0=0 或运算:| 两...
  • lxw907304340
  • lxw907304340
  • 2015-03-15 23:06
  • 4586

C++中int与char*、int与Byte、double与char*的相互装换

在我做课题的时候发现,在C#中int与char*、int与Byte、double与char*的相互装换,都可以采用系统封装好的函数。 但是,不是我想要的结果,和自己调用,不是很适合我自己,于是自己用C...
  • langxm2006
  • langxm2006
  • 2015-09-09 09:12
  • 1214

在LLVM中编写Backend Pass的详细教程(1)

LLVM是一个自由软件项目,它是一种编译器基础设施,以C++写成。当前,LLVM已经发展成为被用于开发从编译器前端到后端的一套模块及可重用的编译器及工具链技术的集合。本文将通过一个具体的例子来介绍如何...
  • baimafujinji
  • baimafujinji
  • 2017-12-31 16:35
  • 83

keras的backend 设置 tensorflow,theano

win7 系统环境安装步骤: 1.首先是安装Python,建议安装anaconda 2.安装完anaconda后打开anaconda promp命令行promp,输入conda list. 可以看到...
  • huixingshao
  • huixingshao
  • 2017-05-04 10:35
  • 1145

Post Json Data by Ajax, and Parse the Json Data in backend

前几天,项目需要在后台接受Posted json data。于是我做了一个简单的json发送页面如下:页面上: JS处理:$.ajaxSetup({ cache: f...
  • miaoxw01131
  • miaoxw01131
  • 2011-07-28 09:39
  • 681

libevent源码分析:backend的选择

libevent提供了7种io后端(eventop)/*io后端*/ struct eventop { /*名字*/ const char *name; /* 使用前通...
  • xtchina
  • xtchina
  • 2016-07-10 17:52
  • 758

Impala源代码分析(3)-backend查询执行过程

4 Replies 这篇文章主要介绍impala-backend是怎么执行一个SQL Query的。 在Impala中SQL Query的入口函数是: void ImpalaServer...
  • novelly
  • novelly
  • 2013-11-26 23:45
  • 544

openstack 管理二十二 - cinder 连接多个存储 backend

利用 openstack cinder 与多个 ceph 后端进行连接 利用 ceph 存储用于 openstack 云盘服务
  • signmem
  • signmem
  • 2017-01-19 18:03
  • 1115

解决在安装openstack swift过程中遇到的"liberasurecode[XX]: liberasurecode_backend_open: dynamic linking error"

解决在安装openstack swift过程中遇到的"liberasurecode[XX]: liberasurecode_backend_open: dynamic linking error"
  • hubinqiang
  • hubinqiang
  • 2017-02-26 17:43
  • 574
    个人资料
    • 访问:114436次
    • 积分:3025
    • 等级:
    • 排名:第13362名
    • 原创:166篇
    • 转载:10篇
    • 译文:0篇
    • 评论:9条
    最新评论