pg关于启动关闭的命令,可以使用系统服务,例如linux的 systemctl、service等,或者使用pg_ctl来操作,都是比较成熟和大家所熟知的。
今天分享一个自定义的的管理命令,可根据需要进行自我改装,例如,加入pgpool的启动关闭,加入实例的判断,等,可以组合,可以单独使用。
#!/usr/bin/env bash# Date:2020-03-30# Version:v1# Author:SamYang# Description: db management script# env for pgsource ~/.bash_profilestart_db(){pg_ctl start -D $PGDATA -l $PGDATA/log/serverlogecho "数据库启动完毕"}stop_db(){pg_ctl stop -D $PGDATA -m fastecho "数据库已关闭"}start_pgagent(){PGHOST=192.168.20.155DBNAME=crUSER=crLOGFILE=$PGDATA/log/pgagent.logpgagent hostaddr=$PGHOST dbname=$DBNAME user=$USER -s $LOGFILEecho "pgagent启动成功"}stop_pgagent(){ps -ef |grep pgagent |grep -v grep |awk '{print $2}'|xargs kill -9echo "pgagent已关闭"}usage(){echo -e "\033[0;31mUsage:1 ) $0 start|stop|restart db (--- 启动\关闭\重启 数据库 ---)2 ) $0 start|stop|restart pgagent (--- 启动\关闭\重启 pgagent ---)3 ) $0 start|stop|restart all (--- 启动\关闭\重启 数据库 pgagent ---)\033[0m"}case $1 instart)case $2 indb)start_db;;pgagent)start_pgagent;;all)start_dbstart_pgagent;;*)usage;;esac;;stop)case $2 indb)stop_db;;pgagent)stop_pgagent;;all)stop_pgagentstop_db;;*)usage;;esac;;restart)case $2 indb)stop_dbstart_db;;pgagent)stop_pgagentstart_pgagent;;all)stop_pgagentstop_dbstart_dbstart_pgagent;;*)usage;;esac;;*)usage;;esac
文章转载自三杯酒coO,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




