Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uHVTw-003XhY-3s for pgsql-hackers@arkaria.postgresql.org; Tue, 20 May 2025 22:30:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uHVTv-000AB7-0Y for pgsql-hackers@arkaria.postgresql.org; Tue, 20 May 2025 22:30:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uHVTu-000AAv-Kn for pgsql-hackers@lists.postgresql.org; Tue, 20 May 2025 22:30:42 +0000 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uHVTr-0001cT-2b for pgsql-hackers@lists.postgresql.org; Tue, 20 May 2025 22:30:42 +0000 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-328b943ae7bso34160711fa.3 for ; Tue, 20 May 2025 15:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747780238; x=1748385038; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BdnST+MLhtd3rYF7POgbcT2WQTmktJ4901UOZ5AFsXc=; b=Hi5tIFqwmz1Pb67la6jgyhRkn7ZTPUEWcYWmdADjuiFecGwrnGXAfSusnGlvI9s13q 5d7OYg0ukgi/t5tynM5VcF6ZxLFCfITSg5o8ZN/pb0tiqksZ6FBIW0UVH3LXDalqo7BW Cl3evtsfo/1IBZfCnfmZ9Bd9CxNnXfm3cJqaiyYgfP+w8929YgQCLvRp8DXNHw3MpLtk +ebR0IuVeFcn9+QIKyUNcCJSZ2UhHmoEYEBCYET+9xh1lgbQZhSFyVaWIm8hX1911JQW Zm5mH9FC+7wRL6BlZlo+ayHEmrIGTJMfIo3azFUn12Pv98+0uN2VDqvWu5gIJ+C5tdzz BRUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747780238; x=1748385038; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BdnST+MLhtd3rYF7POgbcT2WQTmktJ4901UOZ5AFsXc=; b=XA0RnXYFPXZ/Z2v1chzzgQZjl3nvhjSTNDnnnHC1H/dp91qcSf6e4n47Vz45dQsCnx LXYoE+rCjHbHJaRvu4aOEMmANMlK9yNqCjXrdp5OZu88O8Vdz3pi9WDWhXAnb1uKVeay 6YDwHywEXzgZgdABARYcsvP1vtjfp/3/a2cqRBlJhaD0iB89hUXasPrAIMupDCYFc5es xcJpMqCLnR47lLxNfe9+FbS4T+3mT4e7/ZmbaM8KJDXR+a7tPJvMcyj0cmNfxjPi3kww s+4okEz4ffNbZ1BygStCN+NEpFtTDg4ScJIDqa7Lnw70qAEFH3a50qRZutmigJcgvUzJ 5W1g== X-Forwarded-Encrypted: i=1; AJvYcCUEtZYVskqBzVciVnthh7K0N4RpAABZ1CLAcW8hnSs1Mi2C7FSAdhfWQBkqOybShVsEuXCM7Tl2mtDPx0Xh@lists.postgresql.org X-Gm-Message-State: AOJu0YyfdwQiUJKpQb93tsMILJoTiQ0dppbjIgdVBR+N1Y+fXc8UL4wE w1kcTS3MI3vWzUEt0mrlhOhz3rGLrUlWsWg/4kv2vkU5OA+UvSDyfkak8fYquC0zOEcOHDEDfTG 3i9qT7r4c/UwF6OTlDwQLZ48EQvxtleAERM4+ X-Gm-Gg: ASbGncsCNMLV0L32lxhE8EvNmiCiD0wJIAAy9hpX53+xgkZ504ngBlu0LE2itVgSEVA h+AY1vT0Fi6v9YWQXC2ZIpoG6R83xCDoPYWTGXkCiPAWmb5RgT9wT/yei1m2EcF8DHNU2dxqfrm Q3n0fZStnVHSuulDC5/4ZvlJZr611UGjd5Xmzavavn/NJw X-Google-Smtp-Source: AGHT+IHh7hoAMjgO3pu3gj1cQcpV+EG+QNgoUQPQwnqIJPPgUOGENd5bHJZvCZbecYvtlLN2BGrHFqeahusiNNVI5LY= X-Received: by 2002:a2e:a546:0:b0:30b:c07d:29f3 with SMTP id 38308e7fff4ca-328077570e0mr63088231fa.21.1747780237985; Tue, 20 May 2025 15:30:37 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Masahiko Sawada Date: Tue, 20 May 2025 15:30:01 -0700 X-Gm-Features: AX0GCFtcl6EBFR0ii6hpMvlfVh3HMI-Wy6YTgb9zpMD6rgP2Je3CmHfTQVqsScM Message-ID: Subject: Re: POC: Parallel processing of indexes in autovacuum To: Daniil Davydov <3danissimo@gmail.com> Cc: Matheus Alcantara , Sami Imseih , Maxim Orlov , Postgres hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, May 15, 2025 at 10:10=E2=80=AFPM Daniil Davydov <3danissimo@gmail.c= om> wrote: > > Hi, > > On Fri, May 16, 2025 at 4:06=E2=80=AFAM Matheus Alcantara > wrote: > > I've reviewed the v1-0001 patch, the build on MacOS using meson+ninja i= s > > failing: > > =E2=9D=AF=E2=9D=AF=E2=9D=AF ninja -C build install > > ninja: Entering directory `build' > > [1/126] Compiling C object > > src/backend/postgres_lib.a.p/utils_misc_guc_tables.c.o > > FAILED: src/backend/postgres_lib.a.p/utils_misc_guc_tables.c.o > > ../src/backend/utils/misc/guc_tables.c:3613:4: error: incompatible > > pointer to integer conversion initializing 'int' with an expression of > > type 'void *' [-Wint-conversion] > > 3613 | NULL, > > | ^~~~ > > > > Thank you for reviewing this patch! > > > It seems that the "autovacuum_reserved_workers_num" declaration on > > guc_tables.c has an extra gettext_noop() call? > > Good catch, I fixed this warning in the v2 version. > > > > > One other point is that as you've added TAP tests for the autovacuum I > > think you also need to create a meson.build file as you already create > > the Makefile. > > > > You also need to update the src/test/modules/meson.build and > > src/test/modules/Makefile to include the new test/modules/autovacuum > > path. > > > > OK, I should clarify this moment : modules/autovacuum is not a normal > test but a sandbox - just an example of how we can trigger parallel > index autovacuum. Also it may be used for debugging purposes. > In fact, 001_autovac_parallel.pl is not verifying anything. > I'll do as you asked (add all meson and Make stuff), but please don't > focus on it. The creation of the real test is still in progress. (I'll > try to complete it as soon as possible). > > In this letter I will divide the patch into 2 parts : implementation > and sandbox. What do you think about implementation? Thank you for updating the patches. I have some comments on v2-0001 patch: + { + {"autovacuum_reserved_workers_num", PGC_USERSET, RESOURCES_WORKER_PROCESSES, + gettext_noop("Number of worker processes, reserved for participation in parallel index processing during autovacuum."), + gettext_noop("This parameter is depending on \"max_worker_processes\" (not on \"autovacuum_max_workers\"). " + "*Only* autovacuum workers can use these additional processes. " + "Also, these processes are taken into account in \"max_parallel_workers\"."), + }, + &av_reserved_workers_num, + 0, 0, MAX_BACKENDS, + check_autovacuum_reserved_workers_num, NULL, NULL + }, I find that the name "autovacuum_reserved_workers_num" is generic. It would be better to have a more specific name for parallel vacuum such as autovacuum_max_parallel_workers. This parameter is related to neither autovacuum_worker_slots nor autovacuum_max_workers, which seems fine to me. Also, max_parallel_maintenance_workers doesn't affect this parameter. Which number does this parameter mean to specify: the maximum number of parallel vacuum workers that can be used during autovacuum or the maximum number of parallel vacuum workers that each autovacuum can use? --- The patch includes the changes to bgworker.c so that we can reserve some slots for autovacuums. I guess that this change is not necessarily necessary because if the user sets the related GUC parameters correctly the autovacuum workers can use parallel vacuum as expected. Even if we need this change, I would suggest implementing it as a separate patch. --- + { + { + "parallel_idx_autovac_enabled", + "Allows autovacuum to process indexes of this table in parallel mode", + RELOPT_KIND_HEAP, + ShareUpdateExclusiveLock + }, + false + }, The proposed reloption name doesn't align with our naming conventions. Looking at our existing reloptions, we typically write out full words rather than using abbreviations like 'autovac' or 'idx'. The new reloption name seems not to follow the conventional naming style for existing reloption. For instance, we don't use abbreviations such as 'autovac' and 'idx'. I guess we can implement this parameter as an integer parameter so that the user can specify the number of parallel vacuum workers for the table. For example, we can have a reloption autovacuum_parallel_workers. Setting 0 (by default) means to disable parallel vacuum during autovacuum, and setting special value -1 means to let PostgreSQL calculate the parallel degree for the table (same as the default VACUUM command behavior). I've also considered some alternative names. If we were to use parallel_maintenance_workers, it sounds like it controls the parallel degree for all operations using max_parallel_maintenance_workers, including CREATE INDEX. Similarly, vacuum_parallel_workers could be interpreted as affecting both autovacuum and manual VACUUM commands, suggesting that when users run "VACUUM (PARALLEL) t", the system would use their specified value for the parallel degree. I prefer autovacuum_parallel_workers or vacuum_parallel_workers. --- + /* + * If we are running autovacuum - decide whether we need to process ind= exes + * of table with given oid in parallel. + */ + if (AmAutoVacuumWorkerProcess() && + params->index_cleanup !=3D VACOPTVALUE_DISABLED && + RelationAllowsParallelIdxAutovac(rel)) I think that this should be done in autovacuum code. --- +/* + * Minimum number of dead tuples required for the table's indexes to be + * processed in parallel during autovacuum. + */ +#define AV_PARALLEL_DEADTUP_THRESHOLD 1024 + +/* + * How many indexes should process each parallel worker during autovacuum. + */ +#define NUM_INDEXES_PER_PARALLEL_WORKER 30 These fixed values really useful in common cases? I think we already have an optimization where we skip vacuum indexes if the table has fewer dead tuples (see BYPASS_THRESHOLD_PAGES). Given that we rely on users' heuristics which table needs to use parallel vacuum during autovacuum, I think we don't need to apply these conditions. Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com