phppgadmin : How does it kick users out of postgres, so it can db_drop? phppgadmin : How does it kick users out of postgres, so it can db_drop? postgresql postgresql

phppgadmin : How does it kick users out of postgres, so it can db_drop?


First, find all current procesid's using your database:

SELECT usename, procpid FROM pg_stat_activity WHERE datname = current_database();

Second, kill the processes you don't want:

SELECT pg_terminate_backend(your_procpid);

This works as of version 8.4, otherwise pg_terminate_backend() is unknown and you have to kill the process at OS level.


To quickly drop all connections connected to a given database, this shortcut works nicely. Must run as superuser:

SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname='YourDB';

On more recent Postgres versions (at least 9.2+, likely earlier), the column names have changed and the query is:

SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='YourDB';


Not sure about PostgreSQL but i think a possible solution would be to lock the table so other processes will fail when they try to access it.

See:http://www.postgresql.org/docs/current/static/sql-lock.html