forked from eahanson/db-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db-start
executable file
·31 lines (24 loc) · 956 Bytes
/
db-start
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
#!/usr/bin/env bash
# Starts postgres. Assumes that postgres is installed via `asdf` (https://asdf-vm.com).
# The `pgdir` variable below is set to store the postgres data in a `priv/postgres` directory inside
# the current working directory, so that each project has its own postgres data.
# Change the variable if that's not where you want to store it.
set -e
if ! eval "asdf plugin-list | grep postgres > /dev/null 2>&1"; then
echo "${0}: asdf postgres plugin not found"
exit 1
fi
asdf where postgres > /dev/null
pgdir="$(pwd)/priv/postgres"
postgres_path="$(asdf where postgres)"
log_path="${pgdir}/logfile"
datadir="${pgdir}/data"
mkdir -p ${datadir}
if [[ -f ${datadir}/PG_VERSION ]]; then
echo "${0}: Starting postgres"
"${postgres_path}/bin/pg_ctl" -D "${datadir}" -l "${log_path}" start
echo ""
else
echo "${0}: ${datadir} does not seem to be a postgres data directory"
echo "${0}: Try running: pg_ctl -D ${datadir} initdb"
fi