# session_replication_role

> session_replication_role is the PostgreSQL setting that defines the session's behavior for triggers and rewrite rules.
---

> [!NOTE]
> **Fact — official short description:** “Sets the session's behavior for triggers and rewrite rules.”

## Identity {#identity}

| Field | Value | Meaning |
| --- | --- | --- |
| Type | `enum` | Upstream pg_settings type |
| Context | `superuser` | Settable at runtime by a superuser |
| Unit | — | Raw unit |
| Range | — | Raw limits in the last observed version |
| Enum values | `origin`, `replica`, `local` | — for non-enum types |
| Category | Client Connection Defaults / Statement Behavior | Upstream classification |
| Latest boot value | `origin` | origin |
{.fields meta="-"}

## Lifecycle {#lifecycle}

| Fact | Value |
| --- | --- |
| First observed | PG9.0 (research boundary) |
| Present in | PG9.0–19 Beta 3 |
| Removed in | No |
| Introduction commit | Not asserted: predates the PG9.0 research boundary |
| Commit date | — |
| Discussion | — |

## Default history {#default-history}

| Versions | Raw `boot_val` | Unit | Human value |
| --- | --- | --- | --- |
| PG9.0–19 Beta 3 | `origin` | — | origin |
{.full-width caption="Measured PG9.0–19 Beta 3 boot defaults"}

## How it works {#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.

## Tuning advice {#tuning-advice}

> [!TIP]
> **Advice.** These are workload-specific starting points and must be validated with measurements.

| Workload | Guidance |
| --- | --- |
| 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. |
| OLAP | Keep origin for analytical sessions; suppressing triggers does not accelerate reads and creates severe risk if the session writes. |
| Small nodes | Leave origin. The setting is not a small-node optimization and can bypass foreign keys. |
{.full-width}

## Pigsty {#pigsty}

Values use the fixed 8-vCPU, 32-GiB, 100-GiB SSD fixture and render the current Pigsty templates for PG19 Beta 3; this does not assert current Pigsty support for that historical or beta release.

| Template | Effective value | Versus upstream boot | Source expression |
| --- | --- | --- | --- |
| OLTP | Unmodified | — | — |
| OLAP | Unmodified | — | — |
| CRIT | Unmodified | — | — |
| TINY | Unmodified | — | — |
{.full-width}

> [!CAUTION]
> **Advice — pending human review.** Fact from the current Pigsty template projection: OLTP: PG9.0–19 Beta 3 unmodified; OLAP: PG9.0–19 Beta 3 unmodified; CRIT: PG9.0–19 Beta 3 unmodified; TINY: PG9.0–19 Beta 3 unmodified. No Pigsty-specific rationale is inferred from an absent override.

## Common pitfalls {#common-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.

## Related parameters {#related-parameters}

[`search_path`](/parameters/search-path/) · [`row_security`](/parameters/row-security/) · [`event_triggers`](/parameters/event-triggers/) · [`restrict_nonsystem_relation_kind`](/parameters/restrict-nonsystem-relation-kind/) · [`createrole_self_grant`](/parameters/createrole-self-grant/)

## References {#references}

- [PostgreSQL 19 Beta 3 — session_replication_role](https://www.postgresql.org/docs/19/runtime-config-client.html#GUC-SESSION-REPLICATION-ROLE)
- [PostgreSQL 19 release notes](https://www.postgresql.org/docs/19/release-19.html)
- [Machine-readable GUC export](/data/guc.jsonl)
