每天插入和更新 400 万条记录

Posted

技术标签:

【中文标题】每天插入和更新 400 万条记录【英文标题】:Insert and update 4 million records everyday 【发布时间】:2019-11-04 17:23:13 【问题描述】:

审计目的,我想在一张表中插入100万条记录

再次将 100 万条记录放入另一个表中。

并更新交易表(生产数据库)中的 100 万条记录,并再次更新

在另一个事务表(生产数据库)中更新 100 万条记录。

所以超过所有 40M 记录。等待资源时检测到错误 ORA-00060 死锁。

实际上我不能在事务之间提交。成功完成任务后,我必须提交事务。例如,如果我为每个插入保持提交,任何错误都会发生我无法回滚。

我是甲骨文的新手。请多多指教。

提前致谢

流程

插入 1M

插入 1M

更新 1M

更新 1M

提交;

Create or replace procedure prc_tagbalance
As
Begin
  Insert into t1 
  Select custid,mobileno,openingbal,currentvalue
  From mas_walletinfo;
Exception
  -- Error table insert using procedurr with pragma Autonomous transaction
  Return;
End;

Begin
  Insert into t2
    Select vechileid,tid,tbalance from mas_vehicleinfo;
Exception
  --error table insert
  Return;
End;

Begin
  Update mas_walletinfo set openingbal=currentvalue;
Exception
  Return;
End;
Begin
  Update mas_vechileinfo set openingbal=tbalnce:
  Commit;
Exception
  Return;
End:
End;

【问题讨论】:

ORA-0600 与您插入的记录数无关。您必须发布minimal reproducible example 的代码,否则,这里没有人可以提供帮助。看看here 以获得一些建议。 您好,很抱歉给您带来不便。仍然不清楚。我将添加完整的代码。 Kkndy 建议。提前致谢 询问您的 DBA - ORA-0600 在服务器上生成一个跟踪文件,其中包含系统检测到死锁的原因的详细信息。 【参考方案1】:

在每次操作后提交。

Create or replace procedure prc_tagbalance
As
Begin
  Insert into t1 
  Select custid,mobileno,openingbal,currentvalue
  From mas_walletinfo;
 Commit;
Exception
  -- Error table insert using procedurr with pragma Autonomous transaction
  Return;
End;

Begin
  Insert into t2
    Select vechileid,tid,tbalance from mas_vehicleinfo;
 Commit;
Exception
  --error table insert
  Return;
End;

Begin
  Update mas_walletinfo set openingbal=currentvalue;
 Commit;
Exception
  Return;
End;
Begin
  Update mas_vechileinfo set openingbal=tbalnce:
  Commit;
Exception
  Return;
End:
End;

【讨论】:

实际上,如果我在任何事务之间放置任何提交,如果发生任何错误。我必须回滚。

以上是关于每天插入和更新 400 万条记录的主要内容,如果未能解决你的问题,请参考以下文章

数据库缓慢检索/更新/插入问题,每个表中有超过 500 万条记录

如何使用查找的值将记录插入 SQL?

数据库快速插入1000万条记录

数据库快速插入1000万条记录

oracle 插入100万条数据,更新100万条数据

Mysql-Insert插入过慢的原因记录和解决