Skip to content

Instantly share code, notes, and snippets.

@carymrobbins
Last active May 4, 2023 10:22
Show Gist options
  • Save carymrobbins/39b75df64a1201407c80 to your computer and use it in GitHub Desktop.
Save carymrobbins/39b75df64a1201407c80 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
@CacheMoneyPlaya
Copy link

Perfect, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment