-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_local_pg.sh
More file actions
42 lines (38 loc) · 1.57 KB
/
Copy pathstart_local_pg.sh
File metadata and controls
42 lines (38 loc) · 1.57 KB
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
#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────────────────────────
# start_local_pg.sh — Start local PostgreSQL (Homebrew install) for dev
#
# Usage:
# ./start_local_pg.sh # start postgres + open psql shell
# ./start_local_pg.sh start # start only
# ./start_local_pg.sh stop # stop postgres
# ./start_local_pg.sh status # check if running
# ─────────────────────────────────────────────────────────────────────────────
export PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/opt/postgresql@16/bin:$PATH"
PG_DATA="/home/linuxbrew/.linuxbrew/var/postgresql@16"
PG_LOG="/tmp/pg_uscontenthub.log"
PG_CTL="/home/linuxbrew/.linuxbrew/opt/postgresql@16/bin/pg_ctl"
CMD="${1:-start}"
case "$CMD" in
start)
if pg_isready -q 2>/dev/null; then
echo "PostgreSQL is already running on port 5432"
else
echo "Starting PostgreSQL..."
"$PG_CTL" -D "$PG_DATA" -l "$PG_LOG" start
sleep 2
pg_isready && echo "Ready. Connect: psql -U uscontenthub -d uscontenthub"
fi
;;
stop)
echo "Stopping PostgreSQL..."
"$PG_CTL" -D "$PG_DATA" stop
;;
status)
pg_isready && echo "Running" || echo "Not running"
;;
*)
echo "Usage: $0 [start|stop|status]"
exit 1
;;
esac