gpt4 book ai didi

ruby-on-rails - 在事务期间保持数据可用 (postgresql)

转载 作者:行者123 更新时间:2023-11-29 12:48:45 25 4
gpt4 key购买 nike

为什么我无法在使用截断语句的事务期间访问数据?

我虽然可以在同一个表上运行事务时读取表的数据。只要您不执行截断语句,就有可能。我没有在文档中发现任何反对它的内容。

这里有一个示例项目来说明这种行为,自述文件试图解释如何重现:https://github.com/Haelle/pg_transaction_tests

如果它不应该发生,它可能是一个问题? :

  • 我的代码...
  • 事件记录
  • 珍宝
  • Postgresql 中的一个选项

最佳答案

这是 postgresql 特有的东西,来自 TRUNCATE documentation :

TRUNCATE acquires an ACCESS EXCLUSIVE lock on each table it operates on, which blocks all other concurrent operations on the table. When RESTART IDENTITY is specified, any sequences that are to be restarted are likewise locked exclusively. If concurrent access to a table is required, then the DELETE command should be used instead.

这是您遇到的一个非常具体的用例。不确定为什么在截断事务期间需要能够访问即将被截断的表。但是,正如注释所说:改用 delete 。在 rails 中,这意味着:.destroy_all(检查 rails 验证)或 .delete_all(不检查 rails 验证)

关于ruby-on-rails - 在事务期间保持数据可用 (postgresql),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58956860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com