{"Entry":{"collection":"guc","key":"temp_file_limit","name":"temp_file_limit","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Resource Usage / Disk","category_zh":"","changed_in":["9.6"],"changes":[{"documentation_changed":false,"fields":{},"from":"9.1","status":"added","to":"9.2"},{"documentation_changed":true,"fields":{},"from":"9.2","status":"changed","to":"9.3"},{"documentation_changed":true,"fields":{"short_desc":{"from":"Limits the total size of all temporary files used by each session.","to":"Limits the total size of all temporary files used by each process."}},"from":"9.5","status":"changed","to":"9.6"},{"documentation_changed":true,"fields":{},"from":"11","status":"changed","to":"12"},{"documentation_changed":true,"fields":{},"from":"14","status":"changed","to":"15"}],"content_hash":"740af72906ed7c1fe048412911ccf44486b7da224f84a5f886c13a8fcd0ace3a","context":"","default_changed_in":[],"default_history":[{"from":"9.2","to":"19","value":"-1 kB"}],"derived_content_hash":"dd4a347f2c824b9cd5022da0e2f6b2658f7fbac4c0d225353754b13edb0aeb37","editorial":{"advice":{"olap":"Allow a larger but still finite budget for known large joins and sorts, and coordinate it with query concurrency and parallelism. Test cancellation behavior before relying on the limit in production.","oltp":"Use a finite guardrail sized from filesystem headroom and worst-case concurrent spillers. Monitor temp_bytes and log_temp_files so the cap blocks pathological queries rather than routine bursts.","small":"Choose a modest fraction of the data filesystem and preserve emergency free space. Pair a lower limit with conservative work_mem and query timeouts."},"mechanism":["temp_file_limit limits the total instantaneous size of temporary files owned by one PostgreSQL process, including sort and hash spill files and storage for held cursors. Exceeding it cancels the transaction.","The limit is per process, not cluster-wide, so concurrent backends and parallel workers can collectively consume multiples of it. The default -1 means no limit.","Explicit temporary-table storage is excluded from this limit. log_temp_files and pg_stat_database.temp_bytes observe related temporary-file activity but do not change the enforcement boundary."],"pitfalls":["Treating a per-process limit as a cluster-wide disk cap.","Expecting it to constrain explicit temporary tables, which are excluded.","Leaving -1 on a filesystem where one runaway query can exhaust shared storage.","Setting the cap below normal spill sizes and discovering through transaction cancellations."],"references":[{"title":"PostgreSQL 19 Beta 4: temp_file_limit","url":"https://www.postgresql.org/docs/19/runtime-config-resource.html#GUC-TEMP-FILE-LIMIT"},{"title":"PostgreSQL 18: pg_stat_database temp_bytes","url":"https://www.postgresql.org/docs/18/monitoring-stats.html#MONITORING-PG-STAT-DATABASE-VIEW"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["work_mem","hash_mem_multiplier","log_temp_files","temp_tablespaces","max_parallel_workers_per_gather"],"summary":"A per-process safety limit on disk space consumed at one time by executor temporary files."},"enumvals":[],"first_version":"9.2","group":"Resource Usage","group_slug":"resource","imported_at":"2026-09-27T17:57:32.155966+08:00","intro_commit":{"authored_at":"2011-07-17T14:19:31-04:00","discussion":[],"hash":"23e5b16c71f2706978c5f54aabd28ed23a54b6a5","subject":"Add temp_file_limit GUC parameter to constrain temporary file space usage.","url":"https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=23e5b16c71f2706978c5f54aabd28ed23a54b6a5"},"key":"temp_file_limit","last_version":"20","max_val":"","min_val":"","name":"temp_file_limit","position":412,"present_in":["9.2","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:bc3e8ea4d4873adc63cbcf14719e1e5d7d3c9956565e6c7edf30f33e449b3144","receipt_sha256":"f86816030ff9ecda77e0a7f60273366b95ec37ddeb851f393986d1ea648e7465","repair":"wiki-repair-20261023"},"short_desc":"Specifies the maximum amount of disk space that a process can use for temporary files, such as sort and hash temporary files, or the storage file for a held cursor.","short_desc_zh":"","source_rev":"wiki-repair-20261023:8eb3fff5f02a4b1e76cdbf910a8fd43baa8e5a6832a35f745a6f9373f949d006","unit":"","vartype":"integer"}},"Definition":{"Collection":"guc","Key":"temp_file_limit","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"temp_file_limit","SourceRevision":"wiki-repair-20261023:8eb3fff5f02a4b1e76cdbf910a8fd43baa8e5a6832a35f745a6f9373f949d006","Facts":{"boot_val":"-1","category":"Resource Usage / Disk","context":"superuser","description":"Specifies the maximum amount of disk space that a process can use for temporary files, such as sort and hash temporary files, or the storage file for a held cursor. A transaction attempting to exceed this limit will be canceled. If this value is specified without units, it is taken as kilobytes. -1 (the default) means no limit. Only superusers and users with the appropriate SET privilege can change this setting. This setting constrains the total space used at any instant by all temporary files used by a given PostgreSQL process. It should be noted that disk space used for explicit temporary tables, as opposed to temporary files used behind-the-scenes in query execution, does not count against this limit.","description_zh":"指定一个进程可用于临时文件的最大磁盘空间，例如排序和 hash 临时文件，或保留游标的存储文件。尝试超过此限制的事务将被取消。如果未指定单位，则以千字节为单位。-1（默认值）表示没有限制。只有超级用户和具有适当 SET 权限的用户才能更改此设置。 此设置限制单个 PostgreSQL 进程在任意时刻使用的所有临时文件的总空间。需要注意，显式临时表所用的磁盘空间不计入该上限；计入的是查询执行过程中内部使用的临时文件。","description_zh_html":"\u003cp\u003e\n        指定一个进程可用于临时文件的最大磁盘空间，例如排序和 hash 临时文件，或保留游标的存储文件。尝试超过此限制的事务将被取消。如果未指定单位，则以千字节为单位。\u003ccode class=\"literal\"\u003e-1\u003c/code\u003e（默认值）表示没有限制。只有超级用户和具有适当 \u003ccode class=\"literal\"\u003eSET\u003c/code\u003e 权限的用户才能更改此设置。\n       \u003c/p\u003e\u003cp\u003e\n        此设置限制单个 \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 进程在任意时刻使用的所有临时文件的总空间。需要注意，显式临时表所用的磁盘空间\u003cspan class=\"emphasis\"\u003e\u003cem\u003e不\u003c/em\u003e\u003c/span\u003e计入该上限；计入的是查询执行过程中内部使用的临时文件。\n       \u003c/p\u003e","doc":{"anchor":"GUC-TEMP-FILE-LIMIT","file":"runtime-config-resource.html","lang":"en","sha256":"2e207c599f0884dfbe594558c478a2c7c132578981071e980e2015f31dfce28c","slug":"18"},"documented":true,"enumvals":null,"extra_desc":"-1 means no limit.","lang":"en","max_val":"2147483647","metadata_version":"18","min_val":"-1","name":"temp_file_limit","short_desc":"Limits the total size of all temporary files used by each process.","source":"pg-settings-source-snapshot","translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/runtime-config-resource.html","sha256":"f5fedbf88ec5f973aaf4e525c03e46dda2a2186dabee154e26780da96b2ac85a"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"unit":"kB","vartype":"integer","zh_from":"same-version-pgdoc"},"ManualEvidence":{"doc":{"anchor":"GUC-TEMP-FILE-LIMIT","file":"runtime-config-resource.html","lang":"en","sha256":"2e207c599f0884dfbe594558c478a2c7c132578981071e980e2015f31dfce28c","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"temp_file_limit","SourceDatabase":"center","Version":"18","Locale":"en","Title":"temp_file_limit","Summary":"Specifies the maximum amount of disk space that a process can use for temporary files, such as sort and hash temporary files, or the storage file for a held cursor. A transaction attempting to exceed this limit will be canceled. If this value is specified without units, it is taken as kilobytes. -1 (the default) means no limit. Only superusers and users with the appropriate SET privilege can change this setting. This setting constrains the total space used at any instant by all temporary files used by a given PostgreSQL process. It should be noted that disk space used for explicit temporary tables, as opposed to temporary files used behind-the-scenes in query execution, does not count against this limit.","BodyHTML":"\u003cp\u003eSpecifies the maximum amount of disk space that a process can use for temporary files, such as sort and hash temporary files, or the storage file for a held cursor. A transaction attempting to exceed this limit will be canceled. If this value is specified without units, it is taken as kilobytes. -1 (the default) means no limit. Only superusers and users with the appropriate SET privilege can change this setting. This setting constrains the total space used at any instant by all temporary files used by a given PostgreSQL process. It should be noted that disk space used for explicit temporary tables, as opposed to temporary files used behind-the-scenes in query execution, does not count against this limit.\u003c/p\u003e","SourceRevision":"wiki-repair-20261023:8eb3fff5f02a4b1e76cdbf910a8fd43baa8e5a6832a35f745a6f9373f949d006","ContentHash":"d9a5dd160f20474367db2f3a8e63198281e9da5c97ca741ea57bec779aa548b1","Payload":{"description":"Specifies the maximum amount of disk space that a process can use for temporary files, such as sort and hash temporary files, or the storage file for a held cursor. A transaction attempting to exceed this limit will be canceled. If this value is specified without units, it is taken as kilobytes. -1 (the default) means no limit. Only superusers and users with the appropriate SET privilege can change this setting. This setting constrains the total space used at any instant by all temporary files used by a given PostgreSQL process. It should be noted that disk space used for explicit temporary tables, as opposed to temporary files used behind-the-scenes in query execution, does not count against this limit."}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","9.2","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
