Pejman Moghadam / Slackware

Slackware 13.37 - Installing PostgreSQL (with epkg)

First install epkg/encap

Public domain


PostgreSQL Installation

cd /usr/src
wget -c "http://pmoghadam.com/homepage/Pages/Deposit/Source-packages/postgresql-8.4.12.tar.bz2"
su - install
cd /usr/src
tar xf postgresql-8.4.12.tar.bz2
cd postgresql-8.4.12 
./configure --prefix=/usr && gmake 
gmake install DESTDIR=/usr/local/encap/postgresql-8.4.12
cd /usr/local/encap/postgresql-8.4.12
mv usr/share/doc/ usr/
mv usr/share/man/ usr/
cd /usr/local/encap/
mkencap postgresql-8.4.12/ 
logout
rm -rf /usr/src/postgresql-8.4.12
cd /usr/local/encap/
epkg postgresql-8.4.12

Initialize

useradd -m postgres
passwd  -l postgres
mkdir -p /var/lib/pgsql-data
chown postgres /var/lib/pgsql-data
su - postgres -c "initdb -D /var/lib/pgsql-data"
su - postgres -c "postgres -D /var/lib/pgsql-data &"
sleep 2
su - postgres -c "createuser -a -d -P root"
#su - postgres -c "initdb -U root -W -A md5 -D /var/lib/pgsql-data"

/etc/rc.d/rc.postgresql

#!/bin/bash

# Configuration
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
PGDATA="/var/lib/pgsql-data/"
PGUSER=postgres
PGLOG="$PGDATA/serverlog"
DAEMON="postmaster"
PGCTL="pg_ctl"

case $1 in
  start)
    echo -n "Starting PostgreSQL: "
    su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
    echo "ok"
    ;;
  stop)
    echo -n "Stopping PostgreSQL: "
    su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast"
    echo "ok"
    ;;
  restart)
    echo -n "Restarting PostgreSQL: "
    su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
    su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
    echo "ok"
    ;;
  reload)
    echo -n "Reload PostgreSQL: "
    su - $PGUSER -c "$PGCTL reload -D '$PGDATA' -s"
    echo "ok"
    ;;
  status)
    su - $PGUSER -c "$PGCTL status -D '$PGDATA'"
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
    exit 1
    ;;
esac

/etc/rc.d/rc.local

# Start postgresql
if [ -x /etc/rc.d/rc.postgresql ] ; then
  /etc/rc.d/rc.postgresql start
fi

/etc/rc.d/rc.local_shutdown

# Stop postgresql
if [ -x /etc/rc.d/rc.postgresql ] ; then
  /etc/rc.d/rc.postgresql stop
fi

Launch

chmod +x /etc/rc.d/rc.postgresql
/etc/rc.d/rc.postgresql restart
sleep 2
ps -A | grep postmaster

Create user

createuser -P testuser

Create database

createdb testdb

Connecting to database

psql testdb

Uninstall

/etc/rc.d/rc.postgresql stop
rm -f /etc/rc.d/rc.postgresql
cd /usr/local/encap
epkg -r postgresql-8.4.12 
userdel -r postgres
rm -rf /var/lib/pgsql-data/
# Edit /etc/rc.d/rc.local
# Edit /etc/rc.d/rc.local_shutdown

Bookmarks

http://www.postgresql.org/docs/8.4/static/datatype-net-types.html
http://www.postgresql.org/docs/8.4/static/functions-net.html
http://www.postgresql.org/docs/8.4/static/datatype-datetime.html
http://www.postgresql.org/docs/8.4/static/functions-datetime.html


BY: Pejman Moghadam
TAG: epkg, postgresql
DATE: 2012-06-21 12:36:53


Pejman Moghadam / Slackware [ TXT ]