2023-06-30 03:50:30 -04:00
|
|
|
# This script is meant to be run with `source` so it can set environment variables.
|
|
|
|
|
|
|
|
export PGDATA="$PWD/dev_pgdata"
|
|
|
|
export PGHOST=$PWD
|
2024-04-17 20:58:44 -04:00
|
|
|
export PGUSER=postgres
|
2024-01-24 10:22:33 -05:00
|
|
|
export DATABASE_URL="postgresql://lemmy:password@/lemmy?host=$PWD"
|
|
|
|
export LEMMY_DATABASE_URL=$DATABASE_URL
|
2024-04-17 20:58:44 -04:00
|
|
|
export PGDATABASE=lemmy
|
2023-06-30 03:50:30 -04:00
|
|
|
|
|
|
|
# If cluster exists, stop the server and delete the cluster
|
2024-01-24 10:22:33 -05:00
|
|
|
if [[ -d $PGDATA ]]
|
2023-06-30 03:50:30 -04:00
|
|
|
then
|
2024-01-24 10:22:33 -05:00
|
|
|
# Only stop server if it is running
|
|
|
|
pg_status_exit_code=0
|
|
|
|
(pg_ctl status > /dev/null) || pg_status_exit_code=$?
|
|
|
|
if [[ ${pg_status_exit_code} -ne 3 ]]
|
|
|
|
then
|
|
|
|
pg_ctl stop --silent
|
|
|
|
fi
|
|
|
|
|
2023-06-30 03:50:30 -04:00
|
|
|
rm -rf $PGDATA
|
|
|
|
fi
|
|
|
|
|
2024-01-24 10:22:33 -05:00
|
|
|
config_args=(
|
|
|
|
# Only listen to socket in current directory
|
|
|
|
-c listen_addresses=
|
|
|
|
-c unix_socket_directories=$PWD
|
|
|
|
|
|
|
|
# Write logs to a file in $PGDATA/log
|
|
|
|
-c logging_collector=on
|
|
|
|
|
|
|
|
# Allow auto_explain to be turned on
|
|
|
|
-c session_preload_libraries=auto_explain
|
|
|
|
|
|
|
|
# Include actual row amounts and run times for query plan nodes
|
|
|
|
-c auto_explain.log_analyze=on
|
|
|
|
|
|
|
|
# Don't log parameter values
|
|
|
|
-c auto_explain.log_parameter_max_length=0
|
|
|
|
)
|
|
|
|
|
2023-06-30 03:50:30 -04:00
|
|
|
# Create cluster
|
2024-01-24 10:22:33 -05:00
|
|
|
pg_ctl init --silent --options="--username=postgres --auth=trust --no-instructions"
|
2023-06-30 03:50:30 -04:00
|
|
|
|
2024-01-24 10:22:33 -05:00
|
|
|
# Start server
|
|
|
|
pg_ctl start --silent --options="${config_args[*]}"
|
2023-06-30 03:50:30 -04:00
|
|
|
|
|
|
|
# Setup database
|
2024-04-17 20:58:44 -04:00
|
|
|
PGDATABASE=postgres psql --quiet -c "CREATE USER lemmy WITH PASSWORD 'password' SUPERUSER;"
|
|
|
|
PGDATABASE=postgres psql --quiet -c "CREATE DATABASE lemmy WITH OWNER lemmy;"
|