import psycopg
dbh = psycopg.connect('dbname=dbname user=userName')
print "Connection successful."
cur = dbh.cursor()
cur.execute("SELECT * FROM myTable")
cur.arraysize = 2
while 1:
rows = cur.fetchmany()
print "Obtained %d results from fetchmany()." % len(rows)
if not len(rows):
break
for row in rows:
print row
dbh.close()