Skip to content

Instantly share code, notes, and snippets.

@mrbongiolo
Last active March 21, 2019 16:18
Show Gist options
  • Save mrbongiolo/27e4166834bea1477f76 to your computer and use it in GitHub Desktop.
Save mrbongiolo/27e4166834bea1477f76 to your computer and use it in GitHub Desktop.
Install PostgreSQL 9.3 on a Ubuntu Precise VM (Vagrant)
# Add the public GPG key
wget -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# Create a file with the repository address
echo deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main | sudo tee /etc/apt/sources.list.d/postgresql.list
# Remove any older postgresql installation you may have (ex:)
sudo apt-get remove postgresql-9.1 postgresql-contrib-9.1 postgresql-client-9.1
# Install the PostgreSQL
sudo apt-get update
sudo apt-get install postgresql-9.3 postgresql-contrib-9.3
# Create the user to access the db. (vagrant sample)
sudo -u postgres psql -c "CREATE USER vagrant WITH SUPERUSER CREATEDB ENCRYPTED PASSWORD 'vagrant'"
# Change the port
sudo sed -i "s/port = 5433/port = 5432/" /etc/postgresql/9.3/main/postgresql.conf
# Restar de DB
sudo /etc/init.d/postgresql restart
## If you get a locale error follow those instructions
# error message: PG::InvalidParameterValue: ERROR: encoding "UTF8" does not match locale "en_US"
# generate the locales
sudo locale-gen en_US.UTF-8
sudo update-locale LANG=en_US.UTF-8
# drop and recreate the default cluster
sudo pg_dropcluster --stop 9.3 main
sudo pg_createcluster --start -e UTF-8 9.3 main
# recreate our database user
sudo -u postgres psql -c "CREATE USER vagrant WITH SUPERUSER CREATEDB ENCRYPTED PASSWORD 'vagrant'"
# SOURCES
- http://simplesideias.com.br/usando-postgresql-e-hstore-no-rails-4
- https://blog.lnx.cx/tag/locales-fix-slicehost-ubuntu/
- http://jacobian.org/writing/pg-encoding-ubuntu/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment