Major refactoring of PostgreSQL backend to improve reliability

-executePreparedQuery() can now detect if a query failed due to the
DB connection being down and reopen the connection.
-Wherever possible, queries use the executePreparedQuery() code to
take advantage of the above.
-All queries have watchQuery() executed on them to log any errors
that may occur.