{"Entry":{"collection":"guc","key":"temp_tablespaces","name":"temp_tablespaces","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":"8.2","status":"added","to":"8.3"},{"documentation_changed":true,"fields":{},"from":"8.4","status":"changed","to":"9.0"},{"documentation_changed":false,"fields":{"extra_desc":{"from":null,"to":"An empty string means use the database's default tablespace."}},"from":"17","status":"changed","to":"18"}],"content_hash":"78e78603de7d55fd40228c92e3238eb7c4e1afb1f12a83646f2376e2a2bdb2bc","context":"","default_changed_in":[],"default_history":[{"from":"9.0","to":"19","value":"Empty string"}],"editorial":{"advice":{"olap":"Use temp_tablespaces deliberately for bulk objects and spill-heavy jobs, checking I/O placement, compression support, and operational tooling before adoption.","oltp":"Keep temp_tablespaces aligned with schema-management policy and make important storage choices explicit in migrations. Benchmark any physical-layout change with production-shaped writes.","small":"Prefer the upstream default for temp_tablespaces unless the node has a verified alternate storage path or restore requirement; simplicity reduces recovery surprises."},"mechanism":["temp_tablespaces sets the tablespace(s) to use for temporary tables and sort files. An empty string means use the database's default tablespace. PostgreSQL uses the list for temporary relations and executor spill files, choosing among multiple entries to distribute work; permissions and existence are checked by context.","temp_tablespaces 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.","It supplies a default only when SQL omits an explicit choice, so schema migrations, object-level options, privileges, and later ALTER operations can override or outlive it."],"pitfalls":["Changing temp_tablespaces in one session and assuming role defaults, database defaults, or other pooled sessions changed with it.","Expecting a changed default to rewrite existing objects or override explicit DDL clauses.","Ignoring tablespace privileges, installed access methods or compression support, and restore portability.","Changing temp_tablespaces globally without a rollback plan and a client or operational compatibility test."],"references":[{"title":"PostgreSQL 19 Beta 4: temp_tablespaces","url":"https://www.postgresql.org/docs/19/runtime-config-client.html#GUC-TEMP-TABLESPACES"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["default_table_access_method","default_tablespace","default_toast_compression","check_function_bodies","maintenance_work_mem"],"summary":"temp_tablespaces is the PostgreSQL setting that defines the tablespace(s) to use for temporary tables and sort files."},"enumvals":[],"first_version":"8.3","group":"Client Connection Defaults","group_slug":"client","imported_at":"2026-09-27T17:57:32.160052+08:00","intro_commit":{},"key":"temp_tablespaces","last_version":"20","max_val":"","min_val":"","name":"temp_tablespaces","position":413,"present_in":["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 variable specifies tablespaces in which to create temporary objects (temp tables and indexes on temp tables) when a CREATE command does not explicitly specify a tablespace.","short_desc_zh":"","source_rev":"english-manuals:e91d300ab77c08bdbda71e23c6ec1a148a9905c2a4c0dff214acb7e7f86c0059","unit":"","vartype":"string"}},"Definition":{"Collection":"guc","Key":"temp_tablespaces","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"temp_tablespaces","SourceRevision":"english-manuals:e91d300ab77c08bdbda71e23c6ec1a148a9905c2a4c0dff214acb7e7f86c0059","Facts":{"boot_val":"","category":"Client Connection Defaults / Statement Behavior","context":"user","description":"This variable specifies tablespaces in which to create temporary objects (temp tables and indexes on temp tables) when a CREATE command does not explicitly specify a tablespace. Temporary files for purposes such as sorting large data sets are also created in these tablespaces. The value is a list of names of tablespaces. When there is more than one name in the list, PostgreSQL chooses a random member of the list each time a temporary object is to be created; except that within a transaction, successively created temporary objects are placed in successive tablespaces from the list. If the selected element of the list is an empty string, PostgreSQL will automatically use the default tablespace of the current database instead. When temp_tablespaces is set interactively, specifying a nonexistent tablespace is an error, as is specifying a tablespace for which the user does not have CREATE privilege. However, when using a previously set value, nonexistent tablespaces are ignored, as are tablespaces for which the user lacks CREATE privilege. In particular, this rule applies when using a value set in postgresql.conf. The default value is an empty string, which results in all temporary objects being created in the default tablespace of the current database. See also default_tablespace.","doc":{"anchor":"GUC-TEMP-TABLESPACES","file":"runtime-config-client.html","lang":"en","sha256":"6be6cc70f29eca4695dc43b2b2b94c75b7e0eaaa2c00273d7a98488917a7edb7","slug":"18"},"documented":true,"enumvals":null,"extra_desc":"An empty string means use the database's default tablespace.","lang":"en","max_val":null,"metadata_version":"18","min_val":null,"name":"temp_tablespaces","short_desc":"Sets the tablespace(s) to use for temporary tables and sort files.","source":"pg-settings-source-snapshot","unit":null,"vartype":"string"},"ManualEvidence":{"doc":{"anchor":"GUC-TEMP-TABLESPACES","file":"runtime-config-client.html","lang":"en","sha256":"6be6cc70f29eca4695dc43b2b2b94c75b7e0eaaa2c00273d7a98488917a7edb7","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"temp_tablespaces","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"temp_tablespaces","Summary":"","BodyHTML":"\u003cp\u003e这个变量指定当一个\u003ccode\u003eCREATE\u003c/code\u003e命令没有显式指定一个表空间时，创建临时对象（临时表和临时表上的索引）的默认表空间。用于排序大型数据集的临时文件也被创建在这些表空间中。\u003c/p\u003e\u003cp\u003e该值是一个表空间名字的列表。当列表中有多于一个名称时，每次一个临时对象被创建时\u003cspan\u003ePostgreSQL\u003c/span\u003e随机选择列表中的一个成员。例外是在一个事务中，连续创建的临时对象被依次放置在列表中的连续表空间中。如果列表中被选中的元素是一个空字符串，\u003cspan\u003ePostgreSQL\u003c/span\u003e将自动使用当前数据库的默认表空间。\u003c/p\u003e\u003cp\u003e当\u003ccode\u003etemp_tablespaces\u003c/code\u003e被交互式地设置时，指定一个不存在的表空间是一种错误，指定一个用户不具有\u003ccode\u003eCREATE\u003c/code\u003e权限的表空间也同样是错误。不过，当使用一个之前设置的值时，不存在的表空间会被忽略，就像用户缺少\u003ccode\u003eCREATE\u003c/code\u003e权限的表空间一样。特别是，使用一个在\u003ccode\u003epostgresql.conf\u003c/code\u003e中设置的值时，这条规则起效。\u003c/p\u003e\u003cp\u003e默认值是一个空字符串，它使得所有临时对象被创建在当前数据库的默认表空间中。\u003c/p\u003e\u003cp\u003e参阅\u003ca href=\"/docs/18/runtime-config-client.html#GUC-DEFAULT-TABLESPACE\" rel=\"nofollow\"\u003edefault_tablespace\u003c/a\u003e。\u003c/p\u003e","SourceRevision":"2026-09-11@29c86d9","ContentHash":"b7afd1ee4ccbfd01d0a6434cdab84ce10ac31e3a5094cef577762566b785b46a","Payload":{"carried_from":"","carry_reason":"","doc_html":"\u003cp\u003e这个变量指定当一个\u003ccode class=\"command\"\u003eCREATE\u003c/code\u003e命令没有显式指定一个表空间时，创建临时对象（临时表和临时表上的索引）的默认表空间。用于排序大型数据集的临时文件也被创建在这些表空间中。\u003c/p\u003e\u003cp\u003e该值是一个表空间名字的列表。当列表中有多于一个名称时，每次一个临时对象被创建时\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e随机选择列表中的一个成员。例外是在一个事务中，连续创建的临时对象被依次放置在列表中的连续表空间中。如果列表中被选中的元素是一个空字符串，\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e将自动使用当前数据库的默认表空间。\u003c/p\u003e\u003cp\u003e当\u003ccode class=\"varname\"\u003etemp_tablespaces\u003c/code\u003e被交互式地设置时，指定一个不存在的表空间是一种错误，指定一个用户不具有\u003ccode class=\"literal\"\u003eCREATE\u003c/code\u003e权限的表空间也同样是错误。不过，当使用一个之前设置的值时，不存在的表空间会被忽略，就像用户缺少\u003ccode class=\"literal\"\u003eCREATE\u003c/code\u003e权限的表空间一样。特别是，使用一个在\u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e中设置的值时，这条规则起效。\u003c/p\u003e\u003cp\u003e默认值是一个空字符串，它使得所有临时对象被创建在当前数据库的默认表空间中。\u003c/p\u003e\u003cp\u003e参阅\u003ca href=\"/docs/18/runtime-config-client.html#GUC-DEFAULT-TABLESPACE\"\u003edefault_tablespace\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.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}
