CockroachDB · error reference
CockroachDB: session_replication_role is not supported
unimplemented: the configuration setting "session_replication_role" is not supported
The standard Postgres trick for loading data with foreign keys disabled does not exist on CockroachDB. What to do instead, and why the usual workaround is unnecessary here.
What the database is telling you
On Postgres, SET session_replication_role = 'replica' suppresses foreign-key triggers for the session, which is how bulk loaders and replication sinks avoid ordering problems. CockroachDB does not implement the setting and rejects it outright — confirmed against v23.2.
Why it shows up in a migration
Any loader that assumed Postgres because the wire protocol matched will send this and fail. Whether that is fatal depends on how the failure is treated: a loader that ignores it proceeds with constraints enforced, and a loader that warns on the way out can tell you your constraints may be unvalidated when nothing is actually wrong.
Common causes
- A loader detecting Postgres by wire protocol or driver rather than by server version.
- A replication sink configured with a generic 'postgres' target type.
- Scripts copied from Postgres bulk-load guides.
How to fix it
- 1
Do not disable constraints — add them after the data lands. This is faster on any engine and needs no session setting at all.
-- 1. create tables without foreign keys -- 2. load the data -- 3. then: ALTER TABLE orders ADD CONSTRAINT fk_cust FOREIGN KEY (cust_id) REFERENCES customers(id);
- 2
Confirm what your CockroachDB version accepts before relying on any session setting.
SHOW session_replication_role; -- errors if unsupported
- 3
For ongoing replication, apply events in source-transaction order rather than turning enforcement off.
What DBShifts does about it
CockroachDB is listed explicitly as having no FK-disable statement, so the Postgres one is never sent to it. That entry exists to stop the wire-protocol alias from inheriting a statement that always fails — which would have raised a false 'constraints may be left unvalidated' warning on every CockroachDB migration. Foreign keys are applied after the data instead.
Bulk transfer engine
Migrating between engines?
DBShifts converts the schema, moves the data, and then proves the two sides match with a type-aware checksum per table — not just a row count. Errors like this one are handled on the way, and the ones that cannot be handled are reported rather than logged and forgotten.
Related errors
CockroachDB
CockroachDB: at or near "restart" syntax error on TRUNCATE
TRUNCATE ... RESTART IDENTITY CASCADE is valid Postgres and a syntax error on CockroachDB. The difference, and what to use instead.
CockroachDB
CockroachDB: unknown function pg_total_relation_size()
CockroachDB speaks the Postgres wire protocol but does not implement every pg_catalog function. Why tools that introspect Postgres fail on the size query specifically.