Search code examples
postgresqlpatroni

Can you change pg_hba.conf using patronictl?


If you want to change pg_hba.conf in an existing patroni cluster. Can you do it via patronictl or do you have to signal one by one?

The code does not seem to have it after a quick look


Solution

  • Patroni can manage your pg_hba.conf from the centralized configuration. You need to use patronictl edit-config to add the following pg_hba.conf lines:

    postgresql:
      # ...
      pg_hba:
        - local all postgres  ident
        - host all all 0.0.0.0/0 md5
        - host replication replicator 0.0.0.0/0 md5
    

    You need to be careful though, make sure that your local superuser, and cluster wide replication and rewind user connections work. Once you add this to the config it will be picked up by Patroni and existing pg_hba.conf will be replaced within the next 10s.

    If you want to spare yourself converting an existing pg_hba.conf to yaml, the following shell pipeline will take a text file containg pg_hba.conf rules and applies it to an existing cluster:

    cat pg_hba.conf | jq -R -s 'split("\n") | {"postgresql": {"pg_hba": .}}' | \
      patronictl edit-config --apply - --force mycluster