Clean up postgres connection handling