How to fix ERROR: replication origin already exists in PostgreSQL

PostgreSQLINTERMEDIATEMEDIUMUpdated Dec 22, 2025ยท 92 views

This error occurs when attempting to create a replication origin with a name that already exists in the pg_replication_origin catalog, typically during logical replication setup or when manually creating origins.

Quick fix

Fixes ERROR: replication origin already exists

-- View all replication origins
SELECT * FROM pg_replication_origin;

-- View origins with their current replication status
SELECT * FROM pg_replication_origin_status;
  1. Check existing replication origins
  2. Check for active subscriptions
  3. Drop the existing replication origin
  4. Drop the subscription properly (if applicable)
postgresql โ€” error
-- View all replication origins
SELECT * FROM pg_replication_origin;
-- View origins with their current replication status
SELECT * FROM pg_replication_origin_status;
ERROR: replication origin already exists

What this error means

This error is raised when PostgreSQL's logical replication system detects an attempt to create a replication origin that already exists. Replication origins are used to track the progress of logical replication from remote servers and are stored in the pg_replication_origin system catalog. Each replication origin must have a unique name. When you create a logical replication subscription, PostgreSQL automatically creates a corresponding replication origin. The error typically occurs when trying to manually create an origin with a name that's already in use, or when attempting to recreate a subscription that wasn't properly cleaned up. Replication origins are created using pg_replication_origin_create() and store metadata about replication progress, including the LSN (Log Sequence Number) position. If an origin with the same name already exists, PostgreSQL prevents creating a duplicate to avoid conflicts in replication progress tracking.

Typical symptoms

  • Error message appears when creating a logical replication subscription
  • pg_replication_origin_create() function fails with duplicate error
  • Subscription creation fails despite dropping the old subscription
  • Replication setup scripts fail on re-execution

Common causes

  1. Attempting to create a subscription with the same name as an existing one without dropping the old replication origin
  2. Previous subscription was dropped but its replication origin was not cleaned up
  3. Manual creation of a replication origin using a name that already exists in pg_replication_origin
  4. Failed or incomplete cleanup of logical replication subscriptions
  5. Scripts that create origins without checking for existing entries

How to fix "ERROR: replication origin already exists"

1Check existing replication origins

First, identify all existing replication origins in your database:

sql
-- View all replication origins
SELECT * FROM pg_replication_origin;

-- View origins with their current replication status
SELECT * FROM pg_replication_origin_status;

This shows you which origins exist and their current LSN positions. Look for the origin name causing the conflict.

2Check for active subscriptions

Verify if there are any active subscriptions that might be using the origin:

sql
-- List all subscriptions
SELECT subname, subenabled, subconninfo
FROM pg_subscription;

-- Check subscription slots
SELECT slot_name, plugin, slot_type, active
FROM pg_replication_slots;

If a subscription exists but should be removed, drop it first before dealing with the origin.

3Drop the existing replication origin

If the replication origin is no longer needed or needs to be recreated, drop it:

sql
-- Drop a specific replication origin by name
SELECT pg_replication_origin_drop('origin_name');

Replace 'origin_name' with the actual name of the conflicting origin. Note that this requires superuser privileges and will remove all associated progress tracking.

4Drop the subscription properly (if applicable)

If the origin belongs to a subscription, drop the subscription completely:

sql
-- Drop subscription (this should also clean up the origin)
DROP SUBSCRIPTION subscription_name;

In some cases, if the publisher is unavailable, you may need to force the drop:

sql
-- Force drop when publisher is unreachable
ALTER SUBSCRIPTION subscription_name DISABLE;
ALTER SUBSCRIPTION subscription_name SET (slot_name = NONE);
DROP SUBSCRIPTION subscription_name;
5Recreate the subscription or origin

After cleanup, you can now recreate the subscription or origin:

sql
-- Create new subscription (automatically creates origin)
CREATE SUBSCRIPTION my_subscription
CONNECTION 'host=source_host dbname=source_db user=repl_user password=xxx'
PUBLICATION my_publication;

Or manually create an origin if needed:

sql
-- Manually create replication origin
SELECT pg_replication_origin_create('my_origin_name');

Advanced notes

Replication Origin Naming: When PostgreSQL creates a replication origin for a subscription, it typically uses the format "pg_" followed by the subscription's OID. However, origins can also be created with custom names for manual replication setups.

Origin Persistence: Replication origins persist even after subscription drops in some failure scenarios, particularly if the connection to the publisher is lost during the drop operation. Always verify origins are cleaned up using pg_replication_origin catalog queries.

LSN Position Preservation: If you drop and recreate a replication origin, you lose the tracked LSN position. For production replication, consider using pg_replication_origin_advance() to manually adjust positions rather than dropping and recreating origins.

Bi-directional Replication: In bi-directional replication setups using origin filtering, origin names are critical for preventing replication loops. Ensure origin names are unique across all nodes and match your replication topology design.

Permissions: Both pg_replication_origin_drop() and pg_replication_origin_create() require superuser privileges or the pg_read_all_settings and pg_write_all_settings roles in newer PostgreSQL versions.

Catalog Queries: The pg_replication_origin system catalog uses an exclusive lock during origin creation/deletion. This is generally fast but can cause brief waits if multiple replication operations occur simultaneously.

Frequently asked questions

What does "ERROR: replication origin already exists" mean?
This error is raised when PostgreSQL's logical replication system detects an attempt to create a replication origin that already exists. Replication origins are used to track the progress of logical replication from remote servers and are stored in the pg_replication_origin system catalog. Each replication origin must have a unique name.
How do I fix "ERROR: replication origin already exists"?
This error occurs when attempting to create a replication origin with a name that already exists in the pg_replication_origin catalog, typically during logical replication setup or when manually creating origins.
What causes "ERROR: replication origin already exists"?
Attempting to create a subscription with the same name as an existing one without dropping the old replication origin Previous subscription was dropped but its replication origin was not cleaned up Manual creation of a replication origin using a name that already exists in pg_replication_origin
Is the "ERROR: replication origin already exists" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading