Dragonfly

Question: How do I stop PostgreSQL replication?

Answer

Stopping PostgreSQL replication involves different approaches depending on your setup (e.g., streaming replication, logical replication). Below, we provide guidance for both common types.

Streaming Replication

For a Streaming Replication setup, follow these steps:

  1. On the Standby: Stop the PostgreSQL service to ensure it no longer connects to the primary database.
    ```bash
    sudo systemctl stop postgresql
    ```
  2. On the Primary: Identify and remove the replication slot (if used) to prevent the primary from retaining WAL files unnecessarily.
    ```sql
    SELECT pg_drop_replication_slot('slot_name');
    ```
    Replace 'slot_name' with the name of your replication slot.
  3. Configuration Cleanup: On the primary, you may also want to remove or comment out any replication-related configuration in postgresql.conf and pg_hba.conf, such as max_replication_slots, max_wal_senders, and any specific replication user access rules.
  4. Restart the Primary (optional): If you made changes to the configuration files on the primary server, restart PostgreSQL to apply them.
    ```bash
    sudo systemctl restart postgresql
    ```
  5. Replication Slot Check: It's good practice to check if the replication slot has been successfully removed.
    ```sql
    SELECT * FROM pg_replication_slots;
    ```

Logical Replication

In the case of Logical Replication, here is what you need to do:

  1. Drop Subscription (on the subscriber database):
    ```sql
    DROP SUBSCRIPTION subscription_name;
    ```
  2. Drop Publication (on the publisher database):
    ```sql
    DROP PUBLICATION publication_name;
    ```
  3. Configuration Review: Similar to streaming replication, review and adjust any logical replication-specific configurations within postgresql.conf and pg_hba.conf.

Note: Always ensure you have backups before making significant changes to your database infrastructure, especially when stopping replication processes."

Additional Tips

Was this content helpful?

Other Common PostgreSQL Questions (and Answers)

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost