Auto reconnect or throw an exception if connection closed for listen() method. To close connection 1. select * from pg_stat_activity where datname = 'db' 2. select pg_terminate_backend(pid) - get pid from 1.