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