Replace dependency on pyPgSQL with the better maintained psycopg2.

Based on a patch by Nuno Santos.