Postgresql函数锁错误
我有一个更新缓存表的触发器。 触发器执行的函数执行两个操作:删除旧的缓存行并根据 id 添加新的缓存行,总
缓存表列为: id |总计
由于服务器活动水平较高,我相信对该函数的两次并行调用将产生以下情况:
Delete 1 Delete 2 Insert 1 Insert 2 ( this will crash because of the primary key )
有什么方法可以防止这种情况吗?事务不应该阻止这种情况(postgresql 函数中的隐含事务)
I have a trigger that updates a cache table.
The function executed by the trigger makes two operation: deletes the old cache row and adds a new cache row based on the id with a total
cache table columns: id | total
Because of the high level of server activity I believe that two paralles calls on the function will generate the following situation:
Delete 1 Delete 2 Insert 1 Insert 2 ( this will crash because of the primary key )
Is there any way I can prevent this ? Shouldn't the transaction prevent this ( the implied transaction in a postgresql function )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用咨询锁。 http://www.postgresql.org/docs/9.0/interactive/functions -admin.html
帕维尔
you can use a advisory locks. http://www.postgresql.org/docs/9.0/interactive/functions-admin.html
Pavel