Linux HOWTOs

About | Home | Search

HOWTO: postgresql
Description: Scalable, SQL compliant, object-relational database management system
Click here for ChangeLog
NOTE: I use GNU tar >= 1.13.25 so it's -j for .tar.bz2 files,
it's safe to assume that make, gcc, binutils, fileutils/coreutils, gawk, sed, and grep are prerequisites for almost everything

# PostgreSQL 8.4.2
# ================
# If you have trouble downloading it from the URL below, try here:

# Prerequisites:
# bison
# flex
# Perl
# readline
# zlib
# Python (optional)
# PAM (optional)
# OpenLDAP (optional)
# OpenSSL (optional)

test -f installed/postgresql-8.4.2.tar.bz2 &&
 mv installed/postgresql-8.4.2.tar.bz2 .
test ! -f postgresql-8.4.2.tar.bz2 &&

# Verify tarball w/ md5sum:
echo "d738227e2f1f742d2f2d4ab56496c5c6  postgresql-8.4.2.tar.bz2" | md5sum -c

# Extract the tarball and clean up older versions
mkdir -p -m 0700 src
cd src
find -maxdepth 1 -type d -name "postgresql-*" -exec rm -r {} \;
tar xjvf ~/postgresql-8.4.2.tar.bz2
cd postgresql-8.4.2
test $UID = 0 && chown -R root:root .

# If you want PAM support pass --with-pam to configure
# If you want LDAP support pass --with-ldap to configure
# If you want OpenSSL support pass --with-openssl to configure
# For other info, see './configure --help' and read ./INSTALL

# Configure and build it

# Become root to install it

# Install it
make install

# Add /usr/local/pgsql/lib to /etc/, if it's not already in there:
egrep -q "^/usr/local/pgsql/lib$" /etc/ > /dev/null 2>&1 ||
 ( echo "/usr/local/pgsql/lib" >> /etc/ ; ldconfig )

# Create /etc/profile.d/ to update PATH and MANPATH
cat < /etc/profile.d/
export PATH=/usr/local/pgsql/bin:\$PATH
export MANPATH=/usr/local/pgsql/man:\$MANPATH
chmod 755 /etc/profile.d/

# Add a 'postgres' user and group
getent group | grep "^postgres:" > /dev/null 2>&1 || groupadd postgres
id postgres > /dev/null 2>&1 || useradd -g postgres postgres
usermod -d /usr/local/pgsql/data -s /bin/bash postgres

# Create a data directory
mkdir -p /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data

# As the 'postgres' user, create the initial database data, start
# postgres, create a 'test' database
# (see ./logfile after it's done)
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

# Become root again

# If you have a recent version of Slackware that supports Sysv-init style
# init scripts, install the sample init-script
cp contrib/start-scripts/linux /etc/rc.d/init.d/postgresql
chmod 700 /etc/rc.d/init.d/postgresql
( cd /etc/rc.d/rc0.d ; ln -sf ../init.d/postgresql K02postgresql
  cd /etc/rc.d/rc6.d ; ln -sf ../init.d/postgresql K02postgresql
  cd /etc/rc.d/rc2.d ; ln -sf ../init.d/postgresql S98postgresql
  cd /etc/rc.d/rc3.d ; ln -sf ../init.d/postgresql S98postgresql
  cd /etc/rc.d/rc4.d ; ln -sf ../init.d/postgresql S98postgresql
  cd /etc/rc.d/rc5.d ; ln -sf ../init.d/postgresql S98postgresql )
# and then start it
/etc/rc.d/init.d/postgresql start

## If you don't/can't do it the SysV-init way, add something like this:
# /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
## or this
# /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
## to /etc/rc.d/rc.local

# The 'postmaster' daemon will log to /usr/local/pgsql/data/serverlog

# Now as the 'postgres' user again, create a test database, check out
# the shell, then quit (leaving you as root).  While in the shell,
# 'help' for help, to list all databases try '\l', to quit '\q'.
su - postgres
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test

# Become your non-root user again

mkdir -p -m 0700 installed
rm -f installed/postgresql-*.tar.*
mv postgresql-8.4.2.tar.bz2 installed/

# If you ever want to uninstall PostgreSQL, this should do it:
test -d src/postgresql-* && ( cd src/postgresql-* ; make uninstall )
/etc/rc.d/init.d/postgresql stop
killall postmaster
rm -r /usr/local/pgsql
userdel postgres
groupdel postgres
rm -f /etc/rc.d/rc?.d/???postgresql /etc/rc.d/init.d/postgresql
cp -a /etc/ /etc/
cat /etc/ |
 egrep -v "^\/usr\/local\/pgsql\/lib$" > /etc/
find ~/src -maxdepth 1 -type d -name "postgresql-*" -exec rm -r {} \;
rm -f ~/installed/postgresql-*.tar.*

Back to the list

Last updated: Wed, 29 Apr 2020 22:04:50 -0400
Jason Englander <jason at englanders dot us>