I populate a PostgreSQL table with ~ 11.000.000 rows that were previously selected from another database. I am using Python and psycopg2. The whole process takes about 1.5 hours. However, after ~ 30 minutes, I get an exception "connection closed unexpectedly." The source code is as follows:
incursor = indb.cursor()
incursor.execute("SELECT ...")
indb.commit()
outcursor = outdb.cursor()
rows = 0
for (col1, col2, col3) in incursor:
outcursor.execute("INSERT ...", (col1, col2, col3))
row += 1
if row % 100 == 0:
outcursor.close()
outdb.commit()
outcursor = outdb.cursor()
incursor.close()
outcursor.close()
outdb.commit()
I inserted (1)and (2)after the first attempt failed, assuming that the open transaction has an upper limit of time of ~ 30 minutes or that the cursor has an upper limit of waiting inserts. It seems that none of these assumptions is true, and the error lies elsewhere.
VirtualBox, . .
, . , , , ( ), psycopg2 PostgreSQL.