diff --git a/contrib/contrib-global.mk b/contrib/contrib-global.mk
index 11e0293e0101ff42faf756f008e7ec6b65cb12c1..7ac757609d48d86c87e1012b01925d85859079b8 100644
--- a/contrib/contrib-global.mk
+++ b/contrib/contrib-global.mk
@@ -1,4 +1,5 @@
-# $PostgreSQL: pgsql/contrib/contrib-global.mk,v 1.8 2004/07/30 12:26:39 petere Exp $
+# $PostgreSQL: pgsql/contrib/contrib-global.mk,v 1.9 2005/05/17 18:26:22 tgl Exp $
 
 NO_PGXS = 1
+REGRESS_OPTS = --dbname=$(CONTRIB_TESTDB)
 include $(top_srcdir)/src/makefiles/pgxs.mk
diff --git a/contrib/dblink/expected/dblink.out b/contrib/dblink/expected/dblink.out
index 4aebfd974da57d4ce939699c8c92b2fe6ca5d072..de09f6a8e0721794a04c4c9d62275bbf04a3b95d 100644
--- a/contrib/dblink/expected/dblink.out
+++ b/contrib/dblink/expected/dblink.out
@@ -98,7 +98,7 @@ SELECT dblink_build_sql_delete('"MySchema"."Foo"','1 2',2,'{"0", "a"}');
 
 -- regular old dblink
 SELECT *
-FROM dblink('dbname=regression','SELECT * FROM foo') AS t(a int, b text, c text[])
+FROM dblink('dbname=contrib_regression','SELECT * FROM foo') AS t(a int, b text, c text[])
 WHERE t.a > 7;
  a | b |     c      
 ---+---+------------
@@ -112,7 +112,7 @@ FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
 WHERE t.a > 7;
 ERROR:  connection not available
 -- create a persistent connection
-SELECT dblink_connect('dbname=regression');
+SELECT dblink_connect('dbname=contrib_regression');
  dblink_connect 
 ----------------
  OK
@@ -260,14 +260,14 @@ WHERE t.a > 7;
 ERROR:  connection not available
 -- put more data into our slave table, first using arbitrary connection syntax
 -- but truncate the actual return value so we can use diff to check for success
-SELECT substr(dblink_exec('dbname=regression','INSERT INTO foo VALUES(10,''k'',''{"a10","b10","c10"}'')'),1,6);
+SELECT substr(dblink_exec('dbname=contrib_regression','INSERT INTO foo VALUES(10,''k'',''{"a10","b10","c10"}'')'),1,6);
  substr 
 --------
  INSERT
 (1 row)
 
 -- create a persistent connection
-SELECT dblink_connect('dbname=regression');
+SELECT dblink_connect('dbname=contrib_regression');
  dblink_connect 
 ----------------
  OK
@@ -383,7 +383,7 @@ ERROR:  could not establish connection
 DETAIL:  missing "=" after "myconn" in connection info string
 
 -- create a named persistent connection
-SELECT dblink_connect('myconn','dbname=regression');
+SELECT dblink_connect('myconn','dbname=contrib_regression');
  dblink_connect 
 ----------------
  OK
@@ -420,10 +420,10 @@ SELECT dblink_exec('myconn','ABORT');
 
 -- create a second named persistent connection
 -- should error with "duplicate connection name"
-SELECT dblink_connect('myconn','dbname=regression');
+SELECT dblink_connect('myconn','dbname=contrib_regression');
 ERROR:  duplicate connection name
 -- create a second named persistent connection with a new name
-SELECT dblink_connect('myconn2','dbname=regression');
+SELECT dblink_connect('myconn2','dbname=contrib_regression');
  dblink_connect 
 ----------------
  OK
@@ -540,7 +540,7 @@ ERROR:  could not establish connection
 DETAIL:  missing "=" after "myconn" in connection info string
 
 -- create a named persistent connection
-SELECT dblink_connect('myconn','dbname=regression');
+SELECT dblink_connect('myconn','dbname=contrib_regression');
  dblink_connect 
 ----------------
  OK
diff --git a/contrib/dblink/sql/dblink.sql b/contrib/dblink/sql/dblink.sql
index 61d0adb02099fb585b98964a1c85bcbee1b140d7..b574869569790fc20c2f8937c0b14d3d459376e2 100644
--- a/contrib/dblink/sql/dblink.sql
+++ b/contrib/dblink/sql/dblink.sql
@@ -65,7 +65,7 @@ SELECT dblink_build_sql_delete('"MySchema"."Foo"','1 2',2,'{"0", "a"}');
 
 -- regular old dblink
 SELECT *
-FROM dblink('dbname=regression','SELECT * FROM foo') AS t(a int, b text, c text[])
+FROM dblink('dbname=contrib_regression','SELECT * FROM foo') AS t(a int, b text, c text[])
 WHERE t.a > 7;
 
 -- should generate "connection not available" error
@@ -74,7 +74,7 @@ FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
 WHERE t.a > 7;
 
 -- create a persistent connection
-SELECT dblink_connect('dbname=regression');
+SELECT dblink_connect('dbname=contrib_regression');
 
 -- use the persistent connection
 SELECT *
@@ -138,10 +138,10 @@ WHERE t.a > 7;
 
 -- put more data into our slave table, first using arbitrary connection syntax
 -- but truncate the actual return value so we can use diff to check for success
-SELECT substr(dblink_exec('dbname=regression','INSERT INTO foo VALUES(10,''k'',''{"a10","b10","c10"}'')'),1,6);
+SELECT substr(dblink_exec('dbname=contrib_regression','INSERT INTO foo VALUES(10,''k'',''{"a10","b10","c10"}'')'),1,6);
 
 -- create a persistent connection
-SELECT dblink_connect('dbname=regression');
+SELECT dblink_connect('dbname=contrib_regression');
 
 -- put more data into our slave table, using persistent connection syntax
 -- but truncate the actual return value so we can use diff to check for success
@@ -193,7 +193,7 @@ FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
 WHERE t.a > 7;
 
 -- create a named persistent connection
-SELECT dblink_connect('myconn','dbname=regression');
+SELECT dblink_connect('myconn','dbname=contrib_regression');
 
 -- use the named persistent connection
 SELECT *
@@ -210,10 +210,10 @@ SELECT dblink_exec('myconn','ABORT');
 
 -- create a second named persistent connection
 -- should error with "duplicate connection name"
-SELECT dblink_connect('myconn','dbname=regression');
+SELECT dblink_connect('myconn','dbname=contrib_regression');
 
 -- create a second named persistent connection with a new name
-SELECT dblink_connect('myconn2','dbname=regression');
+SELECT dblink_connect('myconn2','dbname=contrib_regression');
 
 -- use the second named persistent connection
 SELECT *
@@ -263,7 +263,7 @@ FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
 WHERE t.a > 7;
 
 -- create a named persistent connection
-SELECT dblink_connect('myconn','dbname=regression');
+SELECT dblink_connect('myconn','dbname=contrib_regression');
 
 -- put more data into our slave table, using named persistent connection syntax
 -- but truncate the actual return value so we can use diff to check for success
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 475902bc470fd4a3611dca1fa6968f525e5af9b4..3bc7cfbbc53191aa86b64c5a9fee253117f4ca9d 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -1,5 +1,5 @@
 # -*-makefile-*-
-# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.213 2005/03/25 23:22:53 momjian Exp $
+# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.214 2005/05/17 18:26:22 tgl Exp $
 
 #------------------------------------------------------------------------------
 # All PostgreSQL makefiles include this file and use the variables it sets,
@@ -228,6 +228,9 @@ XGETTEXT = @XGETTEXT@
 GZIP	= gzip
 BZIP2	= bzip2
 
+PL_TESTDB = pl_regression
+CONTRIB_TESTDB = contrib_regression
+
 # Installation.
 
 INSTALL	= $(SHELL) $(top_srcdir)/config/install-sh -c
diff --git a/src/makefiles/pgxs.mk b/src/makefiles/pgxs.mk
index 4f584ff02d4647549491f0fc93e7e5670a91b072..c00c9674e4a0cc5ee28a5e324d881348d6be4583 100644
--- a/src/makefiles/pgxs.mk
+++ b/src/makefiles/pgxs.mk
@@ -1,6 +1,6 @@
 # PGXS: PostgreSQL extensions makefile
 
-# $PostgreSQL: pgsql/src/makefiles/pgxs.mk,v 1.3 2004/10/10 16:13:03 tgl Exp $ 
+# $PostgreSQL: pgsql/src/makefiles/pgxs.mk,v 1.4 2005/05/17 18:26:22 tgl Exp $ 
 
 # This file contains generic rules to build many kinds of simple
 # extension modules.  You only need to set a few variables and include
@@ -224,12 +224,12 @@ submake:
 
 # against installed postmaster
 installcheck: submake
-	$(top_builddir)/src/test/regress/pg_regress $(REGRESS)
+	$(SHELL) $(top_builddir)/src/test/regress/pg_regress $(REGRESS_OPTS) $(REGRESS)
 
 # in-tree test doesn't work yet (no way to install my shared library)
 #check: all submake
-#	$(top_builddir)/src/test/regress/pg_regress --temp-install \
-#	  --top-builddir=$(top_builddir) $(REGRESS)
+#	$(SHELL) $(top_builddir)/src/test/regress/pg_regress --temp-install \
+#	  --top-builddir=$(top_builddir) $(REGRESS_OPTS) $(REGRESS)
 check:
 	@echo "'make check' is not supported."
 	@echo "Do 'make install', then 'make installcheck' instead."
diff --git a/src/pl/plperl/GNUmakefile b/src/pl/plperl/GNUmakefile
index 6a0d8fa9edf8e218202ff82756033b7b549f058c..509c4634b3e6a0bcbcc1a56d4c8d5aa7f75c4bc7 100644
--- a/src/pl/plperl/GNUmakefile
+++ b/src/pl/plperl/GNUmakefile
@@ -1,5 +1,5 @@
 # Makefile for PL/Perl
-# $PostgreSQL: pgsql/src/pl/plperl/GNUmakefile,v 1.19 2005/05/14 17:55:20 tgl Exp $
+# $PostgreSQL: pgsql/src/pl/plperl/GNUmakefile,v 1.20 2005/05/17 18:26:22 tgl Exp $
 
 subdir = src/pl/plperl
 top_builddir = ../../..
@@ -36,6 +36,7 @@ OBJS = plperl.o spi_internal.o SPI.o
 
 SHLIB_LINK = $(perl_embed_ldflags) $(BE_DLLLIBS)
 
+REGRESS_OPTS = --dbname=$(PL_TESTDB) --load-language=plperl
 REGRESS = plperl
 
 include $(top_srcdir)/src/Makefile.shlib
@@ -62,7 +63,7 @@ uninstall:
 	rm -f $(DESTDIR)$(pkglibdir)/plperl$(DLSUFFIX)
 
 installcheck: submake
-	$(SHELL) $(top_builddir)/src/test/regress/pg_regress --load-language=plperl $(REGRESS)
+	$(SHELL) $(top_builddir)/src/test/regress/pg_regress $(REGRESS_OPTS) $(REGRESS)
 
 .PHONY: submake
 submake:
diff --git a/src/pl/plpython/Makefile b/src/pl/plpython/Makefile
index e6f9a39e8f0b7b91222325c2adb9c9f1c0b6e0f6..3720dc3cef03f8eef9f8f5451377f75e5dfea39a 100644
--- a/src/pl/plpython/Makefile
+++ b/src/pl/plpython/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/src/pl/plpython/Makefile,v 1.19 2005/05/14 17:55:21 tgl Exp $
+# $PostgreSQL: pgsql/src/pl/plpython/Makefile,v 1.20 2005/05/17 18:26:23 tgl Exp $
 
 subdir = src/pl/plpython
 top_builddir = ../../..
@@ -58,6 +58,7 @@ endif
 
 SHLIB_LINK = $(BE_DLLLIBS) $(python_libspec) $(python_additional_libs)
 
+REGRESS_OPTS = --dbname=$(PL_TESTDB) --load-language=plpythonu
 REGRESS = plpython_schema plpython_populate plpython_function plpython_test plpython_error plpython_drop
 
 include $(top_srcdir)/src/Makefile.shlib
@@ -81,7 +82,7 @@ uninstall:
 	rm -f $(DESTDIR)$(pkglibdir)/plpython$(DLSUFFIX)
 
 installcheck: submake
-	$(SHELL) $(top_builddir)/src/test/regress/pg_regress --load-language=plpythonu $(REGRESS)
+	$(SHELL) $(top_builddir)/src/test/regress/pg_regress $(REGRESS_OPTS) $(REGRESS)
 
 .PHONY: submake
 submake:
diff --git a/src/pl/tcl/Makefile b/src/pl/tcl/Makefile
index ff65b0e020e6d5ec5c98d35213eb2b1e1228abb5..6b7764e942ac2b4d3e1610e26f3189c6587ab000 100644
--- a/src/pl/tcl/Makefile
+++ b/src/pl/tcl/Makefile
@@ -2,7 +2,7 @@
 #
 # Makefile for the pltcl shared object
 #
-# $PostgreSQL: pgsql/src/pl/tcl/Makefile,v 1.45 2005/05/14 17:55:22 tgl Exp $
+# $PostgreSQL: pgsql/src/pl/tcl/Makefile,v 1.46 2005/05/17 18:26:23 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -40,6 +40,7 @@ SO_MAJOR_VERSION = 2
 SO_MINOR_VERSION = 0
 OBJS = pltcl.o
 
+REGRESS_OPTS = --dbname=$(PL_TESTDB) --load-language=pltcl
 REGRESS = pltcl_setup pltcl_queries
 
 include $(top_srcdir)/src/Makefile.shlib
@@ -68,7 +69,7 @@ uninstall:
 	$(MAKE) -C modules $@
 
 installcheck: submake
-	$(SHELL) $(top_builddir)/src/test/regress/pg_regress --load-language=pltcl $(REGRESS)
+	$(SHELL) $(top_builddir)/src/test/regress/pg_regress $(REGRESS_OPTS) $(REGRESS)
 
 .PHONY: submake
 submake:
diff --git a/src/test/regress/pg_regress.sh b/src/test/regress/pg_regress.sh
index f637bb659e80417cef540228532016f5720719c5..f08d591b691fedc006c81f69eefe06a7281350f6 100644
--- a/src/test/regress/pg_regress.sh
+++ b/src/test/regress/pg_regress.sh
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $PostgreSQL: pgsql/src/test/regress/pg_regress.sh,v 1.54 2005/05/11 21:52:03 tgl Exp $
+# $PostgreSQL: pgsql/src/test/regress/pg_regress.sh,v 1.55 2005/05/17 18:26:23 tgl Exp $
 
 me=`basename $0`
 : ${TMPDIR=/tmp}
@@ -11,6 +11,7 @@ PostgreSQL regression test driver
 Usage: $me [options...] [extra tests...]
 
 Options:
+  --dbname=DB               use database DB (default \`regression')
   --debug                   turn on debug mode in programs that are run
   --inputdir=DIR            take input files from DIR (default \`.')
   --load-language=lang      load the named language before running the
@@ -123,6 +124,9 @@ do
         --version)
                 echo "pg_regress (PostgreSQL @VERSION@)"
                 exit 0;;
+        --dbname=*)
+                dbname=`expr "x$1" : "x--dbname=\(.*\)"`
+                shift;;
         --debug)
                 debug=yes
                 shift;;