非super user管理会话
在gp中取消或者中断某个用户的超长时间或者SQL存在问题的会话。假设无法拥有超级用户将无法运行该类操作。
首先我们创建两个用户t1、t2,而且使用t1登录到数据库。
[gpadmin@wx60 ~]$ psql gtlions
psql (8.2.15)
Type "help" for help. gtlions=# select version();
version
------------------------------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 8.2.15 (Greenplum Database 4.2.7.2 build 1) on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.4.2 compiled on Feb 25 2014 18:05:04
(1 row) gtlions=# \du
List of roles
Role name | Attributes | Member of
-----------+-----------------------------------+-----------
gpadmin | Superuser, Create role, Create DB | gtlions=# \dn
List of schemas
Name | Owner
--------------------+---------
gp_toolkit | gpadmin
information_schema | gpadmin
pg_aoseg | gpadmin
pg_bitmapindex | gpadmin
pg_catalog | gpadmin
pg_toast | gpadmin
public | gpadmin
(7 rows) gtlions=# create user t1 ;
NOTICE: resource queue required -- using default resource queue "pg_default"
CREATE ROLE
gtlions=# create user t2;
NOTICE: resource queue required -- using default resource queue "pg_default"
CREATE ROLE
gtlions=# \c gtlions t1
You are now connected to database "gtlions" as user "t1".
接下来我们使用用户t2登录到数据库。检查当前会话并尝试取消或者中断用户t1的会话。
[gpadmin@wx60 ~]$ psql -U t2 gtlions
psql (8.2.15)
Type "help" for help. gtlions=> select * from pg_stat_activity ;
datid | datname | procpid | sess_id | usesysid | usename | current_query | waiting | query_start | backend_start
| client_addr | client_port | application_name | xact_start
-------+---------+---------+---------+----------+---------+----------------------------------+---------+-------------------------------+-------------------------------
+-------------+-------------+------------------+-------------------------------
16992 | gtlions | 3395 | 13 | 25881 | t2 | select * from pg_stat_activity ; | f | 2014-10-11 09:25:56.197394+08 | 2014-10-11 09:25:43.293684+08
| | -1 | psql | 2014-10-11 09:25:56.197394+08
16992 | gtlions | 3384 | 12 | 25880 | t1 | <insufficient privilege> | | |
| | | psql |
(2 rows) gtlions=> select pg_cancel_backend(3384);
ERROR: must be superuser to signal other server processes
gtlions=>
会发现非超级用户无法运行取消或者中断其它用户的会话操作。
解决的方法是自己定义一个函数,并授权给t2用户运行权限。这样就能够实现上述操作了。
create or replace function session_mgr(procpid integer, opertype character)
returns boolean
as
$BODY$
declare
ret boolean;
begin
if opertype = 'c' then
ret := (select pg_catalog.pg_cancel_backend(procpid));
elsif opertype = 'k' then
ret := (select pg_catalog.pg_terminate_backend(procpid));
end if;
return ret;
end;
$BODY$
LANGUAGE plpgsql security definer; gtlions=# grant execute on function session_mgr(integer, character) to t2;
GRANT
gtlions=# \c gtlions t1
You are now connected to database "gtlions" as user "t1".
gtlions=>
接着使用用户t2进行相关操作。
[gpadmin@wx60 ~]$ psql -U t2 gtlions
psql (8.2.15)
Type "help" for help. gtlions=> select * from pg_stat_activity ;
datid | datname | procpid | sess_id | usesysid | usename | current_query | waiting | query_start | backend_start
| client_addr | client_port | application_name | xact_start
-------+---------+---------+---------+----------+---------+----------------------------------+---------+-------------------------------+-------------------------------
+-------------+-------------+----------------------------+-------------------------------
16992 | gtlions | 4034 | 19 | 25881 | t2 | select * from pg_stat_activity ; | f | 2014-10-11 09:48:53.767859+08 | 2014-10-11 09:48:51.285594+08
| | -1 | psql | 2014-10-11 09:48:53.767859+08
16992 | gtlions | 3678 | 15 | 10 | gpadmin | <insufficient privilege> | | |
| | | pgAdmin III - ????? ? ??? |
16992 | gtlions | 3704 | 16 | 10 | gpadmin | <insufficient privilege> | | |
| | | pgAdmin III - ? ? ?????? ? ? ?? |
16992 | gtlions | 4023 | 18 | 25880 | t1 | <insufficient privilege> | | |
| | | psql |
(4 rows)
gtlions=> select session_mgr(4023,'c');
session_mgr
-------------
t
(1 row) gtlions=> select * from pg_stat_activity ;
datid | datname | procpid | sess_id | usesysid | usename | current_query | waiting | query_start | backend_start
| client_addr | client_port | application_name | xact_start
-------+---------+---------+---------+----------+---------+----------------------------------+---------+-------------------------------+-------------------------------
+-------------+-------------+----------------------------+-------------------------------
16992 | gtlions | 4034 | 19 | 25881 | t2 | select * from pg_stat_activity ; | f | 2014-10-11 09:52:03.279186+08 | 2014-10-11 09:48:51.285594+08
| | -1 | psql | 2014-10-11 09:52:03.279186+08
16992 | gtlions | 4065 | 20 | 10 | gpadmin | <insufficient privilege> | | |
| | | pgAdmin III - ? ? ??? ?? ??? ? ? |
16992 | gtlions | 3678 | 15 | 10 | gpadmin | <insufficient privilege> | | |
| | | pgAdmin III - ?????? ??? |
16992 | gtlions | 3704 | 16 | 10 | gpadmin | <insufficient privilege> | | |
| | | pgAdmin III - ??? ?? ?? ??? ?? |
16992 | gtlions | 4023 | 18 | 25880 | t1 | <insufficient privilege> | | |
| | | psql |
(5 rows) gtlions=> select session_mgr(4023,'k');
session_mgr
-------------
t
(1 row) gtlions=> select * from pg_stat_activity ;
datid | datname | procpid | sess_id | usesysid | usename | current_query | waiting | query_start | backend_start
| client_addr | client_port | application_name | xact_start
-------+---------+---------+---------+----------+---------+----------------------------------+---------+-------------------------------+-------------------------------
+-------------+-------------+----------------------------+-------------------------------
16992 | gtlions | 4034 | 19 | 25881 | t2 | select * from pg_stat_activity ; | f | 2014-10-11 09:52:28.473137+08 | 2014-10-11 09:48:51.285594+08
| | -1 | psql | 2014-10-11 09:52:28.473137+08
16992 | gtlions | 4065 | 20 | 10 | gpadmin | <insufficient privilege> | | |
| | | pgAdmin III - ? ??? ? ? ?????? |
16992 | gtlions | 3678 | 15 | 10 | gpadmin | <insufficient privilege> | | |
| | | pgAdmin III - ? ? ? ??? ?? ? |
16992 | gtlions | 3704 | 16 | 10 | gpadmin | <insufficient privilege> | | |
| | | pgAdmin III - ? ??????????? |
16992 | gtlions | 4189 | 21 | 25880 | t1 | <insufficient privilege> | | |
| | | psql |
(5 rows) gtlions=>
最后检查下t1当前进程。
gtlions=> select version();
FATAL: terminating connection due to administrator 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.
-EOF-
非super user管理会话的更多相关文章
- Shiro经过Redis管理会话实现集群(转载)
原文:http://www.myexception.cn/software-architecture-design/1815507.html Shiro通过Redis管理会话实现集群 写在前面 1.在 ...
- spring security 管理会话 多个用户不可以使用同一个账号登录系统
多个用户不能使用同一个账号同时登陆系统. 1. 添加监听器 在web.xml中添加一个监听器,这个监听器会在session创建和销毁的时候通知Spring Security. <listener ...
- iOS非ARC内存管理摘要 - 实践型
关于ios内存管理.在开发过程中,内存管理很重要,我简单说明一下. 1.正确用法 UIView *v = [[UIView alloc] init]; //分配后引用计数为1 [self.view a ...
- IT兄弟连 JavaWeb教程 Servlet 状态管理 会话跟踪
HTTP协议是无状态的,我们的客户端与服务器的每一次请求与响应,我们服务器都没有记忆能力将客户端与服务器的多次交互数据进行存储与管理共有两种技术实现: ● 基于客户端实现:Cookie,将状态保存在 ...
- Supervisor安装与配置(非守护进程管理工具)
http://blog.csdn.net/xyang81/article/details/51555473
- MySql(二)_NHibernateHelper管理会话工厂
1.定义接口的好处: (1) 清楚的看到里面有哪些方法: ( 2 ) 可以更换实现类:Nhibernate实现件可以更换: Manger文件夹(另外两个是Model.Mappings文件夹) 首先M ...
- OWASP WEB会话管理备忘单 阅读笔记
https://www.owasp.org/index.php/Session_Management_Cheat_Sheet#Session_ID_Properties 会话简介 HTTP是一种无状态 ...
- 不要使用 JWT 进行会话管理
英文原文地址:Stop using JWT for sessions 最近我发现越来越多的人推荐使用 JWT 来在 Web 应用中管理会话(Session),这是一个非常非常糟糕的主意,在这篇文章中我 ...
- Servlet会话管理一(URL重写和表单隐藏域)
会话可以简单的理解为客户端用户打开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器的整个过程称为一个会话.即一个客户端用户和服务器端进行通讯的过程,也是客户端和服务器端之间的数据传 ...
随机推荐
- STM32 Hardware Development
http://www.st.com/web/en/resource/technical/document/application_note/CD00164185.pdf AN2586 http://w ...
- gitignore / Delphi.gitignore
https://github.com/github/gitignore/blob/master/Delphi.gitignore *.dcu *.~*~ *.local *.identcache __ ...
- DCI:The DCI Architecture: A New Vision of Object-Oriented Programming
SummaryObject-oriented programming was supposed to unify the perspectives of the programmer and the ...
- 记录memcache分布式策略及算法
摘要 http://wenku.baidu.com/link?url=eUmpWDGFiFguyQLxwmXwRYmbnW7Wm1Bo79dGoomSnmOPWDIA5-FFSTNRI7MBQq8QG ...
- 用500行Julia代码开始深度学习之旅 Beginning deep learning with 500 lines of Julia
Click here for a newer version (Knet7) of this tutorial. The code used in this version (KUnet) has b ...
- 解决引用openssl静态库libcrypto.a和libssl.a出现undefined reference to错误的问题
最近在做使用openssl链接http和https的项目,编译时出现以下问题. /usr/local/openssl/lib/libcrypto.a(async.o): In function `as ...
- iOS:使用Github托管自己本地的项目代码方式二(客户端方式: Github Desktop)
管理代码的地方主要有:Github(国外流行).CocoaChina.Cocoa4App.中国开源社区.CSDN.博客园.简书等等..... 前面已经介绍了如何使用命令行和Xcode将本地代码上传到G ...
- Unity3D 浅谈被忽略的Quality [转]
开始分享之前,我先墨迹几句... 最近在工作上,在交流群中,都会遇到一些问题.比如: 为什么打包Android Apk以后,图片变模糊了? 为什么移动端的阴影和电脑端不一样? 我的电脑明明配置很好,为 ...
- Vue使用中遇到问题汇总(三)
1.后台session过期前端跳转到登录页面 axios 拦截器 可以拦截请求和返回,对于失效的情况后端可以返回一个状态码,如401, 使用axios拦截时判断是401,则跳转到指定页面,如login ...
- java设计模式1--工厂方法模式(Factory Method)
本文地址:http://www.cnblogs.com/archimedes/p/java-factory-method-pattern.html,转载请注明源地址. 工厂方法模式(别名:虚拟构造) ...