PostgreSQL数据库管理脚本

适用于PostgreSQL数据库管理,使用普通用户postgres管理,参数为(start|stop|restart|condrestart|status)

#!/bin/bash

if [ -f /etc/rc.d/functions ];
then
. /etc/init.d/functions
fi

#数据库data路径

data_dir="/cache1/PostgreSQL/9.1"
# PostgreSQL Service script for Linux
start()
{
echo $"Starting PostgreSQL_9.1: "
su - postgres -c "LD_LIBRARY_PATH=$data_dir/lib:$LD_LIBRARY_PATH $data_dir/bin/pg_ctl -w start -D \"$data_dir/data\" -l \"$data_dir/data/pg_log/startup.log\""
if [ $? -eq 0 ];
then
echo "PostgreSQL_9.1_data started successfully"
exit 0
else
echo "PostgreSQL_9.1_data did not start in a timely fashion, please see $data_dir/data/pg_log/startup.log for details"
exit 1
fi
}
stop()
{
echo $"Stopping PostgreSQL_9.1: "
su - postgres -c "LD_LIBRARY_PATH=$data_dir/lib:$LD_LIBRARY_PATH $data_dir/bin/pg_ctl stop -m fast -w -D \"$data_dir/data\""
}
restart()
{
echo $"Restarting PostgreSQL_9.1: "
su - postgres -c "LD_LIBRARY_PATH=$data_dir/lib:$LD_LIBRARY_PATH $data_dir/bin/pg_ctl -w restart -D \"$data_dir/data\" -l \"$data_dir/data/pg_log/startup.log\" -m fast"
if [ $? -eq 0 ];
then
echo "PostgreSQL_9.1_data restarted successfully"
exit 0
else
echo "PostgreSQL_9.1_data did not start in a timely fashion, please see $data_dir/data/pg_log/startup.log for details"

exit 1
fi
}
reload()
{
echo $"Reloading PostgreSQL_9.1: "
su - postgres -c "LD_LIBRARY_PATH=$data_dir/lib:$LD_LIBRARY_PATH $data_dir/bin/pg_ctl reload -D \"$data_dir/data\""
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
condrestart)
if [ -f "$data_dir/data/postmaster.pid" ]; then
restart
fi
;;
status)
# su - postgres -c "LD_LIBRARY_PATH=$data_dir/lib:$LD_LIBRARY_PATH $data_dir/bin/pg_ctl status -D \"$data_dir/data_002\""
PIDS=`ps aux |grep postgres |grep "\-D"|grep "data" |awk '{print $2}'`
[ "$PIDS" != "" ] && echo -e "postgresql_data (pid $PIDS) is running"
[ "$PIDS" == "" ] && echo -e "postgresql_data is stop"
;;
*)
echo $"Usage: $data_dir/installer/server/startupcfg.sh {start|stop|restart|condrestart|status}"
exit 1
esac

weinxin
聂扬帆博客
一个分享IT运维相关工作经验和实战技巧的个人博客

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:2   其中:访客  1   博主  0   引用   1

  1. avatar 韩氏减肥 0

    不错,过来看看。!

  2. 来自外部的引用: 1

    • PostgreSQL流复制告警的处理 | 聂扬帆博客