Patroni edit pg_hba.conf

To edit the pg_hba.conf file in Patroni, you can follow these steps:

  1. Connect to the server hosting the Patroni cluster.
  2. Locate the pg_hba.conf file. It is usually present in the PostgreSQL data directory.

    Example:

    If your PostgreSQL data directory is /var/lib/postgresql/12/main, then the pg_hba.conf file can be found at /var/lib/postgresql/12/main/pg_hba.conf.
  3. Open the pg_hba.conf file using a text editor.

    Example:

    You can use the vi editor by running the command:

    vi /var/lib/postgresql/12/main/pg_hba.conf
  4. Locate the section corresponding to the database or user you want to modify access for.
  5. Update the access control rules based on your requirements. The format of each rule follows:

    type database user CIDR-address auth-method [auth-option]

    Example:

    Suppose you want to allow all users from the IP address range 192.168.0.0/24 to access a specific database. You can add the following line to the pg_hba.conf file:

    host mydatabase all 192.168.0.0/24 md5

    This rule allows all users (all) to connect to the database named mydatabase using the md5 authentication method from any IP address within the 192.168.0.0/24 range.
  6. Save the changes to the pg_hba.conf file and exit the text editor.
  7. Restart Patroni or PostgreSQL for the changes to take effect.

    Example:

    You can restart the patroni service by running the command:

    systemctl restart patroni

This is a basic guide to editing the pg_hba.conf file in Patroni. Make sure to take backups and exercise caution while modifying the file, as incorrect configuration can lead to access issues.

Leave a comment