diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 8dd51f1..79054e5 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -828,6 +828,15 @@ count_usable_fds(int max_to_probe, int *usable_fds, int *already_open) ereport(WARNING, (errmsg("getrlimit failed: %m"))); #endif /* HAVE_GETRLIMIT */ + int fd_test = 0; +#ifdef WIN32 + /* + * we have error on Windows7 with max_files_per_process > 1200 when dup(0) - stdin + * make test on postgresql.conf file + */ + fd_test = _open(ConfigFileName, _O_RDONLY); + if (fd_test < 0) fd_test = 0; /* if was error then = stdin */ +#endif /* dup until failure or probe limit reached */ for (;;) { @@ -843,7 +852,7 @@ count_usable_fds(int max_to_probe, int *usable_fds, int *already_open) break; #endif - thisfd = dup(0); + thisfd = dup(fd_test); if (thisfd < 0) { /* Expect EMFILE or ENFILE, else it's fishy */ @@ -869,7 +878,9 @@ 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]); - +#ifdef WIN32 + if (fd_test > 0) _close(fd_test); +#endif pfree(fd); /*