I'm using a library that only supports password authenticated login to psql. So solve this I've edited the pg_hba.conf file as per the doc.

I have a scripted install of my app and psql, and would like to enable local password login problematically from this bash script. Is there a more clever way than using sed or something similar? It sounds a bit "hackish" to alter the config and restarting the service.

  • Hi. Are you looking to login with cmd on a local machine (assuming that you are logged in on Linux)? Apr 16 '19 at 10:00
  • Aside: if you really are using PostgreSQL 9.1 (since it is in the link you provide), you should really try to upgrade... Apr 17 '19 at 23:18
  • 1
    If you have a scripted install of your application and PostgreSQL, why can't you ship your PostgreSQL install with a specific pg_hab.conf that is already formatted the way you need it for your application/library connecting to it? No need to change it afterwards. Apr 17 '19 at 23:20
  • They are not always compatible with all versions of PSQL DB.
    – psv
    Apr 25 '19 at 8:34

This would be a task for a decent config management implementing idempotent actions.

For example ansible has a module called lineinfile for this particular job.

I'm not sure whether it's the best solution to directly edit file pg_hba.conf. Maybe you want to create the database and explicitly add users with the ansible modules for Postgresql.

Implementing ansible just for this requirement might seem a bit heavy-weight but your question heads in a direction of automating things anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.