Postgresql 如何在pgsql中断开连接拉入?

Postgresql 如何在pgsql中断开连接拉入?,postgresql,Postgresql,在这次执行之后,当我执行 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

在这次执行之后,当我执行

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_();

这将是繁忙的任何人告诉我如何清除拉入pgsql

您可以向这个繁忙连接的后端进程发送信号

要取消正在运行的查询,请向运行该命令的进程发送SIGINT信号。要干净地终止后端进程,请向该进程发送SIGTERM

对于exp:

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;

它返回所有与ID的连接

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
您可以通过以下查询通过procpid终止特定连接

SELECT * from pg_stat_activity;

我不知道“清除拉”是什么意思。当我在脚本之后执行查询时,它会很忙,因为数据库连接很忙。您能告诉我如何关闭连接吗?按键盘上的Ctrl+C如何?问题可能是当查询仍在后台运行到完成时如何退出psql?使用
pg\u cancel\u backend(pid int)
pg\u terminate\u backend(pid int)可能更容易些
取消查询和
pg\u stat\u activity
查看以获取
pid
。是的,但是dba没有更多连接时?你应该用信号杀死它。
select pg_terminate_backend(procpid)
    from pg_stat_activity
    where datname = 'database-name'