Securing and Optimizing Linux: RedHat Edition -A Hands on Guide | ||
---|---|---|
Prev | Chapter 27. Linux PostgreSQL Database Server | Next |
First of all, to avoid security risks, we'll create an unprivileged user account named postgres to be the owner of the Postgres files.
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 || : |
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 |
- Enable locale support. |
Edit the Makefile.global file, vi +210 Makefile.global and change the line:
CFLAGS= -I$(SRCDIR)/include -I$(SRCDIR)/backend |
CFLAGS= -I$(SRCDIR)/include -I$(SRCDIR)/backend -O9 -funroll-loops -ffast-math -malign-double -mcpu=pentiumpro -march=pentiumpro -fomit-frame-pointer -fno-exceptions |
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 |
The make command compiles all source files into executable binaries.
The make install command installs the binaries and any supporting files into the appropriate locations.
The mkdir will create a new directory named pgsql under the /usr/include and /usr/lib directories,
and then we move all subdirectories and files related to PostgreSQL under /usr/include and /usr/lib directories to the /usr/include/pgsql and /usr/lib/pgsql directories respectively with the command mv.
The chown command will set the correct owner and group permission for the /var/lib/pgsql directory.
The strip command will discard all symbols from the object files. This means that our binary file will be smaller in size. This will improve the performance hit to the program since there will be fewer lines to read by the system when it executes the binary.
The rm command will remove the global1.description and local1_template1.description files that are not needed by our PosgreSQL program.