File 00011-max_files_per_process.patch of Package postgresql10

diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 8dd51f1..8de9695 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -828,6 +828,13 @@ count_usable_fds(int max_to_probe, int *usable_fds, int *already_open)
 		ereport(WARNING, (errmsg("getrlimit failed: %m")));
 #endif							/* HAVE_GETRLIMIT */
 
+	int fdTest = 0;
+#ifdef WIN32
+	//we have error on Windows7 with max_files_per_process > 1200 when dup(0) - stdin
+	//make test on postgresql.conf file	
+	fdTest = _open(ConfigFileName, _O_RDONLY);
+	if (fdTest < 0) fdTest = 0;// = stdin if error open
+#endif
 	/* dup until failure or probe limit reached */
 	for (;;)
 	{
@@ -843,7 +850,7 @@ count_usable_fds(int max_to_probe, int *usable_fds, int *already_open)
 			break;
 #endif
 
-		thisfd = dup(0);
+		thisfd = dup(fdTest);
 		if (thisfd < 0)
 		{
 			/* Expect EMFILE or ENFILE, else it's fishy */
@@ -869,7 +876,8 @@ count_usable_fds(int max_to_probe, int *usable_fds, int *already_open)
 	/* release the files we opened */
 	for (j = 0; j < used; j++)
 		close(fd[j]);
-
+	
+	if (fdTest>0) _close(fdTest);
 	pfree(fd);
 
 	/*
openSUSE Build Service is sponsored by