diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 3c7d08209f..206f7e1d59 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -106,6 +106,8 @@ int			PostAuthDelay = 0;
 /* Time between checks that the client is still connected. */
 int			client_connection_check_interval = 0;
 
+char 		*QeuryCancelMessage = NULL;
+
 /* ----------------
  *		private typedefs etc
  * ----------------
@@ -3327,6 +3329,8 @@ ProcessInterrupts(void)
 			LockErrorCleanup();
 			ereport(ERROR,
 					(errcode(ERRCODE_QUERY_CANCELED),
+					 QeuryCancelMessage ?
+					 errmsg("%s", QeuryCancelMessage) :
 					 errmsg("canceling statement due to user request")));
 		}
 	}
@@ -4248,6 +4252,9 @@ PostgresMain(const char *dbname, const char *username)
 		/* Report the error to the client and/or server log */
 		EmitErrorReport();
 
+		/* Make sure QeuryCancelMessage is reset. */
+		QeuryCancelMessage = NULL;
+
 		/*
 		 * Make sure debug_query_string gets reset before we possibly clobber
 		 * the storage it points at.
diff --git a/src/include/tcop/tcopprot.h b/src/include/tcop/tcopprot.h
index 15a11bc3ff..83f894cbd0 100644
--- a/src/include/tcop/tcopprot.h
+++ b/src/include/tcop/tcopprot.h
@@ -30,6 +30,7 @@ extern PGDLLIMPORT const char *debug_query_string;
 extern int	max_stack_depth;
 extern int	PostAuthDelay;
 extern int	client_connection_check_interval;
+extern PGDLLIMPORT char* QeuryCancelMessage;
 
 /* GUC-configurable parameters */
 
