Created
June 3, 2026 11:52
-
-
Save Lucus16/65cb4b6bf5ca0f9f02ac87bb1f68a753 to your computer and use it in GitHub Desktop.
simple temp postgres database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # A simple wrapper around pg_ctl that automatically initializes and creates a database on start. | |
| # export PGHOST=$(mktemp -d) | |
| # pg_tmp start | |
| # psql -c "SELECT 'Have fun!';" | |
| # pg_tmp stop | |
| # rm -r $PGHOST # Be careful! | |
| set -eo pipefail | |
| PGDATA="$(realpath --canonicalize-missing "$PGHOST")" | |
| export PGDATA | |
| case "$1" in | |
| start|restart) | |
| mkdir -p "$PGDATA" | |
| [ -f "$PGDATA/PG_VERSION" ] || \ | |
| initdb --auth-local=peer --auth-host=reject >/dev/null | |
| pg_ctl --log="$PGDATA/postgres.log" --wait \ | |
| -o "-c listen_addresses= -c unix_socket_directories=$PGDATA" "$@" | |
| psql --command= 2>/dev/null || createdb | |
| ;; | |
| *) | |
| pg_ctl "$@" | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment