Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pdbKL-0001PR-Ay for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Mar 2023 18:30:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pdbKJ-0001Vq-Sa for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Mar 2023 18:30:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pdbKJ-0001Vg-8p for pgsql-hackers@lists.postgresql.org; Sat, 18 Mar 2023 18:30:47 +0000 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pdbKD-0004pw-CD for pgsql-hackers@postgresql.org; Sat, 18 Mar 2023 18:30:46 +0000 Received: by mail-il1-x134.google.com with SMTP id l15so2944534ilv.4 for ; Sat, 18 Mar 2023 11:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; t=1679164240; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=hl2rsU+j+8HVmWGbhl//0Igo3JW7dnIQ4CKzLCzv+KU=; b=Cev7YQUuLFhqR4+WJ+DXYUhAoZzzmYHEmoR7RjqcXMch1CymPO96urMvJ/40aX9p2Z 1q8ty20CbL/uj1MazPVOkYAorkX9wiWNU1suDvpsNK0gJrhWdtRd1TjdZ1cIOpRXM8pG g2+u4gF/zU+b1CF0PJIYpTV1ZGAbtgVbXiL1pFtBG5V9xEe5ORKczGqEQfjGIe8v1HrH Rc2gTYGkQBiyAYgPGlkvyvY2POxpxE/1vVswK5V7RyooOsF/RLAT78RcCQer4oXTE5UK Nu9VeRWL01n2UugmTJHWGmFKOr5r/KueHngFRFPgrpeQxvIbBjUeFDJaAKZT6C6Jbz6G I0/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679164240; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hl2rsU+j+8HVmWGbhl//0Igo3JW7dnIQ4CKzLCzv+KU=; b=G2D6yxs0UFQBly0UOQJI2sqAcWloY04yDn3lzAfOi3gRvxgdYIMCP0hN249TEMBcKl 4KBMbtz6o3/E5bE3OmdqoPDc5Sw3NHYjDQGHjUOw0MiPyzb+RtdPfWjiZ7LkiOuQ9cmG lbxb4h3/P/+VjPiCND0y1CYWbhH7lFjkRMe6nHQt/9vtGSzgn00nDkNmidfcBt9xhX+U UQVz66f77ubDhAVGAjBjTXMYNXTj76hh4Fm7agC/V1w8GUX1UwiOwp44vZsEQCavx0B9 47aKC1GlYDknr3dBVmfXZAV1GmMOQl0NWe9VA+Vm5PkyHaENmZK6uiAVbAgYkVokZUmp F3dg== X-Gm-Message-State: AO0yUKX5NfLXXwhTF7mwA9FlHlVmFW7Z4iWXjkK7/xNLvpjcPlWdmSC8 7aFWkkPIb7DpuSfGisuP5g1shQ== X-Google-Smtp-Source: AK7set/PZZ1Mhezk9ijsoVALsZ5XCaMumGxgye4l0fzFXK7IpNZJKMV2R95ezZC/ps12RLJzM3BE6w== X-Received: by 2002:a92:d592:0:b0:315:6fc5:ea46 with SMTP id a18-20020a92d592000000b003156fc5ea46mr1791055iln.2.1679164240237; Sat, 18 Mar 2023 11:30:40 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id c7-20020a929407000000b003232362a4c2sm1527343ili.8.2023.03.18.11.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 11:30:39 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 53D16800B1F; Sat, 18 Mar 2023 13:30:38 -0500 (CDT) Date: Sat, 18 Mar 2023 13:30:38 -0500 From: Justin Pryzby To: Melanie Plageman Cc: Masahiko Sawada , Bharath Rupireddy , Andres Freund , Tom Lane , Peter Geoghegan , pgsql-hackers@postgresql.org, Robert Haas , David Rowley Subject: Re: Option to not use ringbuffer in VACUUM, using it in failsafe mode Message-ID: References: <20230111191842.5ywh7twkis42kxad@awork3.anarazel.de> <669645.1673471914@sss.pgh.pa.us> <20230111213905.4ljixbm2oyqzvzzx@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > Subject: [PATCH v4 3/3] add vacuum[db] option to specify ring_size and guc > + Specifies the ring buffer size to be used for a given invocation of > + VACUUM or instance of autovacuum. This size is > + converted to a number of shared buffers which will be reused as part of I'd say "specifies the size of shared_buffers to be reused as .." > + a Buffer Access Strategy. 0 will > + disable use of a Buffer Access Strategy. > + -1 will set the size to a default of 256 > + kB. The maximum ring buffer size is 16 GB. > + Though you may set vacuum_buffer_usage_limit below > + 128 kB, it will be clamped to 128 > + kB at runtime. The default value is -1. > + This parameter can be set at any time. GUC docs usually also say something like "If this value is specified without units, it is taken as .." > + is used to calculate a number of shared buffers which will be reused as *the* number? > + VACUUM. The analyze stage and parallel vacuum workers > + do not use this size. I think what you mean is that vacuum's heap scan stage uses the strategy, but the index scan/cleanup phases doesn't? > + The size in kB of the ring buffer used for vacuuming. This size is used > + to calculate a number of shared buffers which will be reused as part of *the* number > +++ b/doc/src/sgml/ref/vacuumdb.sgml The docs here duplicate the sql-vacuum docs. It seems better to refer to the vacuum page for details, like --parallel does. Unrelated: it would be nice if the client-side options were documented separately from the server-side options. Especially due to --jobs and --parallel. > + if (!parse_int(vac_buffer_size, &result, GUC_UNIT_KB, NULL)) > + { > + ereport(ERROR, > + (errcode(ERRCODE_SYNTAX_ERROR), > + errmsg("buffer_usage_limit for a vacuum must be between -1 and %d. %s is invalid.", > + MAX_BAS_RING_SIZE_KB, vac_buffer_size), > + parser_errposition(pstate, opt->location))); > + } > + > + /* check for out-of-bounds */ > + if (result < -1 || result > MAX_BAS_RING_SIZE_KB) > + { > + ereport(ERROR, > + (errcode(ERRCODE_SYNTAX_ERROR), > + errmsg("buffer_usage_limit for a vacuum must be between -1 and %d", > + MAX_BAS_RING_SIZE_KB), > + parser_errposition(pstate, opt->location))); > + } I think these checks could be collapsed into a single ereport(). if !parse_int() || (result < -1 || result > MAX_BAS_RINGSIZE_KB): ereport(ERROR, errcode(ERRCODE_SYNTAX_ERROR), errmsg("buffer_usage_limit for a vacuum must be an integer between -1 and %d", MAX_BAS_RING_SIZE_KB), There was a recent, similar, and unrelated suggestion here: https://www.postgresql.org/message-id/20230314.135859.260879647537075548.horikyota.ntt%40gmail.com > +#vacuum_buffer_usage_limit = -1 # size of vacuum buffer access strategy ring. > + # -1 to use default, > + # 0 to disable vacuum buffer access strategy and use shared buffers I think it's confusing to say "and use shared buffers", since "strategies" also use shared_buffers. It seems better to remove those 4 words. > @@ -550,6 +563,13 @@ vacuum_one_database(ConnParams *cparams, > pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", > "--parallel", "13"); > > + // TODO: this is a problem: if the user specifies this option with -1 in a > + // version before 16, it will not produce an error message. it also won't > + // do anything, but that still doesn't seem right. Actually, that seems fine to me. If someone installs v16 vacuumdb, they can run it against old servers and specify the option as -1 without it failing with an error. I don't know if anyone will find that useful, but it doesn't seem unreasonable. I still think adding something to the glossary would be good. Buffer Access Strategy: A circular/ring buffer used for reading or writing data pages from/to the operating system. Ring buffers are used for sequential scans of large tables, VACUUM, COPY FROM, CREATE TABLE AS SELECT, ALTER TABLE, and CLUSTER. By using only a limited portion of >shared_buffers<, the ring buffer avoids avoids evicting large amounts of data whenever a backend performs bulk I/O operations. Use of a ring buffer also forces the backend to write out its own dirty pages, rather than leaving them behind to be cleaned up by other backends. If there's a larger section added than a glossary entry, the text could be promoted from src/backend/storage/buffer/README to doc/. -- Justin