2016-11-30 171 views
3

我有两张表A和B与分类账相关。许多交易并行发生在A和B两者中。面临锁表直到交易提交

问题是:螺纹28之前

[28] - A insert success for source entity_id: id001 
[28] - B update success for destination entity_id: id002 
[28] - A insert success for destination entity_id: id002 
[71] - B update success for source entity_id: id001     
[28] - commit success for [28] with amount 100 

螺纹71个更新表B提交更改到分类帐。

这是因为postgres在进程使用它时锁定了表。

  1. 我该如何让线程等待提交完成当前线程?
  2. 如何在postgres中锁定记录? (以便用户可以访问表中的其他帐户)

回答

1

Postgres默认锁定记录。请参阅docs

对于提供的日志,最后一个日志必须在提交事务后。只要交易完成,等待的线程立即接管,这就是你的日志以这种方式出现的原因。