PostgreSQL是否为只读事务运行一些性能优化

时间:2015-10-25 17:28:25

标签: database postgresql transactions readonly database-concurrency

根据reference documentation READ ONLY事务标志除了允许DEFERRABLE事务之外有用吗?

arrayResult = ['value1', 'value3']
  

除非相关,否则DEFERRABLE事务属性无效   交易也是SERIALIZABLE和READ ONLY。全部三个   这些属性是为事务选择的,事务可以   在第一次获取其快照时阻止,之后它可以运行   没有SERIALIZABLE交易的正常开销而没有   任何因序列化而导致或被取消的风险   失败。此模式非常适合长时间运行的报告或备份。

数据库引擎是否为只读事务运行其他优化?

2 个答案:

答案 0 :(得分:7)

总结Nick Barnes和Craig Ringer在评论中的评论:

  1. READ_ONLY标志不一定提供任何优化
  2. 设置READ_ONLY标志的主要好处是确保不会修改元组

答案 1 :(得分:2)

实际上,是的。让我在这里引用源代码注释:

/*
 * Check if we have just become "RO-safe". If we have, immediately release
 * all locks as they're not needed anymore. This also resets
 * MySerializableXact, so that subsequent calls to this function can exit
 * quickly.
 *
 * A transaction is flagged as RO_SAFE if all concurrent R/W transactions
 * commit without having conflicts out to an earlier snapshot, thus
 * ensuring that no conflicts are possible for this transaction.
 */