Why does the query used to create the replication slot get stuck when I run it on a PostgreSQL read replica?
This behavior can occur when long-running transactions are active on the primary PostgreSQL database. Although the replication slot is created on a read replica, PostgreSQL performs this operation in coordination with the primary database instance. While such transactions are in progress, the resources required to create the replication slot may already be in use. As a result, PostgreSQL cannot complete the slot creation request immediately, and the query continues to run and appears stuck while it waits for the ongoing operations to finish.
Long-running operations can include:
-
Bulk data updates or deletes
-
Database maintenance tasks
-
Reporting or analytics queries
-
Custom scripts that keep transactions open
During such activity, PostgreSQL prioritizes completing active transactions before allocating resources to create a replication slot.
To resolve this issue, perform the following actions:
-
Check the primary database instance for long-running transactions and wait for them to complete before creating the replication slot.
-
Ensure that processes such as reporting or analytics queries, database maintenance jobs, or custom scripts do not leave transactions open for long durations, as this can delay replication-related operations.