Обсуждение: Latest pg_autovacuum script
Hi,
I have updated the pg_autovacuum script with some bug fixes and changes. Hope you find this useful.
-- This goes where all the other init scripts are located.
-- Can be placed at the top of /etc/rc.d/init.d/postgresql script or in the /etc/sysconfig/pgsql/{name of script} e.g. postgresql, pg1, pg2
# Initialize pg_autovacuum defaults. Theo Galanakis 11/04/2005
PGAUTO_LOGFILE=/var/log/pg_autovacuum.{$PGPORT}.log
PGAUTO_SLEEP=600
--Include at the top of /etc/rc.d/init.d/postgresql
# pg_autovaccum Include script file. Theo Galanakis 11/04/2005
. $INITD/autovacuum
--Update case statement in postgresql script
case "$1" in
start)
start
startautovacuum
;;
stop)
stop
stopautovacuum
;;
status)
status postmaster
statusautovacuum
;;
restart)
restart
restartautovacuum
;;
--Create a new file /etc/rc.d/init.d/autovacuum with this content.
startautovacuum() {
# Start pg_autovacuum. Theo Galanakis 11/05/2005
# Note : ensure $PGENGINE is being used in script otherwise hardcode to /usr/bin/
if [ -f /var/run/pg_autovacuum.${PGPORT}.pid ]
then
echo $"pg_autovacuum already running."
else
PAUTO_START=$"Starting pg_autovacuum service: "
echo -n "$PAUTO_START"
pg_autovacuum -D -s ${PGAUTO_SLEEP} -p ${PGPORT} -U postgres -L ${PGAUTO_LOGFILE}
sleep 1
pg_autovacuum_pid=`pidof -s $PGENGINE/pg_autovacuum`
if [ $pg_autovacuum_pid ]
then
success "$PAUTO_START"
echo $pg_autovacuum_pid > /var/run/pg_autovacuum.${PGPORT}.pid
echo
else
failure "$PAUTO_START"
echo
fi
fi
}
stopautovacuum () {
# Stop pg_autovaccum. Theo Galanakis 11/04/2005
if [ -f /var/run/pg_autovacuum.${PGPORT}.pid ]
then
pg_autovacuum_pid=`head -n 1 /var/run/pg_autovacuum.${PGPORT}.pid`
ret=`ps --no-heading ${pg_autovacuum_pid}`
if [ -z "$ret" ]
then
echo $"pg_autovacuum: pid [${pg_autovacuum_pid}] stored in /var/run/pg_autovacuum.${PGPORT}.pid does not exist."
else
echo -n $"Stopping pg_autovacuum service: "
kill -TERM $pg_autovacuum_pid
ret=`ps --no-heading ${pg_autovacuum_pid}`
if [ -z "$ret" ]
then
echo_success
else
echo_failure
fi
echo
rm -f /var/run/pg_autovacuum.${PGPORT}.pid
fi
else
echo $"pg_autovacuum is not running."
fi
}
statusautovacuum() {
# Status pg_autovacuum. Theo Galanakis 11/04/2005
if [ -f /var/run/pg_autovacuum.${PGPORT}.pid ]
then
pg_autovacuum_pid=`head -n 1 /var/run/pg_autovacuum.${PGPORT}.pid`
ret=`ps --no-heading ${pg_autovacuum_pid}`
if [ -z "$ret" ]
then
echo $"pg_autovacuum not running..."
else
echo $"pg_autovacuum (pid ${pg_autovacuum_pid}) is running..."
fi
else
status pg_autovacuum
fi
}
restartautovacuum() {
stopautovacuum
startautovacuum
}
______________________________________________________________________ This email, including attachments, is intended only for the addressee and may be confidential, privileged and subject to copyright. If you have received this email in error, please advise the sender and delete it. If you are not the intended recipient of this email, you must not use, copy or disclose its content to anyone. You must not copy or communicate to others content that is confidential or subject to copyright, unless you have the consent of the content owner. |
Do you want this in CVS for 8.0.X? --------------------------------------------------------------------------- Theo Galanakis wrote: > > Hi, > I have updated the pg_autovacuum script with some bug fixes and > changes. Hope you find this useful. > > -- This goes where all the other init scripts are located. > -- Can be placed at the top of /etc/rc.d/init.d/postgresql script or in the > /etc/sysconfig/pgsql/{name of script} e.g. postgresql, pg1, pg2 > # Initialize pg_autovacuum defaults. Theo Galanakis 11/04/2005 > PGAUTO_LOGFILE=/var/log/pg_autovacuum.{$PGPORT}.log > PGAUTO_SLEEP=600 > > --Include at the top of /etc/rc.d/init.d/postgresql > # pg_autovaccum Include script file. Theo Galanakis 11/04/2005 > . $INITD/autovacuum > > > --Update case statement in postgresql script > case "$1" in > start) > start > startautovacuum > ;; > stop) > stop > stopautovacuum > ;; > status) > status postmaster > statusautovacuum > ;; > restart) > restart > restartautovacuum > ;; > > > --Create a new file /etc/rc.d/init.d/autovacuum with this content. > startautovacuum() { > # Start pg_autovacuum. Theo Galanakis 11/05/2005 > # Note : ensure $PGENGINE is being used in script otherwise hardcode > to /usr/bin/ > if [ -f /var/run/pg_autovacuum.${PGPORT}.pid ] > then > echo $"pg_autovacuum already running." > else > PAUTO_START=$"Starting pg_autovacuum service: " > echo -n "$PAUTO_START" > pg_autovacuum -D -s ${PGAUTO_SLEEP} -p ${PGPORT} -U postgres > -L ${PGAUTO_LOGFILE} > sleep 1 > pg_autovacuum_pid=`pidof -s $PGENGINE/pg_autovacuum` > if [ $pg_autovacuum_pid ] > then > success "$PAUTO_START" > echo $pg_autovacuum_pid > > /var/run/pg_autovacuum.${PGPORT}.pid > echo > else > failure "$PAUTO_START" > echo > fi > fi > } > > stopautovacuum () { > # Stop pg_autovaccum. Theo Galanakis 11/04/2005 > if [ -f /var/run/pg_autovacuum.${PGPORT}.pid ] > then > pg_autovacuum_pid=`head -n 1 > /var/run/pg_autovacuum.${PGPORT}.pid` > ret=`ps --no-heading ${pg_autovacuum_pid}` > if [ -z "$ret" ] > then > echo $"pg_autovacuum: pid [${pg_autovacuum_pid}] > stored in /var/run/pg_autovacuum.${PGPORT}.pid does not exist." > else > echo -n $"Stopping pg_autovacuum service: " > > kill -TERM $pg_autovacuum_pid > ret=`ps --no-heading ${pg_autovacuum_pid}` > if [ -z "$ret" ] > then > echo_success > else > echo_failure > fi > echo > rm -f /var/run/pg_autovacuum.${PGPORT}.pid > fi > else > echo $"pg_autovacuum is not running." > fi > } > > statusautovacuum() { > # Status pg_autovacuum. Theo Galanakis 11/04/2005 > if [ -f /var/run/pg_autovacuum.${PGPORT}.pid ] > then > pg_autovacuum_pid=`head -n 1 > /var/run/pg_autovacuum.${PGPORT}.pid` > ret=`ps --no-heading ${pg_autovacuum_pid}` > if [ -z "$ret" ] > then > echo $"pg_autovacuum not running..." > else > echo $"pg_autovacuum (pid ${pg_autovacuum_pid}) is > running..." > fi > else > status pg_autovacuum > fi > } > > restartautovacuum() { > stopautovacuum > startautovacuum > } > > > > ______________________________________________________________________ > This email, including attachments, is intended only for the addressee > and may be confidential, privileged and subject to copyright. If you > have received this email in error, please advise the sender and delete > it. If you are not the intended recipient of this email, you must not > use, copy or disclose its content to anyone. You must not copy or > communicate to others content that is confidential or subject to > copyright, unless you have the consent of the content owner. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073