-
-
Save fredrickwampamba/098e52ec44a32c1cbfe3b23f8d10490f to your computer and use it in GitHub Desktop.
Installing PostgreSQL 9.2 on Ubuntu 12.04 for rails development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Installing PostgreSQL 9.2 on Ubuntu 12.04 for rails development | |
#Add repo | |
sudo apt-get -y install python-software-properties | |
sudo add-apt-repository ppa:pitti/postgresql | |
sudo apt-get update | |
#install psql 9.2 and libpq | |
sudo apt-get -y install postgresql-9.2 postgresql-client-9.2 postgresql-contrib-9.2 | |
sudo apt-get -y install postgresql-server-dev-9.2 libpq-dev | |
# After Installation Log into the postgresql prompt before that set up a password for psql | |
sudo passwd postgres | |
# Enter the psql command prompt | |
su - postgres | |
# create db | |
createdb dbname | |
#drop db | |
dropdb dbname | |
#list all database | |
psql -l | |
# Now create the user for a database to be used for your project for my case its geomap | |
# P- issue a prompt for the password | |
# d- create a db of same name as user | |
# a- allow user to add new users (superuser) | |
# e- Echo the commands that createuser generates and sends to the server. | |
createuser -P -d -a -e geomap | |
#In case you want to create another db with this owner(user) | |
createdb geomap_development --owner=geomap | |
#Now into your rails app (mine is running on rails 3.2.13 with ruby 1.9.2) Add the gem pg into the Gemfile and install it by bundler | |
#Make sure you have the database created before you fill in the details here. for production please refer to a more detailed process | |
#For postgresql the config/database.yml file looks like this | |
development: | |
adapter: postgresql | |
encoding: utf8 | |
database: geomap_development | |
username: geomap | |
password: xxxx | |
host: localhost | |
test: | |
adapter: postgresql | |
encoding: utf8 | |
database: geomap_test | |
username: geomap | |
password: xxxx | |
host: localhost | |
production: | |
adapter: postgresql | |
encoding: utf8 | |
database: geomap_test | |
username: geomap | |
password: xxxx | |
host: localhost | |
#Now in the folder of your rails app: | |
~/geomap$ rake db:migrate | |
# restart the server | |
---------------------------------------------------------------------------- | |
# Trouble shooting | |
1. In case you have to remove postgres 9.2 | |
Ans: | |
# List all the postgresql installs running on the system | |
dpkg -l | grep postgres | |
# Remove postgres | |
sudo apt-get --purge remove postgresql-9.2 postgresql-client-9.2 postgresql-contrib-9.2 | |
# Remove individual postgres folders | |
sudo rm -rf /var/lib/postgresql/ | |
sudo rm -rf /etc/postgresql | |
# Rerun the command given below and it should return nothing | |
dpkg -l | grep postgres | |
#delete users and groups if any; if /var/lib/postgresql folder is deleted the users and groups are deleted. | |
sudo userdel -r postgres | |
sudo groupdel -r postgres | |
2. During reinstallation If you fail with | |
Creating new cluster (configuration: /etc/postgresql/9.2/main, data: /var/lib/postgresql/9.2/main)... | |
FATAL: could not create shared memory segment: Invalid argument | |
DETAIL: Failed system call was shmget(key=1, size=1835008, 03600). | |
Usually Hint will tell you that Shared kernel memory is zero shmmax | |
Ans: | |
#run the command given below and look for shmmax | |
sysctl -a | grep shm | |
# If kernel.shmmax=0 then edit /etc/sysctl.conf and set kernel.shmmax = 2147483648 | |
#Please read the literature before setting shmmax values for your kernel and refer to other sources. | |
#Restart the system configuration setting | |
sudo /sbin/sysctl -p | |
#create pg_cluster | |
sudo pg_createcluster 9.2 main --start | |
sources: | |
1. Chen https://gist.github.com/chen206/4030441 Use it for detailed installation | |
2. PostgreSQL 9.2 Documentation | |
3. stackoverflow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment