{"Entry":{"collection":"guc","key":"session_replication_role","name":"session_replication_role","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Client Connection Defaults / Statement Behavior","category_zh":"","changed_in":[],"changes":[{"documentation_changed":false,"fields":{},"from":"8.2","status":"added","to":"8.3"},{"documentation_changed":true,"fields":{},"from":"10","status":"changed","to":"11"},{"documentation_changed":true,"fields":{},"from":"14","status":"changed","to":"15"}],"content_hash":"75feed1f4b99de24c5b1433157dfc5c2454fd3a2c7a132a67242085a1d5108dc","context":"","default_changed_in":[],"default_history":[{"from":"9.0","to":"19","value":"origin"}],"editorial":{"advice":{"olap":"Keep origin for analytical sessions; suppressing triggers does not accelerate reads and creates severe risk if the session writes.","oltp":"Do not tune session_replication_role. Only a controlled replication or repair process should set replica, and it must independently guarantee constraints and restore origin.","small":"Leave origin. The setting is not a small-node optimization and can bypass foreign keys."},"mechanism":["session_replication_role sets the session's behavior for triggers and rewrite rules. replica suppresses ordinary triggers and rules, including foreign-key enforcement, and changing the value discards cached plans.","session_replication_role is a SUPERUSER-context setting. Superuser or a role granted the appropriate SET privilege 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 session_replication_role 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.","Forgetting that replica mode suppresses foreign-key triggers as well as application triggers."],"references":[{"title":"PostgreSQL 19 Beta 4: session_replication_role","url":"https://www.postgresql.org/docs/19/runtime-config-client.html#GUC-SESSION-REPLICATION-ROLE"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["search_path","row_security","event_triggers","restrict_nonsystem_relation_kind","createrole_self_grant"],"summary":"session_replication_role is the PostgreSQL setting that defines the session's behavior for triggers and rewrite rules."},"enumvals":[],"first_version":"8.3","group":"Client Connection Defaults","group_slug":"client","imported_at":"2026-09-27T17:57:31.958793+08:00","intro_commit":{},"key":"session_replication_role","last_version":"20","max_val":"","min_val":"","name":"session_replication_role","position":356,"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":"Controls firing of replication-related triggers and rules for the current session.","short_desc_zh":"","source_rev":"english-manuals:7b1fafe61b732c4c88689110f48dd865f767085d520bce6684065a986c568ad2","unit":"","vartype":"enum"}},"Definition":{"Collection":"guc","Key":"session_replication_role","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"session_replication_role","SourceRevision":"english-manuals:7b1fafe61b732c4c88689110f48dd865f767085d520bce6684065a986c568ad2","Facts":{"boot_val":"origin","category":"Client Connection Defaults / Statement Behavior","context":"superuser","description":"Controls firing of replication-related triggers and rules for the current session. Possible values are origin (the default), replica and local. Setting this parameter results in discarding any previously cached query plans. Only superusers and users with the appropriate SET privilege can change this setting. The intended use of this setting is that logical replication systems set it to replica when they are applying replicated changes. The effect of that will be that triggers and rules (that have not been altered from their default configuration) will not fire on the replica. See the ALTER TABLE clauses ENABLE TRIGGER and ENABLE RULE for more information. PostgreSQL treats the settings origin and local the same internally. Third-party replication systems may use these two values for their internal purposes, for example using local to designate a session whose changes should not be replicated. Since foreign keys are implemented as triggers, setting this parameter to replica also disables all foreign key checks, which can leave data in an inconsistent state if improperly used.","doc":{"anchor":"GUC-SESSION-REPLICATION-ROLE","file":"runtime-config-client.html","lang":"en","sha256":"6be6cc70f29eca4695dc43b2b2b94c75b7e0eaaa2c00273d7a98488917a7edb7","slug":"18"},"documented":true,"enumvals":["origin","replica","local"],"extra_desc":null,"lang":"en","max_val":null,"metadata_version":"18","min_val":null,"name":"session_replication_role","short_desc":"Sets the session's behavior for triggers and rewrite rules.","source":"pg-settings-source-snapshot","unit":null,"vartype":"enum"},"ManualEvidence":{"doc":{"anchor":"GUC-SESSION-REPLICATION-ROLE","file":"runtime-config-client.html","lang":"en","sha256":"6be6cc70f29eca4695dc43b2b2b94c75b7e0eaaa2c00273d7a98488917a7edb7","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"session_replication_role","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"session_replication_role","Summary":"","BodyHTML":"\u003cp\u003e控制当前会话中复制相关触发器和规则的触发。可能的值是\u003ccode\u003eorigin\u003c/code\u003e（默认值），\u003ccode\u003ereplica\u003c/code\u003e和\u003ccode\u003elocal\u003c/code\u003e。设置此参数会导致丢弃先前缓存的任何查询计划。只有超级用户和具有适当\u003ccode\u003eSET\u003c/code\u003e权限的用户才能更改此设置。\u003c/p\u003e\u003cp\u003e这个设置的预期用途是由逻辑复制系统在应用所复制的更改时将它设置为\u003ccode\u003ereplica\u003c/code\u003e。其效果将是触发器和规则（没有对其默认配置做修改）在副本上将不会被触发。更多信息请参考\u003ca href=\"/docs/18/sql-altertable.html\" title=\"ALTER TABLE\" rel=\"nofollow\"\u003e\u003ccode\u003eALTER TABLE\u003c/code\u003e\u003c/a\u003e的子句\u003ccode\u003eENABLE TRIGGER\u003c/code\u003e以及\u003ccode\u003eENABLE RULE\u003c/code\u003e。\u003c/p\u003e\u003cp\u003ePostgreSQL在内部会把设置\u003ccode\u003eorigin\u003c/code\u003e和\u003ccode\u003elocal\u003c/code\u003e同样对待。第三方复制系统可能会把这两个值用于其内部目的，例如把\u003ccode\u003elocal\u003c/code\u003e用来标出一个不应复制其更改的会话。\u003c/p\u003e\u003cp\u003e因为外键被实现为触发器，将这个参数设置为\u003ccode\u003ereplica\u003c/code\u003e还会禁用所有的外键检查，如果使用不当可能会让数据处于一种不一致的状态。\u003c/p\u003e","SourceRevision":"2026-09-11@29c86d9","ContentHash":"dcf1ee0673e77e5714ceec4529ac30d25d041aa0c1c5b4fad016c9121d14276f","Payload":{"carried_from":"","carry_reason":"","doc_html":"\u003cp\u003e控制当前会话中复制相关触发器和规则的触发。可能的值是\u003ccode class=\"literal\"\u003eorigin\u003c/code\u003e（默认值），\u003ccode class=\"literal\"\u003ereplica\u003c/code\u003e和\u003ccode class=\"literal\"\u003elocal\u003c/code\u003e。设置此参数会导致丢弃先前缓存的任何查询计划。只有超级用户和具有适当\u003ccode class=\"literal\"\u003eSET\u003c/code\u003e权限的用户才能更改此设置。\u003c/p\u003e\u003cp\u003e这个设置的预期用途是由逻辑复制系统在应用所复制的更改时将它设置为\u003ccode class=\"literal\"\u003ereplica\u003c/code\u003e。其效果将是触发器和规则（没有对其默认配置做修改）在副本上将不会被触发。更多信息请参考\u003ca href=\"/docs/18/sql-altertable.html\" title=\"ALTER TABLE\"\u003e\u003ccode class=\"command\"\u003eALTER TABLE\u003c/code\u003e\u003c/a\u003e的子句\u003ccode class=\"literal\"\u003eENABLE TRIGGER\u003c/code\u003e以及\u003ccode class=\"literal\"\u003eENABLE RULE\u003c/code\u003e。\u003c/p\u003e\u003cp\u003ePostgreSQL在内部会把设置\u003ccode class=\"literal\"\u003eorigin\u003c/code\u003e和\u003ccode class=\"literal\"\u003elocal\u003c/code\u003e同样对待。第三方复制系统可能会把这两个值用于其内部目的，例如把\u003ccode class=\"literal\"\u003elocal\u003c/code\u003e用来标出一个不应复制其更改的会话。\u003c/p\u003e\u003cp\u003e因为外键被实现为触发器，将这个参数设置为\u003ccode class=\"literal\"\u003ereplica\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","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}
