Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h2RCG-0001xz-Bj for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Mar 2019 01:54:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h2RCF-0003cz-42 for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Mar 2019 01:54:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h2RCE-0003ac-Ri for pgsql-hackers@lists.postgresql.org; Sat, 09 Mar 2019 01:54:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h2RCB-0000Ih-Su for pgsql-hackers@lists.postgresql.org; Sat, 09 Mar 2019 01:54:42 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x291sB3X026657; Fri, 8 Mar 2019 20:54:11 -0500 From: Tom Lane To: Andrew Dunstan cc: David Rowley , Jeff Janes , Jeremy Schneider , Joe Conway , Peter Geoghegan , PostgreSQL Hackers Subject: Re: Should we increase the default vacuum_cost_limit? In-reply-to: <13d143dd-0a44-0c16-218c-bc924b5922f0@2ndQuadrant.com> References: <241b80ab-7af0-c606-7b2c-b0a5d6be696a@joeconway.com> <4a068b09-5a6f-e975-07c9-2333fcef0a8a@amazon.com> <30411a5b-ef11-71ef-e9ee-4d26ef3fd0c0@2ndQuadrant.com> <21034.1552068630@sss.pgh.pa.us> <13d143dd-0a44-0c16-218c-bc924b5922f0@2ndQuadrant.com> Comments: In-reply-to Andrew Dunstan message dated "Fri, 08 Mar 2019 20:29:14 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26655.1552096451.1@sss.pgh.pa.us> Date: Fri, 08 Mar 2019 20:54:11 -0500 Message-ID: <26656.1552096451@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andrew Dunstan writes: > Increase it to what? Jeff's opinion that it could be INT_MAX without causing trouble is a bit over-optimistic, see vacuum_delay_point(): if (VacuumCostActive && !InterruptPending && VacuumCostBalance >= VacuumCostLimit) { int msec; msec = VacuumCostDelay * VacuumCostBalance / VacuumCostLimit; In the first place, if VacuumCostLimit is too close to INT_MAX, it'd be possible for VacuumCostBalance (also an int) to overflow between visits to vacuum_delay_point, wrapping around to negative and thus missing the need to nap altogether. In the second place, since large VacuumCostLimit implies large VacuumCostBalance when we do get through this if-check, there's a hazard of integer overflow in the VacuumCostDelay * VacuumCostBalance multiplication. The final value of the msec calculation should be easily within integer range, since VacuumCostDelay is constrained to not be very large, but that's no help if we have intermediate overflow. Possibly we could forestall both of those problems by changing VacuumCostBalance to double, but that would make the cost bookkeeping noticeably more expensive than it used to be. I think it'd be better to keep VacuumCostBalance as int, which would then mean we'd better limit VacuumCostLimit to no more than say INT_MAX/2 --- call it 1 billion for the sake of a round number. That'd still leave us at risk of an integer overflow in the msec-to-sleep calculation, but that calculation could be changed to double at little price, since once we get here we're going to sleep awhile anyway. BTW, don't forget autovacuum_cost_limit should have the same maximum. regards, tom lane