ChangesetMD icon indicating copy to clipboard operation
ChangesetMD copied to clipboard

Speed up import with batch execution

Open jlevente opened this issue 5 years ago • 2 comments

Using pyscopg2.extras.execute_batch() and inserting data in batches of 100,000 changesets will speed up the import. On my machine it was ~2x faster than the original method of inserting data line by line.

See documentation for Fast execution helpers in the psycopg docs.

jlevente avatar May 30 '19 14:05 jlevente

When trying to import I get this error

creating tables
parsing changeset file with geometries
Traceback (most recent call last):
  File "./changesetmd.py", line 264, in <module>
    md.parseFile(conn, changesetFile, args.doReplication)
  File "./changesetmd.py", line 122, in parseFile
    self.insertNewBatch(connection, changesets)
  File "./changesetmd.py", line 59, in insertNewBatch
    psycopg2.extras.execute_batch(cursor, sql, data_arr)
AttributeError: 'module' object has no attribute 'execute_batch'

pnorman avatar Aug 22 '19 20:08 pnorman

@pnorman - I'm not working on this actively, but saw this cross my inbox and thought I'd try to help. What version of psycopg2 do you have installed? It looks like execute_batch was only introduced in version 2.7 per notes here. Try upgrading psycopg2 in whatever environment you're running the script.

amahon avatar Aug 23 '19 04:08 amahon