diff --git a/Makefile b/Makefile
index 3a1ecb6829e81e41277a83940555829727fc11c3..d8d63ffe807d49c847227c7342445a71abffe12e 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@ goatherd: goatherd.go
 	go build goatherd.go
 
 test_pg: goatherd.go goatherd_test.go test_pg.sh goatherd
-	sh test_pg.sh
+	sh test_pg.sh --start-pg
 
 test_pam_goatherd: goatherd pam_goatherd.so test_pam_goatherd.sh
 	sh test_pam_goatherd.sh
diff --git a/test_pg.sh b/test_pg.sh
index e8836e2d5b1b0bf47993a29037f9157c000a567d..c4fdadbab458db6ad57a0da830e59a47b23b8d57 100644
--- a/test_pg.sh
+++ b/test_pg.sh
@@ -4,17 +4,21 @@ set -eu
 
 go test -c -o ./goatherd.test &
 
-PGHOST="$PWD/postgres_test"
-if [ $# -ge 1 ]; then
-    PGHOST="$(realpath -- "$1")"
-    shift
-fi
-export PGHOST="$PGHOST"
+if [ "${1:-x}" = "--start-pg" ]; then 
+    PGHOST="$PWD/postgres_test"
+    if [ $# -ge 1 ]; then
+        PGHOST="$(realpath -- "$1")"
+        shift
+    fi
+    export PGHOST="$PGHOST"
 
-. ./start_pg.sh
-trap 'start_pg_cleanup' EXIT INT
+    . ./start_pg.sh
+    trap 'start_pg_cleanup' EXIT INT
 
-createdb goatherd_test
+    createdb goatherd_test
+
+    export DB_URL="host=$PGHOST dbname=goatherd_test" 
+fi
 
 echo Waiting for compile to finish
 wait %1
@@ -22,13 +26,13 @@ wait %1
 echo
 echo ===== Go Tests =====
 
-DB_URL="host=$PGHOST dbname=goatherd_test" ./goatherd.test "$@"
+./goatherd.test "$@"
 
 
 echo ===== Command-Line Tests =====
 
 gh() {
-    ./goatherd -config "$PWD/pam_goatherd_test.conf" -db-url "host=$PGHOST dbname=goatherd_test" "$@"
+    ./goatherd -config "$PWD/pam_goatherd_test.conf" -db-url "$DB_URL" "$@"
 }
 
 expecting() {