Thursday, 20 February 2014

Chapter 2 - Database installation

This chapter will cover the install procedure, on Debian Gnu linux compiling from source and using the packaged install from the pgdg archive.

Install from source

Installing from source, using the default configuration settings requires the root access as the default install location is in /usr/local/. To simplify things I've created a procedure with minimal need for root access. This of course is still required but only for the os user creation and to install the dependencies.
Before starting with the postgresql part, ask your sysadmin, or do it by yourself, to do the following

  • Create a postgres group and a postgres user
  • Add the postgres user to the postgres group
  • Install the packages
  • build-essential
  • libreadline6-dev
  • zlib1g-dev
When everything is in place login as postgres user and download the source's tarball.
mkdir download cd download wget http://ftp.postgresql.org/pub/source/v9.3.2/postgresql-9.3.2.tar.bz2
Extract the tarbal with
tar xfj postgresql-9.2.3.tar.bz2 cd postgresql-9.2.3
The configure script have the -prefix option to set the install directory in a custom location. Assuming the postgres user have his home directory in /home/postgres, we'll put the install target into the bin directory organised per mayor version. In this way is possible to have multiple versions on the same box whitout hassle.
mkdir -p /home/postgres/bin/9.3 ./configure -prefix=/home/postgres/bin/9.3
The script will check all the dependencies and will generate the makefiles. Any error at configure time is usually explained good.
When everthing looks fine you can start the build process with the make command. The time required to compile depends from the box speed. On a laptop usually this doesn't require more than 30 minutes.
After the build is complete is a good idea to run the regression tests before installing.
To do it simply run make check.
All the output is written in the directory src/test/regress/results.
If everything is fine you can complete the installation with
make install
After this, into the /home/postgres/bin/9.3 directory will appear with 4 subfolders bin include lib and share.
The bin folder is the place of the database binaries, like the client psql or the server postgres.
The include folder is the place for the server's header files.
The lib folder is the location for all shared libraries and functions used by the database installation.
In the share folder you'll find the example files and the extension.

Packaged install

The PostgreSQL Global Group mantains an apt repository to simplify the install on the GNU/Linux based on debian.
The supported Linux versions are listed on the wiki page http://wiki.postgresql.org/wiki/Apt and at moment are

  • Debian 6.0 (squeeze)
  • Debian 7.0 (wheezy)
  • Debian unstable (sid)
  • Ubuntu 10.04 (lucid)
  • Ubuntu 12.04 (precise)
  • Ubuntu 13.10 (saucy)
  • Ubuntu 14.04 (trusty)
The packages are available for amd64 and i386.
The available database versions are
  • PostgreSQL 8.4
  • PostgreSQL 9.0
  • PostgreSQL 9.1
  • PostgreSQL 9.2
  • PostgreSQL 9.3
Before starting you shall import the GPG key to validate the packages.
In a root shell simply run wget -quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Then add the file pgdg.list into the directory /etc/apt/sources.d/ with the following contents
deb http://apt.postgresql.org/pub/repos/apt/ codename-pgdg main
Change the codename value accordingly with your distribuition. (e.g. wheezy) then you can run
apt-get update
To install the full set of binaries simply run
apt-get install postgreql-9.3 postgreql-contrib-9.3 postgreql-client-9.3
This will set up also a database cluster up and running.

1 comment: