27.2. Compile and Optimize

First of all, to avoid security risks, we'll create an unprivileged user account named postgres to be the owner of the Postgres files.

  1. To create the Postgres account, use the following command:
    
                   [root@deep] /# useradd -M -o -r -d /var/lib/pgsql -s /bin/bash -c "PostgreSQL Server" -u 40 postgres >/dev/null 2>&1 || :
                     

  2. Move into the new PosgreSQL directory we have untarred earlier, and then move to its subdirectory named src. Type the following commands on your terminal:
    
                   [root@deep] /# cd /var/tmp/postgresql-6.5.3
                       [root@deep ]/postgresql-6.5.3# cd src
                       CC="egcs" \
                       ./configure \
                       --prefix=/usr \
                       --enable-locale
                     
    This tells PostgreSQL to set itself up for this particular hardware setup with:

    - Enable locale support.

  3. Edit the Makefile.global file, vi +210 Makefile.global and change the line:
    
                   CFLAGS= -I$(SRCDIR)/include -I$(SRCDIR)/backend
                     
    To read:
    
                   CFLAGS= -I$(SRCDIR)/include -I$(SRCDIR)/backend -O9 -funroll-loops -ffast-math -malign-double -mcpu=pentiumpro -march=pentiumpro -fomit-frame-pointer -fno-exceptions
                     
    These are our optimization flags for the PostgreSQL Server. Of course, you must tailor them to fit your system and CPU architecture.

Now, we must compile and install PosgreSQL on to the server:

                 [root@deep ]/src# make all
                 [root@deep ]/src# cd ..
                 [root@deep ]/postgresql-6.5.3# make -C src install
                 [root@deep ]/postgresql-6.5.3# make -C src/man install
                 [root@deep ]/postgresql-6.5.3# mkdir -p /usr/include/pgsql
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/access  /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/commands  /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/executor  /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/lib  /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/libpq  /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/libpq++  /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/port  /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/utils  /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/fmgr.h /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/os.h /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/config.h /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/c.h /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/postgres.h /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/postgres_ext.h /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/libpq-fe.h /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/libpq-int.h /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/ecpgerrno.h /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/ecpglib.h /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/ecpgtype.h /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/sqlca.h /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/include/libpq++.H /usr/include/pgsql/
                 [root@deep ]/postgresql-6.5.3# mkdir -p /usr/lib/pgsql
                 [root@deep ]/postgresql-6.5.3# mv /usr/lib/*source /usr/lib/pgsql/
                 [root@deep ]/postgresql-6.5.3# mv /usr/lib/*sample /usr/lib/pgsql/
                 [root@deep ]/postgresql-6.5.3# mkdir -p /var/lib/pgsql
                 [root@deep ]/postgresql-6.5.3# chown -R postgres.postgres /var/lib/pgsql/
                 [root@deep ]/postgresql-6.5.3# chmod 755 /usr/lib/libpq.so.2.0
                 [root@deep ]/postgresql-6.5.3# chmod 755 /usr/lib/libecpg.so.3.0.0
                 [root@deep ]/postgresql-6.5.3# chmod 755 /usr/lib/libpq++.so.3.0
                 [root@deep ]/postgresql-6.5.3# strip /usr/bin/postgres
                 [root@deep ]/postgresql-6.5.3# strip /usr/bin/postmaster
                 [root@deep ]/postgresql-6.5.3# strip /usr/bin/ecpg
                 [root@deep ]/postgresql-6.5.3# strip /usr/bin/pg_id
                 [root@deep ]/postgresql-6.5.3# strip /usr/bin/pg_version
                 [root@deep ]/postgresql-6.5.3# strip /usr/bin/pg_dump
                 [root@deep ]/postgresql-6.5.3# strip /usr/bin/pg_passwd
                 [root@deep ]/postgresql-6.5.3# strip /usr/bin/psql
                 [root@deep ]/postgresql-6.5.3# rm -f  /usr/lib/global1.description
                 [root@deep ]/postgresql-6.5.3# rm -f  /usr/lib/local1_template1.description