Skip to content

Conversation

@jlevente
Copy link
Contributor

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.

@pnorman
Copy link
Contributor

pnorman commented Aug 22, 2019

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'

@amahon
Copy link

amahon commented Aug 23, 2019

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants