Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sergiocampama
Created November 7, 2012 19:33
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save sergiocampama/4033846 to your computer and use it in GitHub Desktop.
Save sergiocampama/4033846 to your computer and use it in GitHub Desktop.
Postgresql 9.2.1 Installation instructions for Ubuntu 12.04
#Postgresql 9.2.1 Compilation instructions for Ubuntu 12.04
#This will install Postgresql 9.2.1 into /usr/local/postgresql-9.2.1
#This assumes that you have sudo provileges on the machine installing postgresql
#It should work by copying and pasting into the shell, I haven't tested it, I just summarized
#what I just did and it worked
#Get requirements
sudo apt-get install build-essential libreadline6-dev zlib1g-dev
#Download and decompress
cd
mkdir temp
cd temp
wget ftp://ftp.postgresql.org/pub/source/v9.2.1/postgresql-9.2.1.tar.gz
tar xzvf postgresql-9.2.1.tar.gz
#Configure, compile and check if successful
cd postgresql-9.2.1
./configure --prefix=/usr/local/postgresql-9.2.1
make
make check
#If successful, install
sudo make install
#Now, we'll install the init.d script that will start postgresql on start
sudo cp contrib/start-scripts/linux /etc/init.d/postgresql
sudo chmod +x /etc/init.d/postgresql
#You should change lines 32 and 35 to the real path to the installation
sudo sh -c "sed -i -e '32s/^.*$/prefix=\/usr\/local\/postgresql-9.2.1/g' /etc/init.d/postgresql"
sudo sh -c "sed -i -e '35s/^.*$/PGDATA=\"\/usr\/local\/postgresql-9.2.1\/data\"/g' /etc/init.d/postgresql"
#And save. Issue an update-rc.d to make it start on boot
sudo update-rc.d postgresql defaults
#Now create a file in /etc/profile.d that sets the postgres path. Enter the following
sudo sh -c "echo 'PATH=/usr/local/postgresql-9.2.1/bin:\$PATH' > /etc/profile.d/pg.sh"
sudo sh -c "echo 'export PATH' >> /etc/profile.d/pg.sh"
#Save. Now configure the libraries to be found by the programs
sudo ldconfig /usr/local/postgresql-9.2.1/lib/
#Postgres uses a data folder to store the databases, which needs to be owned by the postgres user, so
#create the user for postgresql to run on
sudo useradd --shell /bin/bash postgres
#Create the folder and set permissions
sudo mkdir /usr/local/postgresql-9.2.1/data
sudo chown -R /usr/local/postgresql-9.2.1/data postgres
#Postgresql needs the data folder to be initialized, using the postgres user. This next command
#also sets the superuser password for the database and configures locales
sudo su postgres
/usr/local/postgresql-9.2.1/bin/initdb -D /usr/local/postgresql-9.2.1/data --pwprompt -A password --locale=en_US.UTF-8
exit
#Start the server
sudo /etc/init.d/postgresql start
#To check if it is running you can issue `netstat -l` and look for a postgres line, or do
/usr/local/postgresql-9.2.1/bin/psql -U postgres
#Enter the superuser password an hack away. You should now close and reopen the terminal to load the new PATH and
#psql -U postgres should work without having to append it's path
#Check the official docs on how to create roles for webapps (http://www.postgresql.org/docs/9.2/interactive/index.html)
#Any comments or suggestions on this guide please make them in the
#comments below or sending me an e-mail to sergiocampama@gmail.com
@haiiiiiyun
Copy link

Thanks for your script.

When I tested it on my Ubuntu 12.10 server,

line 59 raised an error, after I changed line 59 to "sudo chown -R postgres /usr/local/postgresql-9.2.1/data", it worked well.

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