PostgreSQL does not start when max_files_per_process> 1200 on Windows 7

Started by Victor Spirinabout 8 years ago3 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t39311
psql -h localhost -U postgres

Built from patchset v1 (message #1), July 27, 2026 at 07:58 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t39311_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t39311_1 && git checkout t39311_1

Patchset v1 (message #1) is on t39311_1

Jump to latest
#1Victor Spirin
v.spirin@postgrespro.ru

Hi,

I have a bug in Windows 7 with max_files_per_process> 1200.

Using dup (0) in the  function count_usable_fds more than 1200 times (0
= stdin) causes further unpredictable errors with file operations.

When I open a real file and use its descriptor for the dup, no error
occurs. In the patch I check the file postgresql.conf

--
Victor Spirin
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

Attachments:

t39311_1
max_files_per_process.patchtext/plain; charset=UTF-8; name=max_files_per_process.patchDownload+13-2
#2Andres Freund
andres@anarazel.de
In reply to: Victor Spirin (#1)
Re: PostgreSQL does not start when max_files_per_process> 1200 on Windows 7

Hi,

On 2018-09-05 13:06:06 +0300, Victor Spirin wrote:

I have a bug in Windows 7 with max_files_per_process> 1200.

Using dup (0) in the� function count_usable_fds more than 1200 times (0 =
stdin) causes further unpredictable errors with file operations.

Could you expand a bit on this?

Greetings,

Andres Freund

#3Victor Spirin
v.spirin@postgrespro.ru
In reply to: Andres Freund (#2)
Re: PostgreSQL does not start when max_files_per_process> 1200 on Windows 7

When max_files_per_process=1201 or more server not start. I tested and
debugged this on Windows 7. On Windows 10 work all right.

I found this take place after call function  count_usable_fds(int
max_to_probe, int *usable_fds, int *already_open)

Error occured on the first call selres = select(nSockets, &rmask, NULL,
NULL, &timeout) from ServerLoop. Error 0xC0000142:  "{DLL Initialization
Failed} Initialization of the dynamic link library %hs failed. The
process is terminating abnormally."

I temporarily moved call set_max_safe_fds() to top of the PostmasterMain
and error moved to ReadFile in function pipe_read_line(char *cmd, char
*line, int maxsize):

if (!ReadFile(childstdoutrddup, lineptr, maxsize - (lineptr - line),
                          &bytesread, NULL))

Repeat the error in a separate example did not work yet.

Replacing dup for stdin on dup of file handle resolve this problem.

Victor Spirin
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

05.09.2018 19:24, Andres Freund пишет:

Show quoted text

Hi,

On 2018-09-05 13:06:06 +0300, Victor Spirin wrote:

I have a bug in Windows 7 with max_files_per_process> 1200.

Using dup (0) in the  function count_usable_fds more than 1200 times (0 =
stdin) causes further unpredictable errors with file operations.

Could you expand a bit on this?

Greetings,

Andres Freund