Back to changelog
New
3 minute read

PostgreSQL Replica Identity Support

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

TypeDescription
DEFAULTUses the primary key (if present) for logical replication
NOTHINGNo old row information is written to the WAL
FULLAll columns of the old row are written to the WAL
INDEXUses 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.public
column "id" {
type = serial
}
column "email" {
type = text
null = false
}
primary_key {
columns = [column.id]
}
# Simple enum value: FULL or NOTHING
replica_identity = FULL
}
table "accounts" {
schema = schema.public
column "id" {
type = serial
}
column "account_id" {
type = text
null = false
}
primary_key {
columns = [column.id]
}
index "idx_account_id" {
unique = true
columns = [column.account_id]
}
# Reference to an index for INDEX type
replica_identity = index.idx_account_id
}

Generated Migrations

Atlas generates the appropriate ALTER TABLE ... REPLICA IDENTITY statements:

-- Set replica identity for "users" table
ALTER TABLE "users" REPLICA IDENTITY FULL;
-- Set replica identity for "accounts" table using index
ALTER 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
featurepostgresreplicationlogical-replication