I am curious if it is more common for people to install postgres directly on their dev machine or if people are using a docker container for postgres?
Depends on the person you ask. I prefer local installation and I avoid Docker whenever I can.
For a development instance that is more about the development of application logic than figuring out operational concerns, I’ll do whatever is simplest. In my case I find that local database installation meets that definition. The only database I’ve worked with where database installation might be more difficult than getting a container setup running is Oracle. This assumes that you’re going for a pre-existing database image.
Of course, if you’ve already got a bunch of containers setup and running anyway, what’s one more? I think the key really is that just getting a database up and running for local development purposes usually doesn’t require fine-tuning the database. Many development needs can be met by a terribly badly tuned database (such as the defaults, depending on the database you’re using)… so long as it can run your queries, the amounts of data you’re working with in many local development scenarios are so small as to negate any optimizing work you could do with the database installation. Installing a database just using defaults is typically not much work.
Finally, this is a generalization. I have had gigs doing database work where applications were build around large pre-computed datasets, such as US Medicare data, which formed our starting point for the database even for local development. In those cases I still operated a directly installed database, but paid more attention to tuning the database for the system and workload; again it was a simpler path… one technology to setup/configure vs. two.
My main hesitation is having 50 developers in one company having various versions of postgres because they each installed it when they joined the company and they each upgrade randomly at their own pace. Maybe system installed, but centrally managed by something like custom macos appstore would be a nice compromise between simplicity and consistency.
do you install with the Postgres.app on macos? It suggests upgrades whenever new versions are available I believe. Maybe there’s an auto update setting as well
It really depends.
The last shop I worked in where we used postgres, the most common way to do it was to use
brew install postgres because everybody had standard-issue Macbooks. Nobody really had issues with postgres versions. Any postgres issues we did have were solved by using brew to uninstall and reinstall. There were a few people using Docker as well, though, so it was mixed. I think having everybody on MacOS (and it being a fairly small team of ~12 devs or so) is what saved us there.
If you’ve got a mix of people all with their own dev environments tailored to their personal tastes, then yeah, might wanna use Docker just to avoid all the thorny issues that can arise from everybody having different versions of the same software. That goes double if you’re in a bigger company.
Overall I don’t think it’s a huge deal. Unless the work you’re doing is very heavily focused on the db (e.g. some kind of analytics) then it doesn’t matter that much. SQL is SQL. As long as the db works…
Sure, but this concern suggests that you meant to ask a fundamentally different question: How is it best to manage local development database installations for teams of dozens of developers? There’s both a management component to that question and possible technical solutions that could be employed depending on the variables. For Elixir development in particular, I would speculate that the most common local development environment management techniques will not correctly answer that reposed question.
Even then there’s nuance to the question material to getting the answer you want. If you have developers on the lower end of the coder <-> engineer scale, where the quantity of developers is high or turnover is high, and/or the quality of management and management communication is often poor, then you’ll be needing to rely on technical solutions to automatically standardize developer environments. If the trust levels are sufficient, the developers are sufficiently capable to operate independently and according to clear instructions from management, the reliance on centralized management technologies can be minimized.
All in all I expect that the responses you receive to the original question will depart from what I perceive to be the intended question since I expect more Elixir practitioners here will be operating in environments with greater independence than you’re anticipating in your concern. The common experience/practice here will vary from your scenario.
I use Asdf to locally install a specific version of Postgres for each project. I typically put my Postgres data directory in my project’s
priv directory so that I don’t have to worry about the Postgres version being incompatible with the data in case some projects depend on wildly different versions of Postgres.
The nice thing is that since Asdf’s
.tool-versions file is checked in, any other devs on my team who use Asdf will be using the same version of the database, and any other devs on my team who don’t use Asdf can at least see the version number that everyone else is using.
I use docker to manage all the infrastructure my projects need, the DB being only one component of it. Everything goes into a
docker-compose.yaml. Whenever I check out the project on a new machine - or when another team member or whoever wants to work on my project - all they have to do is run
docker compose up and they have everything set up as I intended, with the right versions, port numbers and so on. It’s so convenient I don’t even think about going back to local installs, I’ve suffered enough
I’m really interested in doing the same. Please, do you have any guide on setting this up?
Also I have a side question about
asdf. Since I have already
postgresql installed locally via
apt (I use Ubuntu), should I unistall it before adding a
postgresql asdf plugin? I’m already using
elixir and some other packages.
I extracted some shell scripts into a new repo: GitHub - eahanson/db-scripts
I don’t think you need to uninstall other versions of Postgres that aren’t installed via Asdf.
Great, really nice ! Thank you for sharing this. ^^
Even though I use nixos and it would be relatively easy to create even throwaway DB instances, I prefer to use some container stack for auxiliary services during development.
Usually it’s easier to manage their lifecycle in bulk operations, also it is what I can expect contributors to be able to use as well.
Though for everything that I actually run, I prefer properly set up services that run on the host.