{"Entry":{"collection":"guc","key":"maintenance_work_mem","name":"maintenance_work_mem","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Resource Usage / Memory","category_zh":"","changed_in":["9.4","17"],"changes":[{"documentation_changed":false,"fields":{},"from":"7.4","status":"added","to":"8.0"},{"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":true,"fields":{"boot_val":{"from":"16384","to":"65536"}},"from":"9.3","status":"changed","to":"9.4"},{"documentation_changed":true,"fields":{},"from":"9.5","status":"changed","to":"9.6"},{"documentation_changed":true,"fields":{},"from":"11","status":"changed","to":"12"},{"documentation_changed":true,"fields":{"min_val":{"from":"1024","to":"64"}},"from":"16","status":"changed","to":"17"}],"content_hash":"a10feed817ea6a323a20b27147dc0f9938ab3dd66bfe5575d986f6de3071050a","context":"","default_changed_in":["9.4"],"default_history":[{"from":"9.0","to":"9.3","value":"16 MiB"},{"from":"9.4","to":"19","value":"64 MiB"}],"editorial":{"advice":{"olap":"Larger values are often useful for index builds, vacuuming large relations, and restores. Schedule heavy maintenance and verify that concurrent maintenance, query memory, and the OS still fit together.","oltp":"Use enough memory to keep routine vacuum and index work efficient, but budget explicitly for simultaneous autovacuum workers. If interactive latency matters and maintenance_work_mem is large, give autovacuum_work_mem its own lower ceiling.","small":"Keep the global value modest and temporarily raise it only for controlled maintenance sessions. Check autovacuum inheritance before increasing it."},"mechanism":["maintenance_work_mem applies to maintenance operations including VACUUM, CREATE INDEX, and ALTER TABLE ADD FOREIGN KEY. Because a session normally runs only one such operation at a time, it can usually be set higher than work_mem.","For parallel utility commands, PostgreSQL treats maintenance_work_mem as a limit for the entire utility command rather than granting the full amount to every parallel maintenance worker. CPU and I/O consumption can still rise with parallelism.","Autovacuum is a separate concurrency concern: when autovacuum_work_mem is -1, each autovacuum worker inherits maintenance_work_mem, so several workers can make the aggregate budget much larger than the single-operation value."],"pitfalls":["Assuming the value is harmless because maintenance is infrequent while leaving autovacuum_work_mem at -1.","Multiplying the limit by parallel maintenance workers; PostgreSQL applies it to the utility command as a whole.","Using a permanently large cluster-wide value for a one-off restore instead of a scoped SET.","Expecting more memory alone to solve maintenance dominated by locks or storage I/O."],"references":[{"title":"PostgreSQL 19 Beta 4: maintenance_work_mem","url":"https://www.postgresql.org/docs/19/runtime-config-resource.html#GUC-MAINTENANCE-WORK-MEM"},{"title":"PostgreSQL 18: Routine Vacuuming","url":"https://www.postgresql.org/docs/18/routine-vacuuming.html#AUTOVACUUM"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["autovacuum_work_mem","autovacuum_max_workers","max_parallel_maintenance_workers","vacuum_buffer_usage_limit","work_mem"],"summary":"The memory ceiling for maintenance commands such as VACUUM, CREATE INDEX, and adding foreign-key constraints."},"enumvals":[],"first_version":"8.0","group":"Resource Usage","group_slug":"resource","imported_at":"2026-09-27T17:57:31.666777+08:00","intro_commit":{},"key":"maintenance_work_mem","last_version":"20","max_val":"","min_val":"","name":"maintenance_work_mem","position":260,"present_in":["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":"Specifies the maximum amount of memory to be used by maintenance operations, such as VACUUM, CREATE INDEX, and ALTER TABLE ADD FOREIGN KEY.","short_desc_zh":"","source_rev":"english-manuals:c60d10b692ff522f054d443f97eedbc54d5118a9eeae63c8be471ec7ca053a65","unit":"","vartype":"integer"}},"Definition":{"Collection":"guc","Key":"maintenance_work_mem","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"maintenance_work_mem","SourceRevision":"english-manuals:c60d10b692ff522f054d443f97eedbc54d5118a9eeae63c8be471ec7ca053a65","Facts":{"boot_val":"65536","category":"Resource Usage / Memory","context":"user","description":"Specifies the maximum amount of memory to be used by maintenance operations, such as VACUUM, CREATE INDEX, and ALTER TABLE ADD FOREIGN KEY. If this value is specified without units, it is taken as kilobytes. It defaults to 64 megabytes (64MB). Since only one of these operations can be executed at a time by a database session, and an installation normally doesn't have many of them running concurrently, it's safe to set this value significantly larger than work_mem. Larger settings might improve performance for vacuuming and for restoring database dumps. Note that when autovacuum runs, up to autovacuum_max_workers times this memory may be allocated, so be careful not to set the default value too high. It may be useful to control for this by separately setting autovacuum_work_mem.","doc":{"anchor":"GUC-MAINTENANCE-WORK-MEM","file":"runtime-config-resource.html","lang":"en","sha256":"2e207c599f0884dfbe594558c478a2c7c132578981071e980e2015f31dfce28c","slug":"18"},"documented":true,"enumvals":null,"extra_desc":"This includes operations such as VACUUM and CREATE INDEX.","lang":"en","max_val":"2147483647","metadata_version":"18","min_val":"64","name":"maintenance_work_mem","short_desc":"Sets the maximum memory to be used for maintenance operations.","source":"pg-settings-source-snapshot","unit":"kB","vartype":"integer"},"ManualEvidence":{"doc":{"anchor":"GUC-MAINTENANCE-WORK-MEM","file":"runtime-config-resource.html","lang":"en","sha256":"2e207c599f0884dfbe594558c478a2c7c132578981071e980e2015f31dfce28c","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"maintenance_work_mem","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"maintenance_work_mem","Summary":"","BodyHTML":"\u003cp\u003e指定维护操作（如 \u003ccode\u003eVACUUM\u003c/code\u003e、\u003ccode\u003eCREATE INDEX\u003c/code\u003e 和 \u003ccode\u003eALTER TABLE ADD FOREIGN KEY\u003c/code\u003e）可使用的最大内存量。如果未指定单位，则以千字节为单位。默认值为 64 兆字节（\u003ccode\u003e64MB\u003c/code\u003e）。由于一个数据库会话一次只能执行一个此类操作，而一个数据库系统通常也不会并发运行很多此类操作，因此可以安全地将该值设得远大于 \u003ccode\u003ework_mem\u003c/code\u003e。更大的设置可能改善清理和恢复数据库转储的性能。\u003c/p\u003e\u003cp\u003e注意，自动清理运行时，最多可能分配此内存量的\u003ca href=\"/docs/18/runtime-config-vacuum.html#GUC-AUTOVACUUM-MAX-WORKERS\" rel=\"nofollow\"\u003eautovacuum_max_workers\u003c/a\u003e倍，因此不要将默认值设得过高。单独设置\u003ca href=\"/docs/18/runtime-config-resource.html#GUC-AUTOVACUUM-WORK-MEM\" rel=\"nofollow\"\u003eautovacuum_work_mem\u003c/a\u003e可能有助于控制这一点。\u003c/p\u003e","SourceRevision":"2026-09-11@29c86d9","ContentHash":"d29a56ef075ce9035fab9dedd569662d59903eeeeb1bbfa6efed30bef25c0035","Payload":{"carried_from":"","carry_reason":"","doc_html":"\u003cp\u003e指定维护操作（如 \u003ccode class=\"command\"\u003eVACUUM\u003c/code\u003e、\u003ccode class=\"command\"\u003eCREATE INDEX\u003c/code\u003e 和 \u003ccode class=\"command\"\u003eALTER TABLE ADD FOREIGN KEY\u003c/code\u003e）可使用的最大内存量。如果未指定单位，则以千字节为单位。默认值为 64 兆字节（\u003ccode class=\"literal\"\u003e64MB\u003c/code\u003e）。由于一个数据库会话一次只能执行一个此类操作，而一个数据库系统通常也不会并发运行很多此类操作，因此可以安全地将该值设得远大于 \u003ccode class=\"varname\"\u003ework_mem\u003c/code\u003e。更大的设置可能改善清理和恢复数据库转储的性能。\u003c/p\u003e\u003cp\u003e注意，自动清理运行时，最多可能分配此内存量的\u003ca href=\"/docs/18/runtime-config-vacuum.html#GUC-AUTOVACUUM-MAX-WORKERS\"\u003eautovacuum_max_workers\u003c/a\u003e倍，因此不要将默认值设得过高。单独设置\u003ca href=\"/docs/18/runtime-config-resource.html#GUC-AUTOVACUUM-WORK-MEM\"\u003eautovacuum_work_mem\u003c/a\u003e可能有助于控制这一点。\u003c/p\u003e","doc_same_as":""}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","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}
