Help Center/ Data Replication Service/ Troubleshooting/ Failure Cases/ Real-Time Synchronization from PostgreSQL to PostgreSQL/ Full or Incremental Phase Error: Initialize logical replication stream failed, the source database may have a long transaction
Updated on 2024-11-30 GMT+08:00

Full or Incremental Phase Error: Initialize logical replication stream failed, the source database may have a long transaction

Scenarios

During a full or incremental synchronization, an error is reported, and the log information is as follows: service LOGMANAGER failed, cause by: Initialize logical replication stream failed, the source database may have a long transaction: ***

Possible Causes

A logical replication slot fails to be created in the source database.

Solution

  1. Check whether the number of replication slots in the source database reaches the upper limit. If yes, delete replication slots that are no longer used from the source database or increase the value of max_replication_slots and restart the source database.

    • Run the following command to query the number of logical replication slots:
      select count(1) from pg_replication_slots;
    • Run the following command to query the maximum number of logical replication slots:
      select setting as number from pg_settings where name = 'max_replication_slots';

  2. Check whether the source database has long transactions that are not submitted. If yes, slot creation times out. As a result, the task fails.

    • Run the following command to query a transaction status:
      select pid, datname, state, backend_xid, xact_start, (now() - xact_start) as cost from pg_stat_activity where backend_xid is not null order by xact_start;
    • Run the following command to stop a long transaction:
      select pg_terminate_backend(pid);