Kill a postgresql session/connection

前端 未结 20 1945
暖寄归人
暖寄归人 2020-11-28 00:11

How can I kill all my postgresql connections?

I\'m trying a rake db:drop but I get:

ERROR:  database \"database_name\" is being accessed         


        
20条回答
  •  囚心锁ツ
    2020-11-28 00:42

    Case :
    Fail to execute the query :

    DROP TABLE dbo.t_tabelname
    

    Solution :
    a. Display query Status Activity as follow :

    SELECT * FROM pg_stat_activity  ;
    

    b. Find row where 'Query' column has contains :

    'DROP TABLE dbo.t_tabelname'
    

    c. In the same row, get value of 'PID' Column

    example : 16409
    

    d. Execute these scripts :

    SELECT 
        pg_terminate_backend(25263) 
    FROM 
        pg_stat_activity 
    WHERE 
        -- don't kill my own connection!
        25263 <> pg_backend_pid()
        -- don't kill the connections to other databases
        AND datname = 'database_name'
        ;
    

提交回复
热议问题