{"Entry":{"collection":"guc","key":"deadlock_timeout","name":"deadlock_timeout","aliases":[],"metadata":{"baseline":true,"boot_human":"Not specified","boot_val":null,"category":"Lock Management","category_zh":"","changed_in":["9.1","9.2"],"changes":[{"documentation_changed":true,"fields":{},"from":"8.1","status":"changed","to":"8.2"},{"documentation_changed":true,"fields":{},"from":"8.2","status":"changed","to":"8.3"},{"documentation_changed":true,"fields":{},"from":"8.4","status":"changed","to":"9.0"},{"documentation_changed":false,"fields":{"max_val":{"from":"2147483","to":"2147483647"}},"from":"9.0","status":"changed","to":"9.1"},{"documentation_changed":true,"fields":{"context":{"from":"sighup","to":"superuser"}},"from":"9.1","status":"changed","to":"9.2"},{"documentation_changed":true,"fields":{},"from":"11","status":"changed","to":"12"},{"documentation_changed":true,"fields":{},"from":"14","status":"changed","to":"15"}],"content_hash":"bdbd391e5149b6820844eddc03f253511c2b4ba9c144b201fa31812f1d12d806","context":"","default_changed_in":[],"default_history":[{"from":"9.0","to":"19","value":"1 s"}],"editorial":{"advice":{"olap":"Partitioned queries, bulk DDL, and SERIALIZABLE reports may touch many objects; test the worst plan, not only an average transaction.","oltp":"Calibrate deadlock_timeout from lock-wait logs, objects touched, and the concurrency bound. Fix long transactions and access ordering before adding shared memory or changing detection granularity.","small":"Defaults are usually sufficient. If raising a startup lock-table setting, account for max_connections, prepared transactions, and standby consistency together."},"mechanism":["Sets the time to wait on a lock before checking for deadlock. A superuser or a role granted SET privilege can change it for the relevant session or configuration scope.","PostgreSQL waits this long before running the comparatively expensive deadlock detector. The same interval controls lock-wait logging when log_lock_waits is enabled, so lowering it improves diagnostics and deadlock response at the cost of more checks during ordinary contention.","Monitor and change deadlock_timeout together with log_lock_waits, lock_timeout, max_locks_per_transaction. Validate on the relevant server role and real workload, then use its superuser context to choose session change, reload, or restart; a historical boot default is not the current effective value."],"pitfalls":["Reading an average shared-memory sizing value as a hard per-transaction limit.","Raising it without the multiplier from connections and prepared transactions.","Expanding lock memory instead of fixing long transactions, access order, or partition explosion.","Ignoring compatible startup lock capacity on standbys."],"references":[{"title":"PostgreSQL 19 Beta 4: deadlock_timeout","url":"https://www.postgresql.org/docs/19/runtime-config-locks.html#GUC-DEADLOCK-TIMEOUT"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["log_lock_waits","lock_timeout","max_locks_per_transaction","max_pred_locks_per_transaction","max_pred_locks_per_page","max_pred_locks_per_relation"],"summary":"deadlock_timeout — Sets the time to wait on a lock before checking for deadlock. Observed in PG9.0–19 Beta 4; its last measured boot default is 1 s in PG19 Beta 4, with superuser context. This is a beta-snapshot fact and can change before PostgreSQL 19 GA."},"enumvals":[],"first_version":"7.4","group":"Lock Management","group_slug":"locks","imported_at":"2026-09-27T17:57:31.027488+08:00","intro_commit":{},"key":"deadlock_timeout","last_version":"20","max_val":"","min_val":"","name":"deadlock_timeout","position":81,"present_in":["7.4","8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"short_desc":"This is the amount of time to wait on a lock before checking to see if there is a deadlock condition.","short_desc_zh":"","source_rev":"english-manuals:27aea65506bb8466f2a581c2c505537b26cd892d07ec370eccfe3cdda4004b38","unit":"","vartype":"integer"}},"Definition":{"Collection":"guc","Key":"deadlock_timeout","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"deadlock_timeout","SourceRevision":"english-manuals:27aea65506bb8466f2a581c2c505537b26cd892d07ec370eccfe3cdda4004b38","Facts":{"boot_val":"1000","category":"Lock Management","context":"superuser","description":"This is the amount of time to wait on a lock before checking to see if there is a deadlock condition. The check for deadlock is relatively expensive, so the server doesn't run it every time it waits for a lock. We optimistically assume that deadlocks are not common in production applications and just wait on the lock for a while before checking for a deadlock. Increasing this value reduces the amount of time wasted in needless deadlock checks, but slows down reporting of real deadlock errors. If this value is specified without units, it is taken as milliseconds. The default is one second (1s), which is probably about the smallest value you would want in practice. On a heavily loaded server you might want to raise it. Ideally the setting should exceed your typical transaction time, so as to improve the odds that a lock will be released before the waiter decides to check for deadlock. Only superusers and users with the appropriate SET privilege can change this setting. When log_lock_waits is set, this parameter also determines the amount of time to wait before a log message is issued about the lock wait. If you are trying to investigate locking delays you might want to set a shorter than normal deadlock_timeout.","doc":{"anchor":"GUC-DEADLOCK-TIMEOUT","file":"runtime-config-locks.html","lang":"en","sha256":"5faab37986a9ca9ff362569c12b8c63e8df57c76c9aea6e40d06e44e9abee87b","slug":"18"},"documented":true,"enumvals":null,"extra_desc":null,"lang":"en","max_val":"2147483647","metadata_version":"18","min_val":"1","name":"deadlock_timeout","short_desc":"Sets the time to wait on a lock before checking for deadlock.","source":"pg-settings-source-snapshot","unit":"ms","vartype":"integer"},"ManualEvidence":{"doc":{"anchor":"GUC-DEADLOCK-TIMEOUT","file":"runtime-config-locks.html","lang":"en","sha256":"5faab37986a9ca9ff362569c12b8c63e8df57c76c9aea6e40d06e44e9abee87b","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"deadlock_timeout","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"deadlock_timeout","Summary":"","BodyHTML":"\u003cp\u003e指定在检查是否发生死锁之前等待锁的时间。检查死锁相对昂贵，因此服务器不会每次等待锁时都运行它。我们乐观地假设在生产应用程序中死锁并不常见，所以在检查死锁之前只是等待一段时间。增加此值会减少在不必要的死锁检查中浪费的时间，但会减慢实际死锁错误的报告速度。如果未指定单位，则将其视为毫秒。默认值为一秒（\u003ccode\u003e1s\u003c/code\u003e），这可能是你在实践中想要的最小值。在负载较重的服务器上，你可能希望提高它。理想情况下，设置应超过你的典型事务时间，以提高在等待者决定检查死锁之前释放锁的几率。只有超级用户和具有适当\u003ccode\u003eSET\u003c/code\u003e权限的用户才能更改此设置。\u003c/p\u003e\u003cp\u003e当\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-LOCK-WAITS\" rel=\"nofollow\"\u003elog_lock_waits\u003c/a\u003e被设置时，这个参数也决定发出关于锁等待的日志之前等待的时间量。如果你想调查锁延迟，你可能希望设置一个比正常的\u003ccode\u003edeadlock_timeout\u003c/code\u003e小的值。\u003c/p\u003e","SourceRevision":"2026-09-11@29c86d9","ContentHash":"81db72614c92247cb4e91802f6bfd3f608b10ae54b299ebaeb360ac75fc57a6a","Payload":{"carried_from":"","carry_reason":"","doc_html":"\u003cp\u003e指定在检查是否发生死锁之前等待锁的时间。检查死锁相对昂贵，因此服务器不会每次等待锁时都运行它。我们乐观地假设在生产应用程序中死锁并不常见，所以在检查死锁之前只是等待一段时间。增加此值会减少在不必要的死锁检查中浪费的时间，但会减慢实际死锁错误的报告速度。如果未指定单位，则将其视为毫秒。默认值为一秒（\u003ccode class=\"literal\"\u003e1s\u003c/code\u003e），这可能是你在实践中想要的最小值。在负载较重的服务器上，你可能希望提高它。理想情况下，设置应超过你的典型事务时间，以提高在等待者决定检查死锁之前释放锁的几率。只有超级用户和具有适当\u003ccode class=\"literal\"\u003eSET\u003c/code\u003e权限的用户才能更改此设置。\u003c/p\u003e\u003cp\u003e当\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-LOCK-WAITS\"\u003elog_lock_waits\u003c/a\u003e被设置时，这个参数也决定发出关于锁等待的日志之前等待的时间量。如果你想调查锁延迟，你可能希望设置一个比正常的\u003ccode class=\"varname\"\u003edeadlock_timeout\u003c/code\u003e小的值。\u003c/p\u003e","doc_same_as":""}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","7.4","8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
