简体   繁体   English

pandas to_sql() 错误 - 对于准备好的语句,超出了 memory 20 MB 的限制(每个 session)

[英]pandas to_sql() error - Exceeded the memory limit of 20 MB per session for prepared statements

I'm already using a chunksize of 50 and im running into memory errors.我已经使用了 50 的块大小并且我遇到了 memory 错误。 I need to upload about 250M records in total so if I use any lower of a chunksize I dont think it will finish within the next decade.我总共需要上传大约 250M 条记录,所以如果我使用任何更低的块大小,我认为它不会在未来十年内完成。 Any tips on how to get around this?关于如何解决这个问题的任何提示?

Database = Azure SQL Server数据库 = Azure SQL 服务器

final_df.to_sql('table', con=engine, schema='example', index=False, chunksize=50, if_exists='append', dtype={'ID':sqlalchemy.types.VARCHAR(length=255),'MSA_NAME':sqlalchemy.types.VARCHAR(length=255)})

I'd like to suggest an alternative.我想提出一个替代方案。

You could export the data as CSV and have it uploaded to one of Azure Storage Services ( Blob for instance - You could probably use AZCopy to achieve.您可以将数据导出为 CSV 并将其上传到 Azure 存储服务之一(例如 Blob - 您可以使用 AZCopy 来实现。

Then use Azure Data Factory in order to copy/import the files to the Azure SQL.然后使用 Azure 数据工厂将文件复制/导入到 Azure SQL。

Copy and transform data in Azure SQL Database by using Azure Data Factory 使用 Azure 数据工厂复制和转换 Azure SQL 数据库中的数据

You could refer to this thread which has a similar discussion.你可以参考这个有类似讨论的线程

I solved this by using fast_executemany=True and method='multi' -我通过使用fast_executemany=Truemethod='multi'解决了这个问题 -

engine = sqlalchemy.create_engine('mssql+pyodbc:///?odbc_connect=%s' % params, echo=False, connect_args={'autocommit': True}, fast_executemany=True)

... ...

final_df.to_sql('table', con=engine, schema='example', index=False, method='multi',  if_exists='append', dtype={'ID':sqlalchemy.types.VARCHAR(length=255),'MSA_NAME':sqlalchemy.types.VARCHAR(length=255)})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM