{"Entry":{"collection":"guc","key":"lock_timeout","name":"lock_timeout","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Client Connection Defaults / Statement Behavior","category_zh":"","changed_in":["18"],"changes":[{"documentation_changed":false,"fields":{},"from":"9.2","status":"added","to":"9.3"},{"documentation_changed":true,"fields":{},"from":"9.3","status":"changed","to":"9.4"},{"documentation_changed":true,"fields":{},"from":"11","status":"changed","to":"12"},{"documentation_changed":false,"fields":{"extra_desc":{"from":"A value of 0 turns off the timeout.","to":"0 disables the timeout."}},"from":"17","status":"changed","to":"18"}],"content_hash":"7a2eefa626240e9df2bf2e7ceb11d6d28e7c3cfda776d94e59785761f07396b3","context":"","default_changed_in":[],"default_history":[{"from":"9.3","to":"19","value":"0 ms"}],"derived_content_hash":"6b924e833b6e554ebaf2635a668e6d4d7c61a12530c0f4f93b11e790f522f9d0","editorial":{"advice":{"olap":"Analytical work usually needs a larger or job-specific lock_timeout; preserve a finite guardrail for abandoned work without killing legitimate long scans.","oltp":"Set lock_timeout from the service latency and failure budget, preferably per role or application. Test retries and cancellation paths before enforcing a cluster-wide value.","small":"Use a conservative finite lock_timeout only when the client or operating system handles termination correctly; verify that maintenance still has a dedicated exception."},"mechanism":["lock_timeout sets the maximum allowed duration of any wait for a lock. 0 disables the timeout. The timer applies separately to each lock acquisition, not to total statement runtime; a statement_timeout at the same or lower value will fire first.","lock_timeout is a USER-context setting. An authorized role can change it for a session, while ALTER ROLE or ALTER DATABASE can establish a default for future sessions.","Timeouts overlap: the first applicable deadline wins, while client, pooler, TCP, and server cancellation behavior determines whether work is retried, canceled, or the session is closed."],"pitfalls":["Changing lock_timeout in one session and assuming role defaults, database defaults, or other pooled sessions changed with it.","Forgetting that zero usually disables the timeout or delegates behavior to the operating system.","Setting overlapping deadlines without deciding which layer owns retries, cancellation, and connection disposal.","Changing lock_timeout globally without a rollback plan and a client or operational compatibility test."],"references":[{"title":"PostgreSQL 19 Beta 4: lock_timeout","url":"https://www.postgresql.org/docs/19/runtime-config-client.html#GUC-LOCK-TIMEOUT"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["statement_timeout","transaction_timeout","idle_in_transaction_session_timeout","idle_session_timeout","deadlock_timeout"],"summary":"lock_timeout is the PostgreSQL setting that defines the maximum allowed duration of any wait for a lock."},"enumvals":[],"first_version":"9.3","group":"Client Connection Defaults","group_slug":"client","imported_at":"2026-09-27T17:57:31.503079+08:00","intro_commit":{"authored_at":"2013-03-16T23:22:17-04:00","discussion":[],"hash":"d43837d03067487560af481474ae985df894f786","subject":"Add lock_timeout configuration parameter.","url":"https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=d43837d03067487560af481474ae985df894f786"},"key":"lock_timeout","last_version":"20","max_val":"","min_val":"","name":"lock_timeout","position":215,"present_in":["9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"repair_provenance":{"original_source_revision":"english-manuals:a799d789f6b2e692fa329fba690107e7393058bca3ea6e7d477ce276da6f5fe3","receipt_sha256":"ab987d58f069d96272f64f64a6af52a740b6d2a965816b092fe81bb23b2e2783","repair":"wiki-repair-20261023"},"short_desc":"Abort any statement that waits longer than the specified amount of time while attempting to acquire a lock on a table, index, row, or other database object.","short_desc_zh":"","source_rev":"wiki-repair-20261023:06c177e23971c3691ec60d60e8d269273ca2a47909006ccb01d8d27c1f1ff3ea","unit":"","vartype":"integer"}},"Definition":{"Collection":"guc","Key":"lock_timeout","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"lock_timeout","SourceRevision":"wiki-repair-20261023:06c177e23971c3691ec60d60e8d269273ca2a47909006ccb01d8d27c1f1ff3ea","Facts":{"boot_val":"0","category":"Client Connection Defaults / Statement Behavior","context":"user","description":"Abort any statement that waits longer than the specified amount of time while attempting to acquire a lock on a table, index, row, or other database object. The time limit applies separately to each lock acquisition attempt. The limit applies both to explicit locking requests (such as LOCK TABLE, or SELECT FOR UPDATE without NOWAIT) and to implicitly-acquired locks. If this value is specified without units, it is taken as milliseconds. A value of zero (the default) disables the timeout. Unlike statement_timeout, this timeout can only occur while waiting for locks. Note that if statement_timeout is nonzero, it is rather pointless to set lock_timeout to the same or larger value, since the statement timeout would always trigger first. If log_min_error_statement is set to ERROR or lower, the statement that timed out will be logged. Setting lock_timeout in postgresql.conf is not recommended because it would affect all sessions.","description_zh":"如果任何语句在试图获取表、索引、行或其他数据库对象上的锁时等待超过指定的时间量，该语句将被中止。该时间限制独立地应用于每一次锁获取尝试。该限制会应用到显式锁定请求（如 LOCK TABLE 或不带 NOWAIT 的 SELECT FOR UPDATE）和隐式获得的锁。如果指定值时没有单位，则以毫秒为单位。一个零值（默认）将禁用超时。 与 statement_timeout 不同，这个超时只在等待锁时发生。注意如果 statement_timeout 为非零，设置 lock_timeout 为相同或更大的值没有意义，因为语句超时将总是第一个被触发。如果 log_min_error_statement 被设置为 ERROR 或更低，超时的语句将被记录。 我们不推荐在 postgresql.conf 中设置 lock_timeout，因为它会影响所有会话。","description_zh_html":"\u003cp\u003e\n        如果任何语句在试图获取表、索引、行或其他数据库对象上的锁时等待超过指定的时间量，该语句将被中止。该时间限制独立地应用于每一次锁获取尝试。该限制会应用到显式锁定请求（如 \u003ccode class=\"command\"\u003eLOCK TABLE\u003c/code\u003e 或不带 \u003ccode class=\"literal\"\u003eNOWAIT\u003c/code\u003e 的 \u003ccode class=\"command\"\u003eSELECT FOR UPDATE\u003c/code\u003e）和隐式获得的锁。如果指定值时没有单位，则以毫秒为单位。一个零值（默认）将禁用超时。\n       \u003c/p\u003e\u003cp\u003e\n        与 \u003ccode class=\"varname\"\u003estatement_timeout\u003c/code\u003e 不同，这个超时只在等待锁时发生。注意如果 \u003ccode class=\"varname\"\u003estatement_timeout\u003c/code\u003e 为非零，设置 \u003ccode class=\"varname\"\u003elock_timeout\u003c/code\u003e 为相同或更大的值没有意义，因为语句超时将总是第一个被触发。如果 \u003ccode class=\"varname\"\u003elog_min_error_statement\u003c/code\u003e 被设置为 \u003ccode class=\"literal\"\u003eERROR\u003c/code\u003e 或更低，超时的语句将被记录。\n       \u003c/p\u003e\u003cp\u003e\n        我们不推荐在 \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e 中设置 \u003ccode class=\"varname\"\u003elock_timeout\u003c/code\u003e，因为它会影响所有会话。\n       \u003c/p\u003e","doc":{"anchor":"GUC-LOCK-TIMEOUT","file":"runtime-config-client.html","lang":"en","sha256":"6be6cc70f29eca4695dc43b2b2b94c75b7e0eaaa2c00273d7a98488917a7edb7","slug":"18"},"documented":true,"enumvals":null,"extra_desc":"0 disables the timeout.","lang":"en","max_val":"2147483647","metadata_version":"18","min_val":"0","name":"lock_timeout","short_desc":"Sets the maximum allowed duration of any wait for a lock.","source":"pg-settings-source-snapshot","translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/runtime-config-client.html","sha256":"1882f8fd5576909c4fcc44af53077378871e05f5be67723f20fe300273024767"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"unit":"ms","vartype":"integer","zh_from":"same-version-pgdoc"},"ManualEvidence":{"doc":{"anchor":"GUC-LOCK-TIMEOUT","file":"runtime-config-client.html","lang":"en","sha256":"6be6cc70f29eca4695dc43b2b2b94c75b7e0eaaa2c00273d7a98488917a7edb7","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"lock_timeout","SourceDatabase":"center","Version":"18","Locale":"en","Title":"lock_timeout","Summary":"Abort any statement that waits longer than the specified amount of time while attempting to acquire a lock on a table, index, row, or other database object. The time limit applies separately to each lock acquisition attempt. The limit applies both to explicit locking requests (such as LOCK TABLE, or SELECT FOR UPDATE without NOWAIT) and to implicitly-acquired locks. If this value is specified without units, it is taken as milliseconds. A value of zero (the default) disables the timeout. Unlike statement_timeout, this timeout can only occur while waiting for locks. Note that if statement_timeout is nonzero, it is rather pointless to set lock_timeout to the same or larger value, since the statement timeout would always trigger first. If log_min_error_statement is set to ERROR or lower, the statement that timed out will be logged. Setting lock_timeout in postgresql.conf is not recommended because it would affect all sessions.","BodyHTML":"\u003cp\u003eAbort any statement that waits longer than the specified amount of time while attempting to acquire a lock on a table, index, row, or other database object. The time limit applies separately to each lock acquisition attempt. The limit applies both to explicit locking requests (such as LOCK TABLE, or SELECT FOR UPDATE without NOWAIT) and to implicitly-acquired locks. If this value is specified without units, it is taken as milliseconds. A value of zero (the default) disables the timeout. Unlike statement_timeout, this timeout can only occur while waiting for locks. Note that if statement_timeout is nonzero, it is rather pointless to set lock_timeout to the same or larger value, since the statement timeout would always trigger first. If log_min_error_statement is set to ERROR or lower, the statement that timed out will be logged. Setting lock_timeout in postgresql.conf is not recommended because it would affect all sessions.\u003c/p\u003e","SourceRevision":"wiki-repair-20261023:06c177e23971c3691ec60d60e8d269273ca2a47909006ccb01d8d27c1f1ff3ea","ContentHash":"90c22b489a495328ba570fd9c06408257dac75aa149e7d690b8de500f3e200fa","Payload":{"description":"Abort any statement that waits longer than the specified amount of time while attempting to acquire a lock on a table, index, row, or other database object. The time limit applies separately to each lock acquisition attempt. The limit applies both to explicit locking requests (such as LOCK TABLE, or SELECT FOR UPDATE without NOWAIT) and to implicitly-acquired locks. If this value is specified without units, it is taken as milliseconds. A value of zero (the default) disables the timeout. Unlike statement_timeout, this timeout can only occur while waiting for locks. Note that if statement_timeout is nonzero, it is rather pointless to set lock_timeout to the same or larger value, since the statement timeout would always trigger first. If log_min_error_statement is set to ERROR or lower, the statement that timed out will be logged. Setting lock_timeout in postgresql.conf is not recommended because it would affect all sessions."}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
