Reset the pg connection if it seems broken

Fix #784