diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 7edd94f0f9..ad9808ab94 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -148,6 +148,8 @@ extern bool optimize_bounded_sort;
 
 static int	GUC_check_errcode_value;
 
+int64 test_mem;
+
 /* global variables for check hook support */
 char	   *GUC_check_errmsg_string;
 char	   *GUC_check_errdetail_string;
@@ -3871,6 +3873,18 @@ static struct config_real ConfigureNamesReal[] =
 
 static struct config_int64 ConfigureNamesInt64[] =
 {
+	{
+		{"test_mem", PGC_USERSET, RESOURCES_MEM,
+			gettext_noop("Sets the maximum memory to be used for query workspaces."),
+			gettext_noop("This much memory can be used by each internal "
+						 "sort operation and hash table before switching to "
+						 "temporary disk files.")
+		},
+		&test_mem,
+		64, 0, INT64_MAX,
+		NULL, NULL, NULL
+	},
+
 		/* End-of-list marker */
 	{
 		{NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL, NULL
diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql
index 95f7ab4189..cc45d06a72 100644
--- a/src/test/regress/sql/reloptions.sql
+++ b/src/test/regress/sql/reloptions.sql
@@ -130,3 +130,5 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test_idx'::regclass;
 CREATE INDEX reloptions_test_idx3 ON reloptions_test (s);
 ALTER INDEX reloptions_test_idx3 SET (fillfactor=40);
 SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test_idx3'::regclass;
+
+SET test_mem = 123456789012345;
