Fixes an issue where the connections to postgres were never closed.