Skip to content

Instantly share code, notes, and snippets.

@haknick
Created November 10, 2013 06:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save haknick/7394776 to your computer and use it in GitHub Desktop.
Save haknick/7394776 to your computer and use it in GitHub Desktop.
Mac Vagrant Postgresql 9.1 - Provisioning snippet
# On Mavericks (same for 10.6+) the biggest issue is that port 5432 is already taken so
# this: --- config.vm.network "forwarded_port", guest: 5432, host: 5433' ---
# should go on 'Vagrantfile' and then you use port 5433 to connect through pgadmin3
echo >&2 "===CUSTOM-MSG=== Setup THE DATABASE"
# installs postgresql database and creates "vagrant" superuser with password "somepass".
sudo apt-get -y install postgresql postgresql-client libpq-dev
echo >&2 "===CUSTOM-MSG=== Create role and login"
sudo su postgres -c "psql -c \"CREATE ROLE vagrant SUPERUSER LOGIN PASSWORD 'somepass'\" "
# create database 'mynewdb' for role (superuser) vagrant
echo >&2 "===CUSTOM-MSG=== Create db"
sudo su postgres -c "createdb -E UTF8 -T template0 --locale=en_US.utf8 -O vagrant mynewdb"
# enable the db to listen from the host through tcp
sudo su postgres -c "printf \"\n\n# === CUSTOM VAGRANT SETTINGS === \n \" >> /etc/postgresql/*/main/postgresql.conf"
sudo su postgres -c "echo \" listen_addresses = '*' \" >> /etc/postgresql/*/main/postgresql.conf"
sudo su postgres -c "printf \"\n\n# === CUSTOM VAGRANT SETTINGS === \n \" >> /etc/postgresql/*/main/pg_hba.conf"
sudo su postgres -c "echo \" host all all 10.0.2.2/24 md5 \" >> /etc/postgresql/*/main/pg_hba.conf"
#restart
sudo /etc/init.d/postgresql restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment