select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

CONFIGURATION / CLIENT CONNECTION DEFAULTS

session_replication_role

Read PG 18 manual ↗

Controls firing of replication-related triggers and rules for the current session.

Type
enum
Context
superuser
Measured default
origin
Unit
Metadata snapshot
18
Allowed values
origin, replica, local

Definition PG 18 manual

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.

Measured default history
Version intervalDefault
9.0 – 19origin
Analysis & operational context

Authored guidance from the GUC source snapshot; the version-specific manual above is the definition reference. View source ↗

How it works

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.

Operational considerations

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.

Workload guidance

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.

Version history 2
  1. PG 14 → 15changed
  2. PG 10 → 11changed

Related entries

Further reading

Definition snapshot: english-manuals:29b668acacf3cd953179655c4d5… · English manual source