찾다

非superuser管理会话

Jun 07, 2016 pm 04:04 PM
방해하다세션취소사용자관리하다

在gp中取消或者中断某个用户的超长时间或者SQL存在问题的会话,如果无法拥有超级用户将无法执行该类操作。 首先我们创建两个用户t1、t2,并且使用t1登录到数据库。 [gpadmin@wx60 ~]$ psql gtlionspsql (8.2.15)Type help for help. gtlions=# select version

在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 = &#39;c&#39; then
		ret := (select pg_catalog.pg_cancel_backend(procpid));
	elsif opertype = &#39;k&#39; 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,&#39;c&#39;);
 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,&#39;k&#39;);
 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-
성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
MySQL Blob : 한계가 있습니까?MySQL Blob : 한계가 있습니까?May 08, 2025 am 12:22 AM

mysqlblobshavelimits : tinyblob (255bodes), blob (65,535 bytes), mediumblob (16,777,215 bctes), andlongblob (4,294,967,295 Bytes) .tousebl obseffectical : 1) 고려 사항을 고려합니다

MySQL : 사용자 생성을 자동화하는 가장 좋은 도구는 무엇입니까?MySQL : 사용자 생성을 자동화하는 가장 좋은 도구는 무엇입니까?May 08, 2025 am 12:22 AM

MySQL에서 사용자 생성을 자동화하기위한 최고의 도구 및 기술은 다음과 같습니다. 1. MySQLworkBench, 중소형 환경에 적합하고 사용하기 쉽지만 자원 소비가 높습니다. 2. 다중 서버 환경에 적합한 Ansible, 간단하지만 가파른 학습 곡선; 3. 사용자 정의 파이썬 스크립트, 유연하지만 스크립트 보안을 보장해야합니다. 4. 꼭두각시와 요리사는 대규모 환경에 적합하며 복잡하지만 확장 가능합니다. 선택할 때 척도, 학습 곡선 및 통합 요구를 고려해야합니다.

MySQL : 블로브 내부를 검색 할 수 있습니까?MySQL : 블로브 내부를 검색 할 수 있습니까?May 08, 2025 am 12:20 AM

예, youcansearchinsideablobinmysqlusingspecifictechniques.1) converttheblobtoautf-8stringwithConvertFunctionandSearchusing

MySQL 문자열 데이터 유형 : 포괄적 인 가이드MySQL 문자열 데이터 유형 : 포괄적 인 가이드May 08, 2025 am 12:14 AM

mysqloffersvariousStringDatatatypes : 1) charfixed-lengthstrings, 이상적인 원인이 길이의 길이가 길이 스트링스, 적합한 포르 플리드 슬리 키나 이름; 3) TextTypesforlargerText, goodforblogpostsbutcactperformance;

MySQL Blobs 마스터 링 : 단계별 자습서MySQL Blobs 마스터 링 : 단계별 자습서May 08, 2025 am 12:01 AM

TomasterMySQLBLOBs,followthesesteps:1)ChoosetheappropriateBLOBtype(TINYBLOB,BLOB,MEDIUMBLOB,LONGBLOB)basedondatasize.2)InsertdatausingLOAD_FILEforefficiency.3)Storefilereferencesinsteadoffilestoimproveperformance.4)UseDUMPFILEtoretrieveandsaveBLOBsco

MySQL의 Blob Data Type : 개발자를위한 상세한 개요MySQL의 Blob Data Type : 개발자를위한 상세한 개요May 07, 2025 pm 05:41 PM

blobdatatypesinmysqlareusedforvoringlargebinarydatalikeimagesoraudio.1) useblobtypes (tinyblobtolongblob) 기반 론다 타지 세인. 2) StoreBlobsin perplate petooptimize 성능.

명령 줄에서 MySQL에 사용자를 추가하는 방법명령 줄에서 MySQL에 사용자를 추가하는 방법May 07, 2025 pm 05:01 PM

toadduserstomysqlfromthecommandline, loginasroot, whenUseCreateUser'Username '@'host'IdentifiedBy'Password '; toCreateAwUser.grantPerMissionswithGrantAllilegesOndatabase

MySQL의 다른 문자열 데이터 유형은 무엇입니까? 자세한 개요MySQL의 다른 문자열 데이터 유형은 무엇입니까? 자세한 개요May 07, 2025 pm 03:33 PM

mysqlofferSeightStringDatatatypes : char, varchar, binary, varbinary, blob, text, enum and set.1) charisfix-length, 2) varcharisvariable-length, 효율적 인 datalikenames.3) binaryandvarbinary-binary Binary Binary Binary Binary Binary Binary Binary-Binary

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

ZendStudio 13.5.1 맥

ZendStudio 13.5.1 맥

강력한 PHP 통합 개발 환경

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

Dreamweaver Mac版

Dreamweaver Mac版

시각적 웹 개발 도구

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

안전한 시험 브라우저

안전한 시험 브라우저

안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.