Postgres error handling

Closes #8485
pylint
Fix failing test.
Merge pull request #12473 from cachedout/8485

Postgres error handling