The error message "replication slots can only be used if max_replication_slots > 0" typically occurs in PostgreSQL when you are trying to create a replication slot but the maximum number of replication slots allowed on the server is set to zero.

Replication slots are used in PostgreSQL to track the progress of replication and ensure that the standby servers do not fall too far behind the primary server. They are especially useful in streaming replication setups.

To resolve this issue, you need to increase the max_replication_slots configuration parameter in your PostgreSQL server to a value greater than zero. By default, this parameter is set to zero, which means that replication slots are not allowed.

Here's how you can increase the max_replication_slots parameter:

  1. Edit the PostgreSQL Configuration File: Open the postgresql.conf file, which is usually located in the data directory of your PostgreSQL installation. The location of the configuration file may vary depending on your operating system and PostgreSQL setup.

    For example, on Linux, you might find it at /etc/postgresql/<version>/main/postgresql.conf.

  2. Change the Configuration Parameter: Look for the max_replication_slots parameter in the configuration file. If it is set to zero, change it to a value greater than zero.

    For example, set max_replication_slots = 5 to allow a maximum of 5 replication slots.

  3. Restart PostgreSQL: After making the changes to the configuration file, restart the PostgreSQL server to apply the new configuration.

    On Linux, you can restart PostgreSQL using the following command:

    sudo systemctl restart postgresql

    The exact command may differ depending on your operating system and how PostgreSQL is installed.

After increasing the max_replication_slots parameter and restarting PostgreSQL, you should be able to create replication slots without encountering the "replication slots can only be used if max_replication_slots > 0" error.

Have questions or queries?
Get in Touch