暂无图片
暂无图片
5
暂无图片
暂无图片
暂无图片

PostgreSQL参数—deadlock_timeout

原创 李先生 2022-02-25
2110

PostgreSQL参数—deadlock_timeout


PostgreSQL参数—deadlock_timeout

参数说明

postgres=# show deadlock_timeout; deadlock_timeout ------------------ 1s (1 row) postgres=# \x Expanded display is on. postgres=# select * from pg_settings where name = 'recovery_target_timeline'; -[ RECORD 1 ]---+---------------------------------------- name | recovery_target_timeline setting | latest unit | category | Write-Ahead Log / Recovery Target short_desc | Specifies the timeline to recover into. extra_desc | context | postmaster vartype | string source | default min_val | max_val | enumvals | boot_val | latest reset_val | latest sourcefile | sourceline | pending_restart | f postgres=#

参数变更

此参数只能在服务器启动时应用,因此任何更改都需要重新启动服务器。这些设置的值通常存储在postgresql.conf文件中,或在启动服务器时通过命令行传递。

postgres=# show deadlock_timeout; deadlock_timeout ------------------ 1s (1 row) postgres=# alter system set deadlock_timeout=2; ALTER SYSTEM postgres=# show deadlock_timeout; deadlock_timeout ------------------ 1s (1 row) postgres=# exit [postgres@lyp ~]$ pg_ctl restart waiting for server to shut down....... done server stopped waiting for server to start....2022-02-25 23:26:32.660 CST [9286] LOG: redirecting log output to logging collector process 2022-02-25 23:26:32.660 CST [9286] HINT: Future log output will appear in directory "log". done server started [postgres@lyp ~]$ psql psql (14.1) Type "help" for help. postgres=# show deadlock_timeout; deadlock_timeout ------------------ 2ms (1 row) postgres=#

参数含义

deadlock_timeout (integer)

这是在检查是否存在死锁条件之前等待锁的时间。死锁检查相对昂贵,因此服务器不会在每次等待锁时都运行它。我们乐观地假设死锁在生产应用程序中并不常见,只需在锁上等待一段时间,然后再检查死锁。增加此值可减少不必要的死锁检查所浪费的时间,但会减慢真正死锁错误的报告速度。如果指定此值没有单位,则以毫秒为单位。默认值为一秒 (1s),这可能是在实践中想要的最小值。在负载很重的服务器上,您可能需要提升它。理想情况下,该设置应该超过您的典型事务时间,以提高在服务员决定检查死锁之前释放锁的几率。只有超级用户可以更改此设置。

log_lock_waits被设置时,这个参数还可以决定发出关于锁等待的日志之前等待的时间量。如果你想分析锁延迟,你可以设置一个比正常的deadlock_timeout小的值。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论