Atlas now supports managing the REPLICA IDENTITY setting for PostgreSQL tables, controlling what information is written to the WAL for logical replication.
Atlas now supports managing the REPLICA IDENTITY setting for PostgreSQL tables, which controls what information is written to the Write-Ahead Log (WAL) for logical replication. This feature is essential for teams using logical replication for real-time data streaming, change data capture (CDC), or database synchronization.
Supported Replica Identity Types
| Type | Description |
|---|---|
| DEFAULT | Uses the primary key (if present) for logical replication |
| NOTHING | No old row information is written to the WAL |
| FULL | All columns of the old row are written to the WAL |
| INDEX | Uses a specific unique index for the replica identity |
HCL Schema Syntax
Define replica identity directly in your HCL schema. For simple types like FULL or NOTHING, use the enum value directly. For index-based replica identity, reference the index:
table "users" {schema = schema.publiccolumn "id" {type = serial}column "email" {type = textnull = false}primary_key {columns = [column.id]}# Simple enum value: FULL or NOTHINGreplica_identity = FULL}table "accounts" {schema = schema.publiccolumn "id" {type = serial}column "account_id" {type = textnull = false}primary_key {columns = [column.id]}index "idx_account_id" {unique = truecolumns = [column.account_id]}# Reference to an index for INDEX typereplica_identity = index.idx_account_id}
Generated Migrations
Atlas generates the appropriate ALTER TABLE ... REPLICA IDENTITY statements:
-- Set replica identity for "users" tableALTER TABLE "users" REPLICA IDENTITY FULL;-- Set replica identity for "accounts" table using indexALTER TABLE "accounts" REPLICA IDENTITY USING INDEX "idx_account_id";
Key Features
- Schema Inspection: Atlas reads the replica identity from pg_class.relreplident and links index references via pg_index.indisreplident
- Diff Detection: Changes between replica identity types (including index changes) are automatically detected and generate migrations
- Reversible Migrations: All replica identity changes include reverse statements (defaulting back to REPLICA IDENTITY DEFAULT)
- HCL & SQL Parity: The feature works consistently whether defining schemas in HCL or SQL