DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Client Connection Defaults / Statement Behavior

session_replication_role

Sets the session's behavior for triggers and rewrite rules.

  • Default: origin
  • Type: enum
  • Values: origin · replica · local
  • Applies: Session (superuser)

In plain words

Replication tools need to apply rows without firing the same triggers again. Setting this to replica makes normal triggers and rules skip, including the internal triggers that check foreign keys. It is powerful and easy to misuse.

For DBAs and operators

Triggers and rules have a firing mode set with ALTER TABLE … ENABLE [REPLICA | ALWAYS] TRIGGER:

  • Normal (ENABLE): fire when the role is origin or local.
  • ENABLE REPLICA: fire only when the role is replica.
  • ENABLE ALWAYS: fire in every mode.

origin and local are treated the same internally. Logical replication apply workers run with replica, which is why ordinary triggers on a subscriber do not fire for replicated rows unless enabled as ALWAYS or REPLICA.

Warning: foreign keys are implemented as triggers, so replica also disables FK checks. Bulk loads with SET session_replication_role = replica are fast but can leave orphaned rows nobody notices until later. Changing it discards cached plans. Only superusers (or roles granted SET) can change it.

How to change it

A superuser (or a role granted SET) can change it per session with SET.

See it in context

Logical replication Logical replication workers

Related parameters

event_triggers max_logical_replication_workers

All Client Connection Defaults parameters