Hello
All.
I am using Redhat Linux 8.0 , I have configured , postgres 7.2 ..now the
postmaster file is in /usr/local/pgsql/bin/postmaster.
my problem is:
when ever
the postmaster is started ( /etc/rc.d/init.d/postgresql start) by defulat it is
starting from : /usr/bin
and
also
in /etc/rc.d/init.d/postgresql
file The PGDATA is refering to /var/lib/pgsql/data.
instead
of starting from /usr/local/pgsql/data. So,
I have
change all the /var/lib/pgsql/data to
/usr/local/pgsql/data
i am
starting the initdb file from /usr/local/pgsql/bin and the
pg_ctl from the same file.
When i
have changed my data which i have mentioned above . and then if i try to restart
the service.
it is
showing the service is [failed].
I am sending my
/etc/rc.d/init.d/postgresql file.......please check this..and suggest me where i
have gone wrong.
thanks in
advance..
Hemachandra
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PGVERSION=7.2
# Source function
library.
INITD=/etc/rc.d/init.d
. $INITD/functions
INITD=/etc/rc.d/init.d
. $INITD/functions
# Get function
listing for cross-distribution logic.
TYPESET=`typeset -f|grep "declare"`
TYPESET=`typeset -f|grep "declare"`
# Get config.
. /etc/sysconfig/network
. /etc/sysconfig/network
# Check that
networking is up.
# Pretty much need it for postmaster.
[ "${NETWORKING}" = "no" ] && exit 0
# Pretty much need it for postmaster.
[ "${NETWORKING}" = "no" ] && exit 0
[ -f
/usr/local/pgsql/bin/postmaster ] || exit 0
start(){
PSQL_START=$"Starting postgresql service: "
# Check for older PGDATA
location.
if [ -f /usr/local/pgsql/PG_VERSION ] && [ -d /usr/local/pgsql/base/template1 ]
then
export PGDATA=/usr/local/pgsql
else
export PGDATA=/usr/local/pgsql/data
fi
if [ -f /usr/local/pgsql/PG_VERSION ] && [ -d /usr/local/pgsql/base/template1 ]
then
export PGDATA=/usr/local/pgsql
else
export PGDATA=/usr/local/pgsql/data
fi
# Check for the PGDATA
structure
echo " pgdata $PGDATA \n"
if [ -f $PGDATA/PG_VERSION ] && [ -d $PGDATA/base ]
then
echo "# Check version of existing PGDATA"
echo " pgdata $PGDATA \n"
if [ -f $PGDATA/PG_VERSION ] && [ -d $PGDATA/base ]
then
echo "# Check version of existing PGDATA"
if [ `cat $PGDATA/PG_VERSION` != '7.2'
]
then
SYSDOCDIR="(Your System's documentation directory)"
if [ -d /usr/doc/postgresql-$PGVERSION ]
then
SYSDOCDIR=/usr/doc
if [ -d /usr/share/doc/postgresql-$PGVERSION ]
then
SYSDOCDIR=/usr/share/doc
fi
if [ -d /usr/doc/packages/postgresql-$PGVERSION ]
then
SYSDOCDIR=/usr/doc/packages
fi
if [ -d /usr/share/doc/packages/postgresql-$PGVERSION ]
then
SYSDOCDIR=/usr/share/doc/packages
fi
echo
echo -e $"An old version of the database format was found.\nYou need to upgrade the data format before using PostgreSQL.\nSee $SYSDOCDIR/postgresql-$PGVERSION/README.rpm-dist for more information."
exit 1
# This doesn't seem to do anything useful...
# else
# if echo "$TYPESET"|grep "declare -f success ()" >/dev/null
# then
# success "$PSQL_CHECK"
# else
# echo " [ OK ]"
# fi
# echo
# fi
then
SYSDOCDIR="(Your System's documentation directory)"
if [ -d /usr/doc/postgresql-$PGVERSION ]
then
SYSDOCDIR=/usr/doc
if [ -d /usr/share/doc/postgresql-$PGVERSION ]
then
SYSDOCDIR=/usr/share/doc
fi
if [ -d /usr/doc/packages/postgresql-$PGVERSION ]
then
SYSDOCDIR=/usr/doc/packages
fi
if [ -d /usr/share/doc/packages/postgresql-$PGVERSION ]
then
SYSDOCDIR=/usr/share/doc/packages
fi
echo
echo -e $"An old version of the database format was found.\nYou need to upgrade the data format before using PostgreSQL.\nSee $SYSDOCDIR/postgresql-$PGVERSION/README.rpm-dist for more information."
exit 1
# This doesn't seem to do anything useful...
# else
# if echo "$TYPESET"|grep "declare -f success ()" >/dev/null
# then
# success "$PSQL_CHECK"
# else
# echo " [ OK ]"
# fi
# echo
# fi
else
echo " hello world"
echo -n $"Initializing database: "
if [ ! -d $PGDATA ]
then
mkdir -p $PGDATA
chown postgres.postgres $PGDATA
fi
# Make sure the locale from the initdb is preserved for later startups...
[ -f /etc/sysconfig/i18n ] && cp /etc/sysconfig/i18n $PGDATA/../initdb.i18n
# Just in case no locale was set, use en_US
[ ! -f /etc/sysconfig/i18n ] && echo "LANG=en_US" > $PGDATA/../initdb.i18n
# Is expanded this early to be used in the command su runs
echo "export LANG LC_ALL LC_CTYPE LC_COLLATE LC_NUMERIC LC_CTYPE LC_TIME" >> $PGDATA/../initdb.i18n
# Initialize the database
su -l postgres -s /bin/sh -c "/usr/local/pgsql/bin/initdb --pgdata=/usr/local/pgsql/data > /dev/null 2>&1" < /dev/null
[ -f $PGDATA/PG_VERSION ] && echo_success
[ ! -f $PGDATA/PG_VERSION ] && echo_failure
echo
fi
fi
echo " hello world"
echo -n $"Initializing database: "
if [ ! -d $PGDATA ]
then
mkdir -p $PGDATA
chown postgres.postgres $PGDATA
fi
# Make sure the locale from the initdb is preserved for later startups...
[ -f /etc/sysconfig/i18n ] && cp /etc/sysconfig/i18n $PGDATA/../initdb.i18n
# Just in case no locale was set, use en_US
[ ! -f /etc/sysconfig/i18n ] && echo "LANG=en_US" > $PGDATA/../initdb.i18n
# Is expanded this early to be used in the command su runs
echo "export LANG LC_ALL LC_CTYPE LC_COLLATE LC_NUMERIC LC_CTYPE LC_TIME" >> $PGDATA/../initdb.i18n
# Initialize the database
su -l postgres -s /bin/sh -c "/usr/local/pgsql/bin/initdb --pgdata=/usr/local/pgsql/data > /dev/null 2>&1" < /dev/null
[ -f $PGDATA/PG_VERSION ] && echo_success
[ ! -f $PGDATA/PG_VERSION ] && echo_failure
echo
fi
fi
echo "Check for postmaster
already running..."
pid=`pidof -s postmaster`
if [ $pid ]
then
echo $"Postmaster already running."
echo " already running plz stop"
else
echo "#all systems go -- remove any stale lock files"
rm -f /tmp/.s.PGSQL.* > /dev/null
echo -n "$PSQL_START"
su -l postgres -s /bin/sh -c "/usr/local/pgsql/bin/pg_ctl -D $PGDATA -p /usr/bin/postmaster start > /dev/null 2>&1" < /dev/null
sleep 1
pid=`pidof -s postmaster`
if [ $pid ]
then
success "$PSQL_START"
touch /var/lock/subsys/postgresql
echo $pid > /var/run/postmaster.pid
echo
else
failure "$PSQL_START"
fi
fi
}
pid=`pidof -s postmaster`
if [ $pid ]
then
echo $"Postmaster already running."
echo " already running plz stop"
else
echo "#all systems go -- remove any stale lock files"
rm -f /tmp/.s.PGSQL.* > /dev/null
echo -n "$PSQL_START"
su -l postgres -s /bin/sh -c "/usr/local/pgsql/bin/pg_ctl -D $PGDATA -p /usr/bin/postmaster start > /dev/null 2>&1" < /dev/null
sleep 1
pid=`pidof -s postmaster`
if [ $pid ]
then
success "$PSQL_START"
touch /var/lock/subsys/postgresql
echo $pid > /var/run/postmaster.pid
echo
else
failure "$PSQL_START"
fi
fi
}
stop(){
echo -n $"Stopping postgresql service: "
# Check for older PGDATA location.
if [ -f /usr/local/pgsql/PG_VERSION ] && [ -d /usr/local/pgsql/base/template1 ]
then
export PGDATA=/usr/local/pgsql
else
export PGDATA=/usr/local/pgsql/data
fi
su -l postgres -s /bin/sh -c "/usr/local/pgsql/bin/pg_ctl stop -D $PGDATA -s -m fast" > /dev/null 2>&1
ret=$?
if [ $ret -eq 0 ]; then
echo_success
else
echo_failure
fi
echo
rm -f /var/run/postmaster.pid
rm -f /var/lock/subsys/postgresql
}
echo -n $"Stopping postgresql service: "
# Check for older PGDATA location.
if [ -f /usr/local/pgsql/PG_VERSION ] && [ -d /usr/local/pgsql/base/template1 ]
then
export PGDATA=/usr/local/pgsql
else
export PGDATA=/usr/local/pgsql/data
fi
su -l postgres -s /bin/sh -c "/usr/local/pgsql/bin/pg_ctl stop -D $PGDATA -s -m fast" > /dev/null 2>&1
ret=$?
if [ $ret -eq 0 ]; then
echo_success
else
echo_failure
fi
echo
rm -f /var/run/postmaster.pid
rm -f /var/lock/subsys/postgresql
}
restart(){
stop
start
}
stop
start
}
condrestart(){
[ -e /var/lock/subsys/postgresql ] && restart || :
}
[ -e /var/lock/subsys/postgresql ] && restart || :
}
reload(){
su -l postgres -s /bin/sh -c "/usr/local/pgsql/bin/pg_ctl reload -D $PGDATA -s" > /dev/null 2>&1
}
su -l postgres -s /bin/sh -c "/usr/local/pgsql/bin/pg_ctl reload -D $PGDATA -s" > /dev/null 2>&1
}
# This script is slightly unusual in that the name of the daemon
(postmaster)
# is not the same as the name of the subsystem (postgresql)
# 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
;;
reload|force-reload)
reload
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload}"
exit 1
esac
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status postmaster
;;
restart)
restart
;;
condrestart)
condrestart
;;
reload|force-reload)
reload
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload}"
exit 1
esac
exit 0