How to break a connection in pgsql?

CREATE OR REPLACE FUNCTION add_() RETURNS void AS 
$BODY$ 
declare
    foo int; 
BEGIN

FOR i IN 1..50 LOOP         
    foo = i;
    RAISE NOTICE 'combination_array(%)', foo ;
    UPDATE table_1 set r_id = foo WHERE id = (select id from table_1 where r_id is null order by id limit 1); 
END LOOP;

END; $BODY$ LANGUAGE 'plpgsql' ;

SELECT add_();

after this execution when i execute

UPDATE table_1 
   set r_id = foo 
WHERE id = (select id from table_1 where r_id is null order by id limit 1); 

END LOOP;

he will be busy, someone will tell me how to clear traction in pgsql

+4
source share
2 answers

it returns all connection with identifiers

SELECT * from pg_stat_activity;

You can kill a specific procpid connection, but after a request.

select pg_terminate_backend(procpid)
    from pg_stat_activity
    where datname = 'database-name'
+4
source

You can send a signal to this connected active process.

To cancel a running request, send a SIGINT signal to the process executing this command. To complete the backend process, send SIGTERM to this process.

for exp:

pg93@db-172-16-3-150-> psql
psql (9.3.3)
Type "help" for help.
digoal=# select pg_sleep(1000000);
-- find the pid
-- ps -ewf|grep postgres
pg93     24872 23190  0 00:11 ?        00:00:00 postgres: postgres digoal [local] SELECT

-- send signal
pg93@db-172-16-3-150-> kill -s SIGINT 24872
-- then we see that feedback from psql.
ERROR:  canceling statement due to user request
0
source

Source: https://habr.com/ru/post/1536128/


All Articles