Well, this seems to be a local administration issue, you've lost connection to your database, so it sounds like the database is down.
This problem might also come from too many opened connections, and hence be related to #8443.
Finally, this problem might be due to the use of pyPgSql itself, as we don't test it, we don't know how reliable this package is (and there are a number of reported problems with it).
So we recommend that you use psycopg2 rather than pyPgSql (see DatabaseBackend).
Hijacking this ticket so that we effectively disable support for pyPgSql in the code. That will remove one possible cause of trouble.