1. Download latest postgresql-XXX.tar.gz (where XXX is a release number) distribution of postgres database. At the time of writing this document 8.2 is the latest release.
2. Due to built-in security reasons, postgres cannot run as a root user. Therefore, become a superuser and create a postgres group. Then add a user postgres to the group as follows;
sudo su - root (become a superuser)
groupadd postgres (create a postgres group)
useradd postgres –g postgres (create a postgres user)
3. Extract the tar file into /usr/local directory. This should create a postgresql-XXX subdirectory in /usr/local.
cd /usr/local
gunzip -c /path-to-file/postgresql-XXX.tar.gz | tar xvf -
4. create a /usr/local/pgsql directory where postgres database will be installed.
mkdir /usr/local/pgsql
5. Assign ownership of directories created above to postgres user.
chown -R postgres.postgres /usr/local/pgsql
chown -R postgres.postgres /usr/local/postgresql-XXX
6. Switch to postgres user from superuser.
su - postgres
7. Configure and prepare postgres for installation.
./configure
gmake
If successful, the last line displayed should be as below.
"All of
8. start installation
gmake install
9. Set environment variables. Add following to .bashrc in home directory of postgres user. For example, /home/postgres
LD_LIBRARY_PATH=/usr/local/pgsql/lib
export LD_LIBRARY_PATH
PATH=/usr/local/pgsql/bin:$PATH
export PATH
MANPATH=/usr/local/pgsql/man:$MANPATH
export MANPATH
10. Link runtime libraries for faster access. (you need to be a superuser to execute this command. Type exit, run the command and then type "su - postgres" to log back in as postgres user).
/sbin/ldconfig /usr/local/pgsql/lib
11. Create a directory for storing database data files.
mkdir /usr/local/pgsql/data
12. Start postgres process.
cd /usr/local/pgsql/bin
postgres -D /usr/local/pgsql/data >logfile 2>&1 &
13. Add following to /etc/rc.d/rc.local script so that postgres is restarted upon reboot.
/usr/local/pgsql/bin/pg_ctl start -l logfile -D /usr/local/pgsql/data
This completes the Postgres installation.
Comments