How to Auto Generate pg_hba.conf file at Startup

Hi there,

I'll start by letting you you know my current shell programming and scripting is very week (and thats a euphemistic description). I'm really just wanting someone to make a suggestion to get me rolling in the right direction though absolutely any help is of course welcome.

Set Up

  • Running multiple servers using Amazons EC2 service
  • One primary postgres DB
  • Multiple application servers all needing access to the DB
  • This set up is monitored for loading and should the load exceed the set parameters another application server instance is spun up

The problem

  • Although the domain names remain static the IPs do not and so when the server farm is started or suspended (as is often the case for the dev farm) and started again the IP addresses change. I can't do anything about this. This is just what I have to work with.
  • Of course with constantly shifting IP addresses it means that I constantly need to log in and adjust the pg_hba.conf file.

The Solution

  • Write a script that fires once the data drive has mounted that queries the domain names of the other existing servers in the farm returning their IP addresses and writing them to the pg_hba.conf file and subsequently reloading the settings or starting the server.

these are the steps as I see it...
1) copy a template pg_hba.conf file over the top of the existing one.
2) in a loop query a set of domain names and append each resulting IP address to the bottom of the new pg_hba.conf file (Line to be appended:"host all all xxx.xxx.xxx.xxx/32 trust"
3) Start/Reload the postgres service

I'm not sure what I am going to do when new servers spin up... Any suggestion about that would be welcome.

The Questions!!

  • Should I be doing this with a shell script?
  • Would I be better to say write a java server that does all this and remains constantly listening on a given port (would solve the issue of additional servers spinning up)?
  • Where should I start?
  • How should I go about it?

Once I have this nailed of course I'll be happy to share :slight_smile: