#!/bin/bash # source this # Place the data directory inside the project directory export PGDATA="$(pwd)/postgres_dev-13" envname="$(basename "${PGDATA}")" # Place Postgres' Unix socket inside the data directory export PGHOST="$PGDATA" if [[ ! -d "$PGDATA" ]]; then # If the data directory doesn't exist, create an empty one, and... initdb --data-checksums # ...configure it to listen only on the Unix socket, and... cat >> "$PGDATA/postgresql.conf" <<-EOF listen_addresses = '' unix_socket_directories = '$PGHOST' shared_preload_libraries = 'pg_stat_statements' EOF # ...create a database using the name Postgres defaults to. echo "CREATE DATABASE $USER;" | postgres --single -E postgres fi export PS1="(${envname})${PS1}" echo<