added cleanup of postgres connection

After all sockets leave a given channel we need to close the
connection to postgres so postgres will queue the notifications
if nobody is listening