diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index ac986c0505..df681df103 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -285,16 +285,26 @@ socket_close(int code, Datum arg)
 		 * call this, so this is safe when interrupting BackendInitialize().
 		 */
 		secure_close(MyProcPort);
+#ifdef WIN32
+		/*
+		 * Shutdown and close the socket explicitly to allow clients to receive
+		 * a message sent just before the backend exit, e.g., a FATAL error.
+		 * Otherwise Windows resets the connection and doesn't transmit data
+		 * when the process dies.
+		 */
+		shutdown(MyProcPort->sock, SD_BOTH);
+		closesocket(MyProcPort->sock);
+#endif
 
 		/*
-		 * Formerly we did an explicit close() here, but it seems better to
-		 * leave the socket open until the process dies.  This allows clients
-		 * to perform a "synchronous close" if they care --- wait till the
-		 * transport layer reports connection closure, and you can be sure the
-		 * backend has exited.
+		 * Formerly we did an explicit close() here on other OSes too, but it
+		 * seems better to leave the socket open until the process dies.
+		 * This allows clients to perform a "synchronous close" if they care
+		 *  --- wait till the transport layer reports connection closure,
+		 * and you can be sure the backend has exited.
 		 *
-		 * We do set sock to PGINVALID_SOCKET to prevent any further I/O,
-		 * though.
+		 * We do set sock to PGINVALID_SOCKET to prevent any further I/O
+		 * in any case.
 		 */
 		MyProcPort->sock = PGINVALID_SOCKET;
 	}
