Here is my answer to [very similar question][1] on StackOverflow. 

Depending on your version of postgresql you might run into a bug, that makes `pg_stat_activity` to omit active connections from dropped users. These connections are also not shown inside pgAdminIII. 

If you are doing automatic testing (in which you also create users) this might be a probable scenario. 

In this case you need to revert to queries like: 

     
     SELECT pg_terminate_backend(pg_stat_activity.procpid) 
     FROM pg_stat_get_activity(NULL::integer) 
     WHERE datid=(SELECT oid from pg_database where datname = 'your_database');


  [1]: https://stackoverflow.com/questions/5408156/how-to-drop-a-postgresql-database-if-there-are-active-connections-to-it/19884946#19884946