Re: Hardcoded PostgreSQL location..

Поиск
Список
Период
Сортировка
От Chris Wolf
Тема Re: Hardcoded PostgreSQL location..
Дата
Msg-id 3A6E2320.8CCEF92F@starclass.com
обсуждение исходный текст
Список pgsql-ports
Hello,

I normally don't like to locate application data in my
"/var" partition, so I modified the postgresql startup
script to locate PGDATA relative to the home directory
of the postgres user. (Usually "postgres")

I was able to change the home directory of "postgres"
to "/home/pgsql" and the script sucessfully picked up
the new location and initialized a database.

Regards,

Chris Wolf#! /bin/sh
# postgresql    This is the init script for starting up the PostgreSQL
#        server

# Version 6.5.3-2 Lamar Owen
# Added code to determine if PGDATA exists, whether it is current version
#     or not, and initdb if no PGDATA (initdb will not overwrite a database).

# Version 7.0 Lamar Owen
# Added logging code
# Changed PGDATA.
#

# Version 7.0.2 Trond Eivind Glomsrød <teg@redhat.com>
# use functions, add conditional restart

# Version 7.?  Chris Wolf <pg@starclass.com>
# Make PGDATA relative to user postgres home directory


# chkconfig: 345 85 15
# description: Starts and stops the PostgreSQL backend daemon that handles \
#           all database requests.
# processname: postmaster
# pidfile: /var/run/postmaster.pid
#

# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
# Pretty much need it for postmaster.
[ ${NETWORKING} = "no" ] && exit 0

[ -f /usr/bin/postmaster ] || exit 0

GREP=/bin/grep
AWK=/bin/awk
DBUSER=postgres

PG_HOME=`$GREP $DBUSER /etc/passwd | $AWK -F\: '{print $6}'`

start(){
    PSQL_CHECK="Checking postgresql installation: "
    PSQL_START="Starting postgresql service: "

    echo -n "$PSQL_CHECK"

    # Check for older PGDATA location.
    if [ -f /var/lib/pgsql/PG_VERSION ] && [ -d /var/lib/pgsql/base/template1 ]
    then
        export PGDATA=/var/lib/pgsql
    else
        export PGDATA=$PG_HOME/data
    fi

    # Check for the PGDATA structure
    if [ -f $PGDATA/PG_VERSION ] && [ -d $PGDATA/base/template1 ]
    then
    # Check version of existing PGDATA

        if [ `cat $PGDATA/PG_VERSION` != '7.0' ]
        then
            echo
            echo "old version. Need to Upgrade."
            echo "See /usr/share/doc/postgresql-7.0.2/README.rpm for more information."
            exit 1
        else
            success "$PSQL_CHECK"
            echo
        fi

    # No existing PGDATA! Initdb it.

    else
        echo "no database files found."
                if [ ! -d $PGDATA ]
        then
            mkdir -p $PGDATA
            chown postgres.postgres $PGDATA
        fi
        su -l postgres -c "/usr/bin/initdb --pglib=/usr/lib/pgsql --pgdata=$PGDATA" < /dev/null
    fi

    # Check for postmaster already running...
    pid=`pidof postmaster`
    if [ $pid ]
    then
        echo "Postmaster already running."
    else
        #all systems go -- remove any stale lock files
        rm -f /tmp/.s.PGSQL.* > /dev/null
        echo -n "$PSQL_START"
        su -l postgres -c "/usr/bin/pg_ctl  -D $PGDATA -p /usr/bin/postmaster start >/dev/null 2>&1" < /dev/null
        sleep 1
        pid=`pidof postmaster`
        if [ $pid ]
        then
            success "$PSQL_START"
            touch /var/lock/subsys/postgresql
            echo $pid > /var/run/postmaster.pid
            echo
        else
            failure "$PSQL_START"
            echo
        fi
    fi
}

stop(){
    echo -n "Stopping postgresql service: "
    killproc postmaster
    sleep 2
    rm -f /var/run/postmaster.pid
    rm -f /var/lock/subsys/postgresql
    echo
}

restart(){
    stop
    start
}

condrestart(){
    [ -e /var/lock/subsys/postgresql ] && restart || :
}


# This script is slightly unusual in that the name of the daemon (postmaster)
# is not the same as the name of the subsystem (postgresql)

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status postmaster
    ;;
  restart)
    restart
    ;;
  condrestart)
    condrestart
    ;;
  *)
    echo "Usage: postgresql {start|stop|status|restart|condrestart}"
    exit 1
esac

exit 0

В списке pgsql-ports по дате отправления:

Предыдущее
От: Ryan Kirkpatrick
Дата:
Сообщение: Re: PostgreSQL pre-7.1 Linux/Alpha Status...
Следующее
От: "Jim"
Дата:
Сообщение: DEC UNIX