我应该在每次执行之后还是在循环之后提交

时间:2019-05-31 11:05:27

标签: python oracle

我在循环中有2000次插入 我确实执行sql

我的问题是:我应该在每次执行或循环之后执行一次提交,以最大程度地减少对锁定表的影响并且不关心缓冲区吗?

问题:我的脚本发送了很多查询,它们处于等待状态

我不问提交中x行的sql限制,也不问代码回滚。我的问题是关于在oracle服务器中半天不活动的队列以及一些等待并阻止新进程运行的队列。

1 个答案:

答案 0 :(得分:2)

2000 inserts is close to nothing. Though, it would be far better if you could insert them at once, using a single INSERT statement, than doing it in a loop.

Generally speaking, commit once you're done with the transaction. It is most probably not ended at every turn of the loop, is it? Besides, committing in a loop (frequently) leads to ORA-01555 snapshot too old error.

Saying that "your script sends many queries" - what kind of them? SELECTs aren't blocked by anything. INSERTs aren't blocked either (I guess you don't lock the whole table, do you)? If you're trying to update rows locked by other user(s), that - obviously - won't work until they are released. The question is: why do those queries wait half a day? Smells like bad management.