Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save johnnncodes/53dc1fd0cbe90825afae45031a4e1457 to your computer and use it in GitHub Desktop.
Save johnnncodes/53dc1fd0cbe90825afae45031a4e1457 to your computer and use it in GitHub Desktop.
Configure PostgreSQL in a Vagrant guest to allow connections from the host.

Configure Postgres

  • Update pg_hba.conf (most likely in /etc/postgresql/9.4/main) with -
    • host all all 0.0.0.0/0 trust
  • Update postgresql.conf to use listen_addresses = '*'
  • Be sure to sudo service 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