diff --git a/Makefile b/Makefile
index e1f9761eefc98d14b76d92de64a28373ccc31633..4628f48c9f9425ea8c3768da135bd78862cd3e95 100644
--- a/Makefile
+++ b/Makefile
@@ -3,10 +3,13 @@ CFLAGS += -std=c11 -D_POSIX_C_SOURCE=201112 -Wall -Wconversion -fPIC
 goatherd: goatherd.go
 	go build goatherd.go
 
-goatherd_test: goatherd.go goatherd_test.go
+test_sqlite: goatherd.go goatherd_test.go
 	go test
 
-test: goatherd_test
+test_pg: goatherd.go goatherd_test.go test_pg.sh
+	sh test_pg.sh
+
+test: test_sqlite test_pg
 
 pam_goatherd.so: pam_goatherd.o
 	$(LINK.c) -lpam -lgnutls -Wl,-soname,$@ -shared $< -o $@
diff --git a/test_pg.sh b/test_pg.sh
new file mode 100644
index 0000000000000000000000000000000000000000..dab00d9392305f5d4a9844ff0b4fef669af332fb
--- /dev/null
+++ b/test_pg.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+set -eu
+
+export PGHOST="$PWD/postgres_test"
+if [ $# -ge 1 ]; then
+    PGHOST="$(realpath -- "$1")"
+    shift
+fi
+export PGDATA="$PGHOST/data"
+
+cleanup() {
+    pg_ctl stop || true
+    echo -n "removing directories... "
+    rm -rf $PGHOST
+    echo "[x]"
+}
+trap 'cleanup' EXIT INT
+
+mkdir -p "$PGHOST"
+initdb
+echo "unix_socket_directories = '$PGHOST'" >"$PGDATA/postgresql.conf"
+
+pg_ctl -l "$PGHOST/log" -o '-h ""' start
+
+export PGHOST="$PGHOST"
+createdb goatherd_test
+
+DB_DRIVER=postgres DB_URL="host=$PGHOST dbname=goatherd_test" go test "$@"