2023-12-01 11:11:19 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
export PGHOST=$1
|
|
|
|
export PGDATA="$1/dev_pgdata"
|
|
|
|
|
2023-12-01 23:59:24 +00:00
|
|
|
# If cluster exists, stop the server
|
2023-12-01 11:11:19 +00:00
|
|
|
if [ -d $PGDATA ]
|
|
|
|
then
|
|
|
|
# Prevent `stop` from failing if server already stopped
|
|
|
|
pg_ctl restart > /dev/null
|
|
|
|
pg_ctl stop
|
|
|
|
fi
|
|
|
|
|
2023-12-01 23:59:24 +00:00
|
|
|
# Remove any leftover data from revious run
|
|
|
|
rm -rf $PGDATA
|
|
|
|
|
2023-12-01 11:11:19 +00:00
|
|
|
# Create cluster
|
|
|
|
initdb --username=postgres --auth=trust --no-instructions
|
|
|
|
|
2023-12-01 14:16:07 +00:00
|
|
|
touch "$PGHOST/.s.PGSQL.5432"
|
|
|
|
echo "$PGHOST/.s.PGSQL.5432"
|
2023-12-01 11:11:19 +00:00
|
|
|
|
|
|
|
# Start server that only listens to socket in current directory
|
|
|
|
pg_ctl start --options="-c listen_addresses= -c unix_socket_directories=$PGHOST"
|
|
|
|
|
|
|
|
# Setup database
|
|
|
|
psql -c "CREATE USER lemmy WITH PASSWORD 'password' SUPERUSER;" -U postgres
|
|
|
|
psql -c "CREATE DATABASE lemmy WITH OWNER lemmy;" -U postgres
|