improved postgres error handling