PostgreSQL does not start when max_files_per_process> 1200 on Windows 7

Lists: pgsql-hackers
From: Victor Spirin <v(dot)spirin(at)postgrespro(dot)ru>
To: pgsql-hackers(at)postgresql(dot)org
Subject: PostgreSQL does not start when max_files_per_process> 1200 on Windows 7
Date: 2018-09-05 10:06:06
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

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

Attachment Content-Type Size
max_files_per_process.patch text/plain 1.2 KB

From: Andres Freund <andres(at)anarazel(dot)de>
To: Victor Spirin <v(dot)spirin(at)postgrespro(dot)ru>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: PostgreSQL does not start when max_files_per_process> 1200 on Windows 7
Date: 2018-09-05 16:24:55
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

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


From: Victor Spirin <v(dot)spirin(at)postgrespro(dot)ru>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: PostgreSQL does not start when max_files_per_process> 1200 on Windows 7
Date: 2018-09-05 21:25:28
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

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 пишет:
> 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
>