-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgres.plugins.bash
executable file
·82 lines (60 loc) · 1.72 KB
/
postgres.plugins.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# shellcheck shell=bash
cite about-plugin
about-plugin 'Postgres helper functions'
if _command_exists pg_config; then
PGVERSION=`pg_config --version | awk '{print $2}'`
POSTGRES_BIN=`pg_config --bindir`
export PGVERSION
export POSTGRES_BIN
COMMON_PGDATA_PATHS=("/usr/local/var/postgres" "/var/pgsql" "/Library/Server/PostgreSQL/Data")
for possible in "${COMMON_PGDATA_PATHS[@]}"
do
:
if [[ -f "$possible/pg_hba.conf" ]]
then
export PGDATA=$possible
fi
done
postgres_start () {
about 'Starts PostgreSQL server'
group 'postgres'
echo 'Starting PostgreSQL....';
$POSTGRES_BIN/pg_ctl -D $PGDATA -l $PGDATA/logfile start
}
postgres_stop () {
about 'Stops PostgreSQL server'
group 'postgres'
echo 'Stopping PostgreSQL....';
$POSTGRES_BIN/pg_ctl -D $PGDATA -l $PGDATA/logfile stop -s -m fast
}
postgres_status () {
about 'Returns status of PostgreSQL server'
group 'postgres'
# $POSTGRES_BIN/pg_ctl -D $PGDATA status
if [[ $(is_postgres_running) == "no server running" ]]
then
echo "PostgreSQL service [STOPPED]"
else
echo "PostgreSQL service [RUNNING]"
fi
}
is_postgres_running () {
$POSTGRES_BIN/pg_ctl -D $PGDATA status | egrep -o "no server running"
}
postgres_restart () {
about 'Restarts status of PostgreSQL server'
group 'postgres'
echo 'Restarting PostgreSQL....';
$POSTGRES_BIN/pg_ctl -D $PGDATA restart
}
postgres_logfile () {
about 'View the last 500 lines from logfile'
group 'postgres'
tail -500 $PGDATA/logfile | less
}
postgres_serverlog () {
about 'View the last 500 lines from server.log'
group 'postgres'
tail -500 $PGDATA/server.log | less
}
fi