diff --git a/src/common/stringinfo.c b/src/common/stringinfo.c
index 6192e65477..e740b499fa 100644
--- a/src/common/stringinfo.c
+++ b/src/common/stringinfo.c
@@ -46,6 +46,24 @@ makeStringInfo(void)
 	return res;
 }
 
+/*
+ * makeStringInfoWithSize
+ *
+ * Create an empty 'StringInfoData' & return a pointer to it.
+ * The initial memory allocation size is specified by 'size'.
+ */
+StringInfo
+makeStringInfoWithSize(int size)
+{
+	StringInfo	res;
+
+	res = (StringInfo) palloc(sizeof(StringInfoData));
+
+	initStringInfoWithSize(res, size);
+
+	return res;
+}
+
 /*
  * initStringInfo
  *
@@ -57,6 +75,20 @@ initStringInfo(StringInfo str)
 {
 	int			size = 1024;	/* initial default buffer size */
 
+	initStringInfoWithSize(str, size);
+}
+
+/*
+ * initStringInfoWithSize
+ *
+ * Same as initStringInfo except accepting additional 'size' argument for the
+ * initial memory allocation.
+ */
+void
+initStringInfoWithSize(StringInfo str, int size)
+{
+	Assert(size > 0);
+
 	str->data = (char *) palloc(size);
 	str->maxlen = size;
 	resetStringInfo(str);
diff --git a/src/include/lib/stringinfo.h b/src/include/lib/stringinfo.h
index cd9632e3fc..5d603aa0cc 100644
--- a/src/include/lib/stringinfo.h
+++ b/src/include/lib/stringinfo.h
@@ -60,6 +60,10 @@ typedef StringInfoData *StringInfo;
  * StringInfo stringptr = makeStringInfo();
  *		Both the StringInfoData and the data buffer are palloc'd.
  *
+ * StringInfo stringptr = makeStringInfoWithSize(size);
+ *		Both the StringInfoData and the data buffer are palloc'd.
+ *		The data buffer is allocated with size 'size'.
+ *
  * StringInfoData string;
  * initStringInfo(&string);
  *		The data buffer is palloc'd but the StringInfoData is just local.
@@ -106,6 +110,13 @@ typedef StringInfoData *StringInfo;
  */
 extern StringInfo makeStringInfo(void);
 
+/*------------------------
+ * makeStringInfo
+ * Create an empty 'StringInfoData' & return a pointer to it.
+ * The data buffer is allocated with size 'size'.
+ */
+extern StringInfo makeStringInfoWithSize(int size);
+
 /*------------------------
  * initStringInfo
  * Initialize a StringInfoData struct (with previously undefined contents)
@@ -113,6 +124,14 @@ extern StringInfo makeStringInfo(void);
  */
 extern void initStringInfo(StringInfo str);
 
+/*------------------------
+ * initStringInfoWithSize
+ * Initialize a StringInfoData struct (with previously undefined contents)
+ * to describe an empty string.
+ * The data buffer is allocated with size 'size'.
+ */
+extern void initStringInfoWithSize(StringInfo str, int size);
+
 /*------------------------
  * initReadOnlyStringInfo
  * Initialize a StringInfoData struct from an existing string without copying
