Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.