When PostgreSQL logical replication is the right tool
Use logical replication when you need selected tables copied to another PostgreSQL server, another major version or another site, and you cannot accept a long write freeze to get there. Typical cases are a low-downtime major upgrade, consolidating data from several databases into an analytics server, or sharing a subset of data with another team or organization. If you need a full, byte-identical standby for failover, streaming replication is usually the better fit, and the two can coexist on the same primary.
The difference comes down to what is shipped. Streaming replication sends physical WAL blocks, so the standby is a copy of the entire cluster and must run the same major version. Logical replication instead decodes row changes and sends them through a publication on the source to a subscription on the target. You choose which tables are published, the subscriber can run a different major version, and the subscriber stays writable for the tables it does not receive. Because the target applies ordinary row changes, it can also hold data in a different layout, although the schema of each published table must still match on both sides.
Before committing to the design, confirm three things in your own environment: that each published table has a primary key or a replica identity that lets updates and deletes be matched on the subscriber, that the source has enough wal_level set to logical and sufficient replication slots and senders for your planned subscriptions, and that someone owns the replication slot, because an abandoned slot keeps WAL on the source. The PostgreSQL upgrading documentation describes the version-upgrade pattern, and the exact prerequisites for your release should be checked there before you schedule a cutover.
How publications and subscriptions move changes
Changes start in the publisher's write-ahead log, where the publication decides which tables and operations are eligible. A replication slot holds the stream on the publisher until the subscriber confirms it has applied the changes, so a stalled subscriber keeps WAL on the publisher's disk. The subscriber applies the changes to its own tables, and the link between the two sites is the trust boundary to check: credentials, TLS and network reachability all cross it.
Changes flow from a publication through a replication slot to a subscription across the site boundary.
Which use case fits logical replication
Logical replication can carry data from an older PostgreSQL major version to a newer one, which is why it is a candidate for upgrades that cannot tolerate a long outage. The PostgreSQL upgrading documentation says this approach allows a major upgrade with only several seconds of downtime. That figure describes the cutover mechanism, not your whole project. The real window depends on how you stop writes, how long the subscriber takes to catch up, and how you repoint applications, so measure it in a rehearsal in your environment.
- Version pairing: Confirm the source and target majors are supported and that the target is the version you intend to run, using the PostgreSQL versioning policy.
- Primary keys: Every replicated table needs a primary key or a replica identity, or updates and deletes cannot be applied on the subscriber.
- Sequences: Sequence values do not replicate, so plan how identity and serial columns are advanced at cutover.
- Schema changes: DDL is not replicated, so the target schema must be created and kept aligned while replication runs.
- Rollback path: Design a reverse subscription or a retained source so you can return if the new version misbehaves.
Before committing, confirm the cutover steps and the measured window with your own application owners and change board.
Teams often publish selected tables from several operational databases into one analytics database, so reports do not query production systems directly. The source databases stay in their own roles, and the target holds a combined copy. Because the subscriber is separate, you can add indexes and reporting structures there without touching the sources. The design work is mostly about naming, conflict avoidance and deciding which tables are worth copying at all.
- Table selection: Publish only the tables analytics needs, and document why each one is included.
- Key uniqueness: Tables from different sources may share primary key values, so the target needs a source identifier or composite key.
- Subscription per source: Use one subscription per source database so a failure in one feed does not stop the others.
- Monitoring lag: Track replication lag and alert when a subscription stops applying changes.
- Schema drift: Source teams must not change published tables without coordinating the target.
Ask the analytics owner which columns are required, how stale data can be before reports become wrong, and who approves changes to published tables.
Logical replication can send selected tables to another site or to a partner organization, which is useful when the recipient needs current rows but should not have access to the whole database. The publisher controls exactly which tables and, depending on the version you run, which row filters or column lists are published. The network path, authentication and credential handling matter as much as the data selection, because the subscriber connects back to the publisher with a role you define.
- Least-privilege role: Create a dedicated replication role on the publisher with the minimum rights needed, and restrict where it can connect from.
- Transport security: Require TLS for the connection and review the authentication method in the client authentication documentation.
- Data classification: Confirm what the recipient may see before publishing, since replicated rows are full copies.
- Deletions and corrections: Plan how erroneous data is corrected, since the subscriber applies changes as they arrive.
- Network failure: Decide how long a broken link is tolerated and how the publisher's retained change data is sized.
Confirm the data sharing agreement, the recipient's controls and the network paths with both teams before any subscription is created.
Logical replication is defined between PostgreSQL servers, so it is the right tool when the target is also PostgreSQL but runs on a different platform, operating system, hardware or hosting arrangement. It is not a general bridge to other database engines. If the target is a different product, you need a separate migration tool, and the replication design does not carry over. For PostgreSQL to PostgreSQL moves across platforms, the main risks are configuration differences and extensions that must exist on both ends.
- Extension parity: Any extension whose data or types are in replicated tables must be installed on the target before the copy starts.
- Collation and encoding: Check that the database encoding and locale settings produce the same ordering and comparisons on both platforms.
- Data types: Confirm custom types and domains exist on the target with the same definitions.
- Scope of copy: Objects such as sequences, large objects, and some DDL need separate handling outside replication.
- Testing: Compare row counts and checksums on sample tables after the initial sync and again after the cutover.
Before starting, ask the platform team to list every extension, type and collation in use so the target can be prepared to match.
Configuration options and when each fits
This table compares the main choices when you define a logical replication setup: how much of each database is published, whether existing data is copied, how subscribers commit, and how replication slots and origins are handled. Read each row with the workload it serves, because most choices trade simpler operations against fewer surprises during cutover or failure.
| Option | What it controls | When it fits | Trade-off to plan for |
|---|---|---|---|
| Publication of all tables | Every table in the database is sent to subscribers, including tables created later if the publication is defined for all tables | Full consolidation into an analytics or reporting target where the subscriber should mirror the whole database | New tables may replicate before the subscriber schema is ready, and sensitive tables are included unless excluded explicitly |
| Publication of selected tables | Only named tables are sent, and each table must be added deliberately | Data sharing or a phased migration where only some tables move | Someone must add new tables to the publication, or they silently stay out of replication |
| Row filters | A WHERE clause decides which rows of a published table are sent | Sending a regional or tenant subset of data to a separate site | Filter logic runs on the publisher and must be reviewed with the same care as access control, and filtered rows can complicate updates that move rows in or out of scope |
| Column lists | Only selected columns of a published table are sent | Withholding personal or internal columns from a downstream consumer | Subscriber tables must still supply the columns that are sent, and column choices need review whenever the table changes |
| Initial data copy | Existing rows are copied when the subscription is created | A new subscriber that must start from a complete, consistent copy | The copy can take a long time on large tables and adds load on the publisher |
| Skip initial copy | Only changes made after subscription creation are applied | The subscriber already holds the data, or the data was loaded by another method | Any gap or mismatch is not repaired automatically, so row counts and checksums should be compared before go-live |
| Synchronous commit on the subscriber | Whether a publisher commit waits for the subscriber to confirm, using settings such as synchronous_commit and synchronous_standby_names | Cases where the subscriber must not lag behind for cutover checks or critical reporting | A slow or unavailable subscriber can stall writes on the publisher, so it is rarely the default for cross-site links |
| Asynchronous commit on the subscriber | The publisher commits without waiting for the subscriber, and changes are applied as they arrive | Analytics consolidation, cross-site sharing and most migrations where a short lag is acceptable | Subscriber data can trail the publisher, and a failover can leave recent changes unapplied |
| Replication slot on the publisher | Keeps WAL needed by the subscriber until changes are consumed | Reliable delivery of changes across network interruptions | An inactive or stalled slot retains WAL and can fill the publisher disk, so slot lag must be monitored |
| Origin setting | Controls whether changes that already came from another replication source are forwarded again | Bidirectional or chained setups where loops must be avoided | Incorrect origin handling can cause duplicate or looping changes, and the behavior should be tested against the target version's documentation |
How to set up a publication and subscription
This sequence takes a selected set of tables from a source PostgreSQL server to a target, first copying existing rows and then streaming ongoing changes. It ends with a verified, lagging-free copy and a cutover plan that accounts for sequences and the objects logical replication does not carry.
Confirm wal_level and connection settings
The platform engineer or DBA checks that the source has wal_level set to logical, that enough replication slots and WAL sender processes are available, and that the target can reach the source over the network with a role allowed to replicate. Settings are changed in the configuration file, and wal_level requires a server restart, so schedule that change before work begins. Confirm the values with SHOW wal_level and SHOW max_replication_slots on the source, and check that pg_hba.conf allows the replication role from the target address. The step is done when both ends report the expected values and a test connection from the target succeeds.
Create the publication on the source
A DBA creates a publication on the source that lists only the tables to replicate, using CREATE PUBLICATION with explicit table names rather than an all-tables publication unless every table is intended. Decide which operations are published (inserts, updates, deletes, truncates) and whether row filters or column lists are needed, since these are defined on the publication. Check the result by querying pg_publication and pg_publication_tables to confirm that each intended table appears and no others do. Unlisted tables stay out of the stream, so a missing table here is the most common reason a later sync looks incomplete.
Prepare the target schema and primary keys
The target database needs matching tables with the same names, column names and compatible data types, created before the subscription exists. Each replicated table must have a primary key or a replica identity, because updates and deletes are matched on that identity, so the team checks this on the source with a query against the system catalogs before creating target tables. Sequences, indexes beyond keys, triggers, views and functions are not created by replication, so they are added on the target as part of this step. The step is complete when the schema diff between source and target shows only the intended differences.
Create the subscription on the target
On the target, a DBA runs CREATE SUBSCRIPTION with the source connection string and the publication name, which starts an initial table copy followed by streaming of changes. The subscription creates a replication slot on the source unless the slot is named and managed separately, so the team records the slot name in its runbook. Decide whether the initial copy should run immediately or be deferred, and make sure the source has enough disk space to hold WAL while the copy runs. The step is done when the subscription appears in pg_subscription and the target reports each table as ready or actively syncing.
Verify initial sync and replication lag
The operator checks pg_subscription_rel on the target to confirm every table reaches the ready state, then compares row counts and a sample of checksummed or aggregated values between source and target for each table. On the source, pg_replication_slots and pg_stat_replication show whether the slot is active and how far behind the subscriber is, measured in bytes of WAL. Lag should fall toward zero under normal write load, and a slot that stays inactive or grows steadily needs investigation because it prevents WAL cleanup on the source. The step is done when counts match, no table is stuck in an initial copy state and lag stays within the tolerance the team has agreed in advance.
Plan cutover and sequence handling
Sequences are not replicated, so before cutover the team reads the current value of each sequence on the source and sets the matching sequence on the target higher than the last value used, with an agreed buffer. The cutover plan defines the write freeze on the source, the wait for the subscriber to catch up, the final count and checksum comparison, the switch of application connection strings, and the rollback path. Each action is written as a runbook step with a named owner and a check, and the team rehearses it on a copy of the environment. The cutover is complete when the target accepts writes, the source is fenced from application traffic, and the replication slot is dropped deliberately once rollback is no longer needed.
What logical replication does not carry over
Logical replication copies row changes for the tables you publish, so everything else has to be moved and kept in step by other means. The main gaps are schema changes, sequences, large objects and any object outside the publication. Schema changes are not replicated: a CREATE TABLE, ALTER TABLE or new index on the publisher does not appear on the subscriber, and the subscriber must be changed by hand, in an order that keeps incoming rows valid. Sequence values are also not carried over, so the subscriber's sequences must be set to a value above the highest key in use before cutover, or new inserts will collide with replicated rows. Confirm the current list of unreplicated objects, including whether functions, triggers, views and permissions are covered for your version, in the PostgreSQL upgrading documentation and the logical replication restrictions in the PostgreSQL reference for that release.
Large objects, the storage behind the lo interface, are a separate case that catches teams out. Check whether your application uses them, because a table that stores only an OID pointing at a large object will replicate fine while the content it points to does not move. Tables you did not add to the publication, and any table without a usable replica identity for updates and deletes, need an explicit decision: add them, exclude them with a documented reason, or move them with a separate dump-and-restore step. Make that inventory a written deliverable before the first subscription is created, and compare the publisher and subscriber catalogs after the initial copy finishes.
These gaps shape cutover and rollback. A cutover is safe only after the subscriber has caught up, the sequences are reset, the schema drift check is clean and the application is paused or pointed at the new server in a planned order. Rollback is harder than cutover: once writes land on the new server, changes must be replicated back to the old one, or the old server is stale and the change window is lost. Decide before go-live how long the old primary stays available, who approves a reverse subscription, and how you will reconcile sequences in both directions. Rehearse the whole sequence on a copy of production, and time it, so the cutover window is based on measurement rather than estimate.
Security and operational risks to plan for
Logical replication moves data between servers, so the risks sit where access, transport, storage and content meet. Each card names one place where a design decision changes what can go wrong, and what to check before the first subscription goes live.
Replication user privileges
A subscription connects with a role that must be allowed to read published tables and, on the publisher, to use replication. Granting a superuser or a broad owner role to that connection gives a remote server far more reach than replication needs. Create a dedicated replication role with the minimum table privileges, and check the role attributes after every change to the publication list. Ask the platform team which accounts can alter publications and subscriptions, since those changes alter what data leaves the site.
Authentication methodsEncryption and authentication between sites
Replication traffic carries full row data, so it must cross the network under TLS with the subscriber verifying the publisher's certificate. Set the connection string to require encryption, then choose an authentication method that suits your identity estate, such as SCRAM passwords or client certificates. Restrict pg_hba.conf entries on the publisher to the subscriber's addresses and the replication role. Confirm with your network team which firewall paths and certificate authority apply to each site pair.
Replication slot growth on the publisher
A logical replication slot keeps the publisher retaining WAL until the subscriber confirms it has consumed that data. If a subscriber stalls, is disabled or is deleted without dropping its slot, WAL accumulates and can fill the publisher's disk, which stops writes for every database on that server. Set an alert on the retained WAL size per slot, define the response when a subscription is paused, and decide who may drop a slot. Treat this as an outage risk for the publisher, not only the replica.
Monitoring replication lag
Lag tells you whether the subscriber keeps up, but a subscription can show as running while its apply worker is blocked by a conflict or a missing row. Track the difference between the publisher's current WAL position and each slot's confirmed position, along with apply errors in the subscriber's logs. Set thresholds that page someone, and test them by pausing a subscription in a non-production environment. Ask your monitoring team which exporter or view will expose these values in your current stack.
Exposure of published rows and columns
A publication decides what leaves the database. Publishing a whole table can carry personal data, credentials, free-text notes or restricted fields to a site that was only meant to receive aggregates. Row filters and column lists limit this, but they are set in SQL and easy to widen during a later change. Review each publication against your data classification, record which fields reach which site, and check that the receiving team's controls match the sensitivity of what arrives.
Questions teams ask before running logical replication
What drives the effort and cost of a logical replication project?
The main drivers are how much schema alignment the source and target need, how much testing the cutover requires, how detailed the cutover plan is, and how much monitoring you want during replication. Schema alignment covers matching tables, column types, primary keys and sequences, which is often the largest unknown in a legacy database. Testing covers replication lag, application behavior against the target and rollback rehearsal. One-time costs include design, build and cutover; recurring costs are whatever monitoring and operations you keep afterward. Ask any quote to itemize these phases, state who performs each one, and list the assumptions about table count, data volume and application changes.
How long does a logical replication migration window take, and what sets it?
The downtime window is set mostly by the cutover, not by the initial copy. PostgreSQL documents that logical replication allows a major upgrade with only several seconds of downtime, but that result depends on the cutover being rehearsed, sequences being synchronized, and replication lag being near zero before you switch traffic. Initial table synchronization time grows with data volume and write activity, and it can run for a long time without affecting users. Ask for a timeline that separates the copy period from the cutover window, and confirm how the plan handles tables without primary keys and large tables that take longer to synchronize.
Can our in-house team run logical replication without a partner?
Often yes, if the team already operates PostgreSQL and has someone who can read replication slots, publication and subscription state, and the server logs. The skills that are hardest to build quickly are rehearsing the cutover, handling sequences and conflicts, and monitoring slot growth on the source. Teams that have not done a cutover before usually benefit from an outside review of the plan and a rehearsal. Decide based on how many tables you replicate, how much schema change happens during the project, and whether you can staff the cutover night with people who have practiced it.
What do we need to provide before a logical replication project starts?
You need network and account access to the source and target servers, a test copy or representative sample of the data, and a schedule of maintenance windows that the business accepts. You also need a list of the tables and sequences in scope, the applications that write to them, and the owners who approve the cutover. Without a non-production environment that resembles production, testing will not show what breaks at cutover. Confirm these inputs in the statement of work so that delays caused by missing access or data do not turn into schedule changes.
What does logical replication not carry over that we need to plan for?
Logical replication replicates the row changes for tables included in a publication, so schema objects and some state must be handled separately. Sequence values are not continuously replicated, so they need an explicit synchronization step at cutover. Schema changes such as new tables or columns are not automatically propagated, and large objects, certain DDL and other server-level settings need their own plan. Check the PostgreSQL logical replication restrictions for your version and confirm each object type in your database against them before you commit to a design.
When is streaming replication or pg_upgrade a better choice than logical replication?
Choose streaming replication when the goal is high availability or read replicas on the same major version, because it copies the whole cluster and is designed for failover. Choose pg_upgrade when you are moving to a new major version on the same server, the database is small enough that a planned outage is acceptable, and you want a simpler procedure with fewer moving parts. Logical replication fits when you need to replicate selected tables, move between platforms or major versions with low downtime, or consolidate data from several sources. Compare the downtime window, rollback path, schema change needs and the team's operating experience before deciding.
How should we check that the target is correct before cutover?
Start with replication lag and row-count comparisons for each replicated table, then compare checksums or sampled rows where counts can hide differences. Verify sequences, constraints, indexes and permissions on the target, and run application test suites against it. Monitor the replication slot on the source, because an inactive slot retains WAL and can fill the disk. Rehearse the full cutover, including the rollback, at least once on a copy of production before the planned window. Ask the quote to state which checks are included and what evidence you receive at the end.
Official PostgreSQL documentation to read first
Before you choose a logical replication design, read the official PostgreSQL documentation on upgrading a cluster. It explains that logical replication works between different major versions, which is what makes a low-downtime major upgrade possible, and it sets out how it compares with pg_dumpall, pg_upgrade and the other upgrade paths. Pair that reading with your own inventory of which tables carry the data you need to move, because logical replication copies only the objects you publish. Confirm the exact requirements for your source and target versions in the documentation for those versions, since the upgrade chapter describes general behavior rather than a checklist for your environment. Upgrading a PostgreSQL cluster is the natural starting point for that work.
Next, read the high availability documentation. It covers streaming replication, hot standby and the difference between synchronous and asynchronous replication, which is the context you need to decide whether logical replication should sit alongside physical replicas or replace them for a given workload. The page also makes clear that PostgreSQL does not detect a failed primary or promote a standby on its own, so any failover behavior in a logical replication topology is a design decision you own. Note which replication features apply to the database you run in production and which ones are useful only for migration or data sharing.
Finally, read the PostgreSQL versioning policy before fixing a target version. It lists the supported major versions and their end-of-life dates, and it describes the minor release cadence. Use those dates to decide whether your subscriber should run a version that will still be supported when the migration is complete. Confirm the current support table on the policy page at the time you plan, because end-of-life dates drive the timing of any upgrade that logical replication is meant to support. PostgreSQL versioning policy lists the dates that should anchor that decision.
How DeployOpen scopes and delivers logical replication work
DeployOpen plans, builds, tests, documents and supports PostgreSQL logical replication inside infrastructure you control, with the publisher, subscriber and network path agreed before any work starts. Each engagement is fixed-scope, so the tables, versions, cutover steps and acceptance tests are written down before the build begins.
How we scope
- Inventory the publisher and subscriber major versions, the tables to replicate and the schema changes that logical replication will not carry.
- Agree the replication direction, the cutover or consolidation goal, and the acceptable write pause, recorded in the written scope.
- Confirm network paths, TLS, credentials and the owner of each sequence, trigger and DDL change before any subscription is created.
How we build
- Create publications and subscriptions on tables with primary keys or replica identity settings chosen for each table's update and delete pattern.
- Copy initial data, monitor replication lag and slot retention on the publisher, and set alerts before the first production write is replicated.
- Test cutover with rehearsal runs, including sequence synchronization, application connection switches and a rollback path back to the source.
How we hand over
- Deliver the written runbook with publication and subscription definitions, configuration files, monitoring thresholds and rollback steps.
- Document the replication objects that are not carried over, such as DDL, sequences, large objects and roles, with the owner for each.
- Walk your operations and database teams through the cutover results and the acceptance test evidence before the engagement closes.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers after handover, covering replication health and version changes.
- Ask any quote to state which replication tasks recur, such as monitoring review, slot cleanup and retesting after schema changes.
- Confirm with your team how replication failures are escalated and who approves changes to published tables.

