首页 > 解决方案 > cx_Oracle 中批量处理的性能改进

问题描述

使用 cx_Oracle 将数据批量加载到 oracle 时面临性能问题。似乎附加提示不适用于 cx_Oracle 或至少我无法使其工作。任何帮助将不胜感激

我试图使用 cx_Oracle 将 200 万条记录批量推送到 Oracle,但是如果我使用附加提示,它只需要 20 秒,而从 oracle 到 oracle 需要 1.5 分钟。

insertquery="""insert /*+ append parallel(XYZ,8) */ into XYZ(A,B,C,D,E,F,G,H, I,J,K,L,M,N,O,P,Q,R,S)             VALUES('abc',:B,'N',:D,:E,:F,:G,:H,:I,:J,:K,:L,:M,:N,:O,'MIG','MIG',{current_time},{current_time})""".format(current_time=current_time)


print("XYZ START",datetime.datetime.now())
trg_cur.prepare(insertquery)
trg_cur.executemany(None,entityList)'''

如果我保留附加提示,所用时间保持不变。除了线程之外,还有什么方法可以提高这种性能,我会在多个线程中运行它,因为我的输入数据范围可以达到几亿行,我必须将此数据插入多个表中

标签: python-3.xoracleperformance-testingbulkinsertcx-oracle

解决方案


using append_Values worked like a charm and 40 sec reduced to 10 sec for pushing 1 million records

insertquery="""insert /*+ append_values parallel(XYZ,8) */ into XYZ(A,B,C,D,E,F,G,H, I,J,K,L,M,N,O,P,Q,R,S)             VALUES('abc',:B,'N',:D,:E,:F,:G,:H,:I,:J,:K,:L,:M,:N,:O,'MIG','MIG',{current_time},{current_time})""".format(current_time=current_time)


推荐阅读