kiere / vagrant-phoenix-postgres

Vagrant VM build for Elixir/Phoenix/PostgreSQL development. Includes nodejs 0.12 and Git.
13 stars 10 forks source link

Why are PostrgreSQL ports forwarded #1

Closed wende closed 8 years ago

wende commented 8 years ago

Hello. First of all I love your Vagrant config. It's exactly what I needed. Although when launching on my machine it rejects to raise Vagrant because of port 5432 being taken. I see it's a port for PostreSQL. I'm a Vagrant newbie and wanted to ask why are ports for the database forwarded. Shouldn't the DB be located on the VM instead of the host?

Cheers, Chris

kiere commented 8 years ago

Hey Chris,

Yes, the ports are forwarded so that I can run a Postgres client on my Mac without modifying ports in my connection options. Since I usually only have one Postgres VM running at a time, this makes it look like the database is running on my local machine. But when I'm done, I just shut down the VM and I no longer have a database taking up resources in the background.

If you have Postgres running locally on your machine, you can set a different port for HOST in your Vagrantfile as long as the GUEST port is still 5432. You would then tell your Postgres client which port you want in the connection options (5432 for the local db and <whatever host port from Vagrantfile> for the VM db).

The issue you described can also happen when you leave a VM running by accident and try and start a second one. If you need multiple db servers running simultaneously, you'd need to specify different ports in each Vagrantfile.

Hope that helps, Kiere

kiere commented 8 years ago

I should also add that I don't always develop inside the VM. That might be a confusing point that I didn't clarify. Sometimes I use editors and clients on my Mac that just connect to the db in the VM. For this particular Vagrant config, I installed erlang/elixir/Phoenix on the VM even though I haven't really needed them there yet. I've just been playing with Elixir/Phoenix locally on my Mac, connected to the Postgres instance in the VM (hence the port forwarding).

wende commented 8 years ago

Thank you a lot! That has cleared out everything to me. Glory to Alchemists and merry christmass :gift: