diff --git a/.gitignore b/.gitignore index 8ae1d06..fe2cd71 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ dist-newstyle *.swp result bench.html +download +pgdata diff --git a/with-db.sh b/with-db.sh index f10d509..09bb70d 100755 --- a/with-db.sh +++ b/with-db.sh @@ -1,14 +1,21 @@ -BASE_DIR=$(mktemp -d) +if [ -z "$BASE_DIR" ]; then + BASE_DIR=$(mktemp -d) +fi export PGDATA="$BASE_DIR/pgdata" # On error or exit: Stop the DB server stop_db_server() { - pg_ctl stop --wait + pg_ctl stop -o "-p 5433" --wait } trap stop_db_server EXIT -initdb --username=yore-test --auth=trust -pg_ctl start --wait -createdb yore-test --username=yore-test +if [ ! -s "$PGDATA/PG_VERSION" ]; then + initdb --username=yore-test --auth=trust || true + DO_CREATE_DB=1 +fi +pg_ctl start -o "-p 5433" --wait +if [ -n "$DO_CREATE_DB" ]; then + createdb -p 5433 yore-test --username=yore-test || true +fi "$@"