Skip to content

Instantly share code, notes, and snippets.

@yarox
Forked from carymrobbins/setup-postgresql-vagrant.md
Last active March 2, 2018 17:33
Show Gist options
  • Save yarox/0d23949be420255148850ad255db3af7 to your computer and use it in GitHub Desktop.
Save yarox/0d23949be420255148850ad255db3af7 to your computer and use it in GitHub Desktop.
Configure PostgreSQL in a Vagrant guest to allow connections from the host.

Configure PostgreSQL

  • Add host all all 0.0.0.0/0 trust to /etc/postgresql/<version>/main/pg_hba.conf
  • Update /etc/postgresql/<version>/main/postgresql.conf to use listen_addresses = '*'
  • Restart the server with sudo /etc/init.d/postgresql restart

Configure Vagrant

  • Add config.vm.network :forwarded_port, host: 5432, guest: 5432 to the Vagrant.configure block in your Vagrantfile.

Test your connection

  • Attempt to connect from your host using psql -h localhost -U vagrant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment