How Can I Edit Pg_Hba. Conf Programmatically?

How Can I Edit Pg_Hba. Conf Programmatically?

I'm looking for a way to edit pg_hba.conf programmatically, similar to how pg_conftool allows you to edit postgresql.conf:

~$ pg_conftool 11 main set timezone 'UTC'

I tried using pg_conftool to edit pg_hba.conf. Unfortunately, it only allows key = value entries to be added / removed, which is not the format pg_hba.conf expects.

I can use echo and sed to achieve what I want, but I'm wondering if there's a better way. I found a tool pg_hba in postgresql-common that seems to be what I'm looking for:

I have postgresql-common version 201.pgdg18.04+1 installed, however, I can't figure out how to access / install / invoke pg_hba.

Is the pg_hba tool the right tool for the job? If yes, how do I "install" the pg_hba binary for Ubuntu? If no, is there another recommended approach for programmatically editing pg_hba.conf?

1

1 Answer

We don't have a good way for editing pg_hba.conf yet. The pg_hba binary you found is still a WIP. If it works for you, please tell us, and we can work out if installing it to /usr/bin makes sense.

What works now is "pg_conftool 11 main pg_hba.conf edit", but that will just give you an editor.

Another option might be , it has a Pg_Hba "lens". (Puppet supports that natively.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.