Quick Install of PostgreSQL from Git

Notes on switching from a packaged PostgreSQL to one built from source out of the official git repository. Platform was Ubuntu 12.04. We remove the packaged version and configure the new version for development.

We're currently migrating from MySQL to postgreSQL. Since we're developers and our database is core, we want to work with source. Before we begin, let's see which postgreSQL packages we already have installed on our system.

$ dpkg -l | grep postgresql
ii  postgresql                                  9.1+129ubuntu1                          object-relational SQL database (supported version)
ii  postgresql-9.1                              9.1.9-0ubuntu12.04                      object-relational SQL database, version 9.1 server
ii  postgresql-client-9.1                       9.1.9-0ubuntu12.04                      front-end programs for PostgreSQL 9.1
ii  postgresql-client-common                    129ubuntu1                              manager for multiple PostgreSQL client versions
ii  postgresql-common                           129ubuntu1                              PostgreSQL database-cluster manager

Let's remove postgresql including the database cluster and configuration files. However, let's first make sure we know how Ubuntu had everything configured.

$ ps -ef | grep postgresql
postgres 22864     1  0 17:47 ?        00:00:00 /usr/lib/postgresql/9.1/bin/postgres -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf

$ ls /etc/postgresql/9.1/main/
environment  pg_ctl.conf  pg_hba.conf  pg_ident.conf  postgresql.conf  start.conf

$ sudo ls /var/lib/postgresql/9.1/main/
base  global  pg_clog  pg_multixact  pg_notify	pg_serial  pg_stat_tmp	pg_subtrans  pg_tblspc	pg_twophase  PG_VERSION  pg_xlog  postmaster.opts  postmaster.pid  server.crt  server.key

$ which psql

$ ls -l /usr/bin/psql
lrwxrwxrwx 1 root root 37 Sep  7  2012 /usr/bin/psql -> ../share/postgresql-common/pg_wrapper

We perform a purge rather than remove since we want to remove the configuration files along with the packages.

$ sudo apt-get purge postgresql-client-common postgresql-common postgresql

Let's make sure everything has been removed. If not, we'll remove it:

$ dpkg -l | grep postgresql

$ dpkg -l | grep libpq
ii  libpq5                                      9.1.9-0ubuntu12.04                      PostgreSQL C client library

$ sudo apt-get purge libpq5

$ sudo apt-get autoremove

$ ls /etc/postgresql
ls: cannot access /etc/postgresql: No such file or directory

$ ls /var/lib/posgresql
ls: cannot access /var/lib/posgresql: No such file or directory

$ ls /usr/bin/psql
ls: cannot access /usr/bin/psql: No such file or directory

We want postgreSQL for development and learning, so let's download the git repo. We'll follow the official postgreSQL documentation, and there's a wiki page for Working with Git

$ mkdir -p $HOME/projects/postgresql
$ cd $HOME/projects/postgresql

$ git clone git://git.postgresql.org/git/postgresql.git

$ cd postgresql/
$ ls
aclocal.m4  config  configure  configure.in  contrib  COPYRIGHT  doc  GNUmakefile.in  Makefile  README  README.git  src

We're going to work with the 9.3 git branch, so let's do the following, which creates a local branch that tracks the remote branch:

git branch --track REL9_3_STABLE origin/REL9_3_STABLE
git checkout REL9_3_STABLE

We prefer to build outside the source directory, so let's create a new build directory and run configure from there. Note that you may need to install some packages before configure will succeed (e.g., libreadline-dev, systemtap-sdt-dev, zlib1g-dev, libssl-dev, libpam0g-dev, and python-dev). Also, make sure you have flex and bison installed. If you get stuck on finding a package missing during configure, then take a look at the Ubuntu Packages Search page.

$ ../postgresql/configure --with-python --with-openssl --with-pam --enable-debug --enable-depend --enable-dtrace

$ make

Note that configure has many build and install options. Type ../postgresql/configure --help for more information.

Next we need to install postgreSQL. We're happy to stay with the default path of /usr/local/postgresql. However, the default path can be overridden with the use of configure options (e.g., --prefix=<default path>)

$ sudo make install

Let's now do some checking and general housekeeping:

$ cd /usr/local/pgsql/
$ tree -d -L 2
├── bin
├── include
│   ├── informix
│   ├── internal
│   ├── libpq
│   └── server
├── lib
│   ├── pgxs
│   └── pkgconfig
└── share
    ├── extension
    ├── timezone
    ├── timezonesets
    └── tsearch_data

$ find . -name '*.conf.sample'

export PATH=$PATH:/usr/local/pgsql/		# add this to your .bashrc

Help us improve this article by adding your comment or question:

email addresses are neither displayed nor shared