 <p>You can use <a href="http://www.postgresql.org/docs/current/static/functions-admin.html">pg_terminate_backend()</a> to kill a connection. You have to be superuser to use this function. This works on all operating systems the same. </p> <pre><code>SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE -- don't kill my own connection! pid &lt;&gt; pg_backend_pid() -- don't kill the connections to other databases AND datname = 'database_name' ; </code></pre> <p>Before executing this query, you have to <a href="http://www.postgresql.org/docs/current/interactive/sql-revoke.html">REVOKE</a> the CONNECT privileges to avoid new connections:</p> <pre><code>REVOKE CONNECT ON DATABASE dbname FROM PUBLIC, username; </code></pre> <blockquote> <p>If you're using Postgres 8.4-9.1 use procpid instead of pid</p> </blockquote> <pre><code>SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE -- don't kill my own connection! procpid &lt;&gt; pg_backend_pid() -- don't kill the connections to other databases AND datname = 'database_name' ; </code></pre>