pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix error handling of vacuumdb and reindexdb when running out of
5+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2022-10-07 e5555657ba  meson: Add support for building with precompiled headers
  2022-10-06 4289263cf2  windows: Adjust FD_SETSIZE via commandline define
  2019-08-27 b783a38d45 128e9b2cc9 c900960093 c4d75313ee 4ed3bda49d  Fix failure of --jobs with vacuumdb on Windows
  2019-08-27 9acda73118  Fix failure of --jobs with reindexdb and vacuumdb on Windows
* pgsql: Fix error handling of vacuumdb and reindexdb when running out of
@ 2019-08-26 02:17 Michael Paquier <michael@paquier.xyz>
  2019-08-26 05:40 ` Re: pgsql: Fix error handling of vacuumdb and reindexdb when running out of Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 5+ messages in thread

From: Michael Paquier @ 2019-08-26 02:17 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix error handling of vacuumdb and reindexdb when running out of fds

When trying to use a high number of jobs, vacuumdb (and more recently
reindexdb) has only checked for a maximum number of jobs used, causing
confusing failures when running out of file descriptors when the jobs
open connections to Postgres.  This commit changes the error handling so
as we do not check anymore for a maximum number of allowed jobs when
parsing the option value with FD_SETSIZE, but check instead if a file
descriptor is within the supported range when opening the connections
for the jobs so as this is detected at the earliest time possible.

Also, improve the error message to give a hint about the number of jobs
recommended, using a wording given by the reviewers of the patch.

Reported-by: Andres Freund
Author: Michael Paquier
Reviewed-by: Andres Freund, Álvaro Herrera, Tom Lane
Discussion: https://postgr.es/m/20190818001858.ho3ev4z57fqhs7a5@alap3.anarazel.de
Backpatch-through: 9.5

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/71d84efba714db3b8a330a54be15c4d385719ad6

Modified Files
--------------
src/bin/scripts/reindexdb.c        |  6 ------
src/bin/scripts/scripts_parallel.c | 26 ++++++++++++--------------
src/bin/scripts/scripts_parallel.h |  2 --
src/bin/scripts/vacuumdb.c         |  6 ------
4 files changed, 12 insertions(+), 28 deletions(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pgsql: Fix error handling of vacuumdb and reindexdb when running out of
  2019-08-26 02:17 pgsql: Fix error handling of vacuumdb and reindexdb when running out of Michael Paquier <michael@paquier.xyz>
@ 2019-08-26 05:40 ` Michael Paquier <michael@paquier.xyz>
  2019-08-26 15:36   ` Re: pgsql: Fix error handling of vacuumdb and reindexdb when running out of Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Michael Paquier @ 2019-08-26 05:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

On Mon, Aug 26, 2019 at 02:17:06AM +0000, Michael Paquier wrote:
> Fix error handling of vacuumdb and reindexdb when running out of fds
> 
> When trying to use a high number of jobs, vacuumdb (and more recently
> reindexdb) has only checked for a maximum number of jobs used, causing
> confusing failures when running out of file descriptors when the jobs
> open connections to Postgres.  This commit changes the error handling so
> as we do not check anymore for a maximum number of allowed jobs when
> parsing the option value with FD_SETSIZE, but check instead if a file
> descriptor is within the supported range when opening the connections
> for the jobs so as this is detected at the earliest time possible.
> 
> Also, improve the error message to give a hint about the number of jobs
> recommended, using a wording given by the reviewers of the patch.

jacana does not like that, and has reported an error for 9.6:
https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=jacana&dt=2019-08-26 03%3A51%3A19
# Running: vacuumdb -zj2 postgres
vacuumdb: vacuuming database "postgres"
vacuumdb: too many jobs for this platform -- try 1

I am able to reproduce the problem locally, and the problem is that we
don't declare FD_SETSIZE on Windows before winsock2.h in
scripts_parallel.c (or vacuumdb.c in ~12) so all the Windows machines
running TAP are going to complain on that.

This matches with the same problem reported here
https://www.postgresql.org/message-id/1248903114.6348.195.camel@lapdragon

We have never done that before in vacuumdb.c, and because of that I
think that with a high number of jobs we run into buffer overflows.

The patch attached does the job on my end, any objections?  There
is an argument to do that in win32_port.h, but for now I'd rather take
a safe path, or just do for the change in win32_port.h on HEAD.

(Noticed the missing newline as well in the error string in
back-branches...  I'll address it at the same time.)
--
Michael

Attachments:

windows-fdset.patch (text/x-diff, 455B) download diff --git a/src/bin/scripts/scripts_parallel.c b/src/bin/scripts/scripts_parallel.c index 55bda9044b..97435160e9 100644 --- a/src/bin/scripts/scripts_parallel.c +++ b/src/bin/scripts/scripts_parallel.c @@ -12,6 +12,10 @@ *------------------------------------------------------------------------- */ +#ifdef WIN32 +#define FD_SETSIZE 1024 /* must set before winsock2.h is included */ +#endif + #include "postgres_fe.h" #ifdef HAVE_SYS_SELECT_H
signature.asc (application/pgp-signature, 832B) download ^ permalink raw reply [nested|flat] 5+ messages in thread

* Re: pgsql: Fix error handling of vacuumdb and reindexdb when running out of
  2019-08-26 02:17 pgsql: Fix error handling of vacuumdb and reindexdb when running out of Michael Paquier <michael@paquier.xyz>
  2019-08-26 05:40 ` Re: pgsql: Fix error handling of vacuumdb and reindexdb when running out of Michael Paquier <michael@paquier.xyz>
@ 2019-08-26 15:36   ` Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
  2019-08-27 00:18     ` Re: pgsql: Fix error handling of vacuumdb and reindexdb when running out of Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 5+ messages in thread

From: Andrew Dunstan @ 2019-08-26 15:36 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; pgsql-committers@lists.postgresql.org


On 8/26/19 1:40 AM, Michael Paquier wrote:
> On Mon, Aug 26, 2019 at 02:17:06AM +0000, Michael Paquier wrote:
>> Fix error handling of vacuumdb and reindexdb when running out of fds
>>
>> When trying to use a high number of jobs, vacuumdb (and more recently
>> reindexdb) has only checked for a maximum number of jobs used, causing
>> confusing failures when running out of file descriptors when the jobs
>> open connections to Postgres.  This commit changes the error handling so
>> as we do not check anymore for a maximum number of allowed jobs when
>> parsing the option value with FD_SETSIZE, but check instead if a file
>> descriptor is within the supported range when opening the connections
>> for the jobs so as this is detected at the earliest time possible.
>>
>> Also, improve the error message to give a hint about the number of jobs
>> recommended, using a wording given by the reviewers of the patch.
> jacana does not like that, and has reported an error for 9.6:
> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=jacana&dt=2019-08-26 03%3A51%3A19
> # Running: vacuumdb -zj2 postgres
> vacuumdb: vacuuming database "postgres"
> vacuumdb: too many jobs for this platform -- try 1
>
> I am able to reproduce the problem locally, and the problem is that we
> don't declare FD_SETSIZE on Windows before winsock2.h in
> scripts_parallel.c (or vacuumdb.c in ~12) so all the Windows machines
> running TAP are going to complain on that.
>
> This matches with the same problem reported here
> https://www.postgresql.org/message-id/1248903114.6348.195.camel@lapdragon
>
> We have never done that before in vacuumdb.c, and because of that I
> think that with a high number of jobs we run into buffer overflows.
>
> The patch attached does the job on my end, any objections?  There
> is an argument to do that in win32_port.h, but for now I'd rather take
> a safe path, or just do for the change in win32_port.h on HEAD.
>
> (Noticed the missing newline as well in the error string in
> back-branches...  I'll address it at the same time.)



Looks OK.


cheers


andrew



-- 
Andrew Dunstan                https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pgsql: Fix error handling of vacuumdb and reindexdb when running out of
  2019-08-26 02:17 pgsql: Fix error handling of vacuumdb and reindexdb when running out of Michael Paquier <michael@paquier.xyz>
  2019-08-26 05:40 ` Re: pgsql: Fix error handling of vacuumdb and reindexdb when running out of Michael Paquier <michael@paquier.xyz>
  2019-08-26 15:36   ` Re: pgsql: Fix error handling of vacuumdb and reindexdb when running out of Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
@ 2019-08-27 00:18     ` Michael Paquier <michael@paquier.xyz>
  2019-08-27 03:44       ` Re: pgsql: Fix error handling of vacuumdb and reindexdb when running out of Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 5+ messages in thread

From: Michael Paquier @ 2019-08-27 00:18 UTC (permalink / raw)
  To: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>; +Cc: pgsql-committers@lists.postgresql.org

On Mon, Aug 26, 2019 at 11:36:50AM -0400, Andrew Dunstan wrote:
> Looks OK.

Thanks Andrew for looking at the patch.  I have now committed it on
all the impacted branches, after running vcregress bincheck for all of
them with MSVC.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pgsql: Fix error handling of vacuumdb and reindexdb when running out of
  2019-08-26 02:17 pgsql: Fix error handling of vacuumdb and reindexdb when running out of Michael Paquier <michael@paquier.xyz>
  2019-08-26 05:40 ` Re: pgsql: Fix error handling of vacuumdb and reindexdb when running out of Michael Paquier <michael@paquier.xyz>
  2019-08-26 15:36   ` Re: pgsql: Fix error handling of vacuumdb and reindexdb when running out of Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
  2019-08-27 00:18     ` Re: pgsql: Fix error handling of vacuumdb and reindexdb when running out of Michael Paquier <michael@paquier.xyz>
@ 2019-08-27 03:44       ` Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 5+ messages in thread

From: Michael Paquier @ 2019-08-27 03:44 UTC (permalink / raw)
  To: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>; +Cc: pgsql-committers@lists.postgresql.org

On Tue, Aug 27, 2019 at 09:18:27AM +0900, Michael Paquier wrote:
> Thanks Andrew for looking at the patch.  I have now committed it on
> all the impacted branches, after running vcregress bincheck for all of
> them with MSVC.

bowerbird has turned back to green on 9.5 and 9.6 now, so it seems
that we are fine.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2019-08-27 03:44 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-08-26 02:17 pgsql: Fix error handling of vacuumdb and reindexdb when running out of Michael Paquier <michael@paquier.xyz>
2019-08-26 05:40 ` Michael Paquier <michael@paquier.xyz>
2019-08-26 15:36   ` Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
2019-08-27 00:18     ` Michael Paquier <michael@paquier.xyz>
2019-08-27 03:44       ` Michael Paquier <michael@paquier.xyz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox