diff --git a/db.py b/db.py
index b9779834376827c109f54dfa3f523f675097907c..efb35f744dd3039131017f9a90f2f0ce87f3edf9 100644
--- a/db.py
+++ b/db.py
@@ -91,11 +91,11 @@ elif config['DB_ENGINE'] == 'mysql':
 		db.close()
 		return res
 elif config['DB_ENGINE'] == 'postgres':
-	import psycopg  # pylint: disable=import-error
+	import psycopg2  # pylint: disable=import-error
 	
 	def get_dbcursor():
-		if 'db' not in g or g.db.broken:
-			g.db = psycopg.Connection.connect(
+		if 'db' not in g or g.db.closed:
+			g.db = psycopg2.connect(
 				host=config["POSTGRES_HOST"],
 				port=config["POSTGRES_PORT"],
 				user=config["POSTGRES_USER"],
@@ -133,7 +133,7 @@ def query(operation, *params, delim="sep", nlfix=True):
 	try:
 		rows = cur.fetchall()
 	except Exception as e:  # pylint: disable=broad-except
-		if str(e) == 'No result set to fetch from.' or str(e) == "the last operation didn't produce a result":
+		if str(e) == 'no results to fetch' or str(e) == "the last operation didn't produce a result":
 			# no problem, we were just at the end of the result set
 			pass
 		else: