{"Entry":{"collection":"guc","key":"search_path","name":"search_path","aliases":[],"metadata":{"baseline":true,"boot_human":"Not specified","boot_val":null,"category":"Client Connection Defaults / Statement Behavior","category_zh":"","changed_in":["9.5"],"changes":[{"documentation_changed":true,"fields":{},"from":"8.0","status":"changed","to":"8.1"},{"documentation_changed":true,"fields":{},"from":"8.1","status":"changed","to":"8.2"},{"documentation_changed":true,"fields":{},"from":"8.4","status":"changed","to":"9.0"},{"documentation_changed":true,"fields":{},"from":"9.1","status":"changed","to":"9.2"},{"documentation_changed":true,"fields":{},"from":"9.2","status":"changed","to":"9.3"},{"documentation_changed":true,"fields":{},"from":"9.3","status":"changed","to":"9.4"},{"documentation_changed":true,"fields":{"boot_val":{"from":"\"$user\",public","to":"\"$user\", public"}},"from":"9.4","status":"changed","to":"9.5"},{"documentation_changed":true,"fields":{},"from":"11","status":"changed","to":"12"},{"documentation_changed":true,"fields":{},"from":"12","status":"changed","to":"13"},{"documentation_changed":true,"fields":{},"from":"14","status":"changed","to":"15"},{"documentation_changed":true,"fields":{},"from":"16","status":"changed","to":"17"},{"documentation_changed":true,"fields":{},"from":"18","status":"changed","to":"19"}],"content_hash":"145ad2e461e2005d6fc96b116552651dd7eed2a49159c680713e4170dbecc019","context":"","default_changed_in":["9.5"],"default_history":[{"from":"9.0","to":"9.4","value":"\"$user\",public"},{"from":"9.5","to":"19","value":"\"$user\", public"}],"editorial":{"advice":{"olap":"Use a dedicated analytical role if search_path must differ, and verify that exports, triggers, policies, and name resolution still preserve data correctness.","oltp":"Treat search_path as a correctness or security control, not a throughput knob. Grant SET authority narrowly and establish it from trusted role or application policy.","small":"Keep search_path at its safe default unless a documented repair or compatibility workflow requires otherwise; record and automatically restore temporary changes."},"mechanism":["search_path sets the schema search order for names that are not schema-qualified. It controls both lookup and the target schema for unqualified CREATE; pg_catalog and the temporary schema have special implicit search rules.","search_path 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.","Because session state can survive in pooled connections, role defaults, SET privilege, RESET behavior, and application checkout hooks are part of the control's effective boundary."],"pitfalls":["Changing search_path in one session and assuming role defaults, database defaults, or other pooled sessions changed with it.","Granting broad SET rights to a control that can change correctness, policy enforcement, or name resolution.","Failing to reset a security-sensitive session value before a pooled connection is reused by another request.","Placing a schema writable by an untrusted role before trusted schemas and enabling object-shadowing attacks."],"references":[{"title":"PostgreSQL 19 Beta 4: search_path","url":"https://www.postgresql.org/docs/19/runtime-config-client.html#GUC-SEARCH-PATH"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["row_security","session_replication_role","event_triggers","restrict_nonsystem_relation_kind","createrole_self_grant"],"summary":"search_path is the PostgreSQL setting that defines the schema search order for names that are not schema-qualified."},"enumvals":[],"first_version":"7.4","group":"Client Connection Defaults","group_slug":"client","imported_at":"2026-09-27T17:57:31.926463+08:00","intro_commit":{},"key":"search_path","last_version":"20","max_val":"","min_val":"","name":"search_path","position":346,"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 variable specifies the order in which schemas are searched when an object (table, data type, function, etc.) is referenced by a simple name with no schema specified.","short_desc_zh":"","source_rev":"english-manuals:82c59c3eac5889f57b143abafcf11e0b2eb6eff014da8a9c1d6d78ba6d75a464","unit":"","vartype":"string"}},"Definition":{"Collection":"guc","Key":"search_path","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"search_path","SourceRevision":"english-manuals:82c59c3eac5889f57b143abafcf11e0b2eb6eff014da8a9c1d6d78ba6d75a464","Facts":{"boot_val":"\"$user\", public","category":"Client Connection Defaults / Statement Behavior","context":"user","description":"This variable specifies the order in which schemas are searched when an object (table, data type, function, etc.) is referenced by a simple name with no schema specified. When there are objects of identical names in different schemas, the one found first in the search path is used. An object that is not in any of the schemas in the search path can only be referenced by specifying its containing schema with a qualified (dotted) name. The value for search_path must be a comma-separated list of schema names. Any name that is not an existing schema, or is a schema for which the user does not have USAGE permission, is silently ignored. If one of the list items is the special name $user, then the schema having the name returned by CURRENT_USER is substituted, if there is such a schema and the user has USAGE permission for it. (If not, $user is ignored.) The system catalog schema, pg_catalog, is always searched, whether it is mentioned in the path or not. If it is mentioned in the path then it will be searched in the specified order. If pg_catalog is not in the path then it will be searched before searching any of the path items. Likewise, the current session's temporary-table schema, pg_temp_nnn, is always searched if it exists. It can be explicitly listed in the path by using the alias pg_temp. If it is not listed in the path then it is searched first (even before pg_catalog). However, the temporary schema is only searched for relation (table, view, sequence, etc.) and data type names. It is never searched for function or operator names. When objects are created without specifying a particular target schema, they will be placed in the first valid schema named in search_path. An error is reported if the search path is empty. The default value for this parameter is \"$user\", public. This setting supports shared use of a database (where no users have private schemas, and all share use of public), private per-user schemas, and combinations of these. Other effects can be obtained by altering the default search path setting, either globally or per-user. For more information on schema handling, see Section 5.10. In particular, the default configuration is suitable only when the database has a single user or a few mutually-trusting users. The current effective value of the search path can be examined via the SQL function current_schemas (see Section 9.27). This is not quite the same as examining the value of search_path, since current_schemas shows how the items appearing in search_path were resolved.","doc":{"anchor":"GUC-SEARCH-PATH","file":"runtime-config-client.html","lang":"en","sha256":"6be6cc70f29eca4695dc43b2b2b94c75b7e0eaaa2c00273d7a98488917a7edb7","slug":"18"},"documented":true,"enumvals":null,"extra_desc":null,"lang":"en","max_val":null,"metadata_version":"18","min_val":null,"name":"search_path","short_desc":"Sets the schema search order for names that are not schema-qualified.","source":"pg-settings-source-snapshot","unit":null,"vartype":"string"},"ManualEvidence":{"doc":{"anchor":"GUC-SEARCH-PATH","file":"runtime-config-client.html","lang":"en","sha256":"6be6cc70f29eca4695dc43b2b2b94c75b7e0eaaa2c00273d7a98488917a7edb7","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"search_path","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"search_path","Summary":"","BodyHTML":"\u003cp\u003e这个变量指定当一个对象（表、数据类型、函数等）被用一个无模式限定的简单名称引用时，搜索该对象时的模式顺序。当在不同模式中有同名对象时，将使用第一个在搜索路径中被找到的对象。一个不属于搜索路径中任何一个模式的对象只能通过用限定名（带点号）指定包含它的模式来引用。\u003c/p\u003e\u003cp\u003e\u003ccode\u003esearch_path\u003c/code\u003e的值必须是一个逗号分隔的模式名列表。任何不是一个已有模式的名称，或者是一个用户不具有\u003ccode\u003eUSAGE\u003c/code\u003e权限的模式，将被静默忽略。\u003c/p\u003e\u003cp\u003e如果列表项之一是特殊名\u003ccode\u003e$user\u003c/code\u003e，则具有\u003ccode\u003eCURRENT_USER\u003c/code\u003e返回的名字的模式将取代它（如果有这样一个模式并且该用户有该模式的\u003ccode\u003eUSAGE\u003c/code\u003e权限；如果没有，\u003ccode\u003e$user\u003c/code\u003e会被忽略）。\u003c/p\u003e\u003cp\u003e系统目录模式\u003ccode\u003epg_catalog\u003c/code\u003e总是被搜索，不管它是否在搜索路径中被提及。如果它在路径中被提及，那么它将被按照路径指定的顺序搜索。如果\u003ccode\u003epg_catalog\u003c/code\u003e不在路径中，则它将在任何路径项\u003cspan\u003e\u003cem\u003e之前\u003c/em\u003e\u003c/span\u003e被搜索。\u003c/p\u003e\u003cp\u003e同样，如果存在，当前会话的临时表模式\u003ccode\u003epg_temp_\u003cem\u003e\u003ccode\u003ennn\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e总是被搜索。可以通过使用别名\u003ccode\u003epg_temp\u003c/code\u003e在路径中显式列出它。如果它没有列在路径中，则首先搜索它（甚至在\u003ccode\u003epg_catalog\u003c/code\u003e之前）。然而，临时模式仅用于搜索关系（表、视图、序列等）和数据类型名称。它永远不会用于搜索函数或操作符名称。\u003c/p\u003e\u003cp\u003e当对象创建时没有指定一个特定目标模式，它们将被放置在\u003ccode\u003esearch_path\u003c/code\u003e中第一个合法模式中。如果搜索路径为空将报告一个错误。\u003c/p\u003e\u003cp\u003e这个参数的默认值是\u003ccode\u003e\u0026#34;$user\u0026#34;, public\u003c/code\u003e。这种设置支持共享使用数据库（用户没有私有模式，所有人共享使用\u003ccode\u003epublic\u003c/code\u003e）、每个用户拥有私有模式，以及二者的组合。还可以通过全局或针对每个用户修改默认搜索路径设置来获得其他效果。\u003c/p\u003e\u003cp\u003e更多有关模式处理的信息，请参考\u003ca href=\"/docs/18/ddl-schemas.html\" rel=\"nofollow\"\u003e第 5.10 节\u003c/a\u003e。特别地，只有当数据库只有一个用户或者有少数的相互信任的用户时，默认配置是合适的。\u003c/p\u003e\u003cp\u003e搜索路径的当前有效值可以通过SQL函数\u003ccode\u003ecurrent_schemas\u003c/code\u003e检查（见\u003ca href=\"/docs/18/functions-info.html\" rel=\"nofollow\"\u003e第 9.27 节\u003c/a\u003e）。它和检查\u003ccode\u003esearch_path\u003c/code\u003e的值不太一样，因为\u003ccode\u003ecurrent_schemas\u003c/code\u003e显示出现在\u003ccode\u003esearch_path\u003c/code\u003e中的项如何被解析。\u003c/p\u003e","SourceRevision":"2026-09-11@29c86d9","ContentHash":"1a185fbe34c4f6eaae730f0a8314b2665abdf103bdf65359f2f2789fe3913189","Payload":{"carried_from":"","carry_reason":"","doc_html":"\u003cp\u003e这个变量指定当一个对象（表、数据类型、函数等）被用一个无模式限定的简单名称引用时，搜索该对象时的模式顺序。当在不同模式中有同名对象时，将使用第一个在搜索路径中被找到的对象。一个不属于搜索路径中任何一个模式的对象只能通过用限定名（带点号）指定包含它的模式来引用。\u003c/p\u003e\u003cp\u003e\u003ccode class=\"varname\"\u003esearch_path\u003c/code\u003e的值必须是一个逗号分隔的模式名列表。任何不是一个已有模式的名称，或者是一个用户不具有\u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e权限的模式，将被静默忽略。\u003c/p\u003e\u003cp\u003e如果列表项之一是特殊名\u003ccode class=\"literal\"\u003e$user\u003c/code\u003e，则具有\u003ccode class=\"function\"\u003eCURRENT_USER\u003c/code\u003e返回的名字的模式将取代它（如果有这样一个模式并且该用户有该模式的\u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e权限；如果没有，\u003ccode class=\"literal\"\u003e$user\u003c/code\u003e会被忽略）。\u003c/p\u003e\u003cp\u003e系统目录模式\u003ccode class=\"literal\"\u003epg_catalog\u003c/code\u003e总是被搜索，不管它是否在搜索路径中被提及。如果它在路径中被提及，那么它将被按照路径指定的顺序搜索。如果\u003ccode class=\"literal\"\u003epg_catalog\u003c/code\u003e不在路径中，则它将在任何路径项\u003cspan class=\"emphasis\"\u003e\u003cem\u003e之前\u003c/em\u003e\u003c/span\u003e被搜索。\u003c/p\u003e\u003cp\u003e同样，如果存在，当前会话的临时表模式\u003ccode class=\"literal\"\u003epg_temp_\u003cem\u003e\u003ccode\u003ennn\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e总是被搜索。可以通过使用别名\u003ccode class=\"literal\"\u003epg_temp\u003c/code\u003e在路径中显式列出它。如果它没有列在路径中，则首先搜索它（甚至在\u003ccode class=\"literal\"\u003epg_catalog\u003c/code\u003e之前）。然而，临时模式仅用于搜索关系（表、视图、序列等）和数据类型名称。它永远不会用于搜索函数或操作符名称。\u003c/p\u003e\u003cp\u003e当对象创建时没有指定一个特定目标模式，它们将被放置在\u003ccode class=\"varname\"\u003esearch_path\u003c/code\u003e中第一个合法模式中。如果搜索路径为空将报告一个错误。\u003c/p\u003e\u003cp\u003e这个参数的默认值是\u003ccode class=\"literal\"\u003e\"$user\", public\u003c/code\u003e。这种设置支持共享使用数据库（用户没有私有模式，所有人共享使用\u003ccode class=\"literal\"\u003epublic\u003c/code\u003e）、每个用户拥有私有模式，以及二者的组合。还可以通过全局或针对每个用户修改默认搜索路径设置来获得其他效果。\u003c/p\u003e\u003cp\u003e更多有关模式处理的信息，请参考\u003ca href=\"/docs/18/ddl-schemas.html\" title=\"5.10. 模式\"\u003e第 5.10 节\u003c/a\u003e。特别地，只有当数据库只有一个用户或者有少数的相互信任的用户时，默认配置是合适的。\u003c/p\u003e\u003cp\u003e搜索路径的当前有效值可以通过SQL函数\u003ccode class=\"function\"\u003ecurrent_schemas\u003c/code\u003e检查（见\u003ca href=\"/docs/18/functions-info.html\" title=\"9.27. 系统信息函数和操作符\"\u003e第 9.27 节\u003c/a\u003e）。它和检查\u003ccode class=\"varname\"\u003esearch_path\u003c/code\u003e的值不太一样，因为\u003ccode class=\"function\"\u003ecurrent_schemas\u003c/code\u003e显示出现在\u003ccode class=\"varname\"\u003esearch_path\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}
