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 1u7sxr-0094OQ-K9 for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Apr 2025 09:33:52 +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 1u7sxp-00F5Id-Pk for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Apr 2025 09:33:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u7sxo-00F5IV-S6 for pgsql-hackers@lists.postgresql.org; Thu, 24 Apr 2025 09:33:49 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u7sxn-001gbO-0g for pgsql-hackers@postgresql.org; Thu, 24 Apr 2025 09:33:48 +0000 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-5e5e63162a0so1180048a12.3 for ; Thu, 24 Apr 2025 02:33:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1745487226; x=1746092026; darn=postgresql.org; h=message-id:date:content-transfer-encoding:content-id:mime-version :comments:references:in-reply-to:subject:cc:to:from:from:to:cc :subject:date:message-id:reply-to; bh=JzE799M1kXr+KnnlaifVWZLLvFdsd1XQrvSiV3miauk=; b=irrzTjlaySLWeS7Nnlb7o3LQoVyZCZmZUvNptHNlozwQ+cDs3c/BqSE9Skl5YjJeol PoZqoGdHX+y77nYi8Ufi/nWS8Usy0wsj2nt8ADNUYmB8/hsDUbL3l+LqzDjaND/oJpQe ftCtUtQGP1n2g91/AgZxQF0Zdu9qNF8NT1GZIf1cnj8NqsxMw/S7PSykozsFzx8pyh31 ovcMW9YX5VnWx1FmDW35H4+O2RFmDePfGERKj9+C0RE1xEYu9GhOXgjtLOzrSbvfO8Aa m3Vsgk56cqr9FQg3B64P8ps3D5GKzDpqRJGGkNxQijC390OX0Yr7QEeJ5GT5HAHRN9BE gYZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745487226; x=1746092026; h=message-id:date:content-transfer-encoding:content-id:mime-version :comments:references:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JzE799M1kXr+KnnlaifVWZLLvFdsd1XQrvSiV3miauk=; b=KOX6owidyL+JovzdcLWcV29kYJqFlqOSxxSPwZ5/cWsjFtzz5/ufFyeJ8yq4cmoIyg aeB7glSbbPyXOoMoiqpfsWrKmrRrJ1XYNSPSDIt48SYM3WgWDxUuleVW2me5DD/NBRsA /SaKGI210TvUxcZ4nIsZmnhMU4hFa2qulQyPyvFWComrls3rSDjY2QHi/erpez6gw+EL VCHLzD+cqQ7RjmxrqSZLZ+fVyN1Jdh1JBMeXzGlV1QfSFCqUI3JlpiYu0EBTkSFJUSLs TytCN6OtTKXXUbsqyUa03nzFwzwDYiUNwz1SGWyJ7VJ3Tb/Lh77o/JsXbB21wjNFq7MX zvNQ== X-Gm-Message-State: AOJu0Yy8iryfpZCnjn8454qiZvEwZaP0ithKRxCLDkDhwfkz2gNuMcmX GNpyKcXtr3CoDcy32Y6SCxGlDzYSDhZYoPNdHDHtEBWX8lNS171UfOwsRvYIycs= X-Gm-Gg: ASbGnctSYhBw6OKuSB80iG2bf/2Ii1BwhyjVVg2/uv1QZ/eWSRJ0anMLXlAeXTGhgE1 MfhQfL2q0uSK5SVR7QlA873P5OLHjxjRRbQJ8ArgiHNBf5PqR/v/YM0Opym1XO5fACfMXIlLUS3 C+vhI667JGN1yCXjwi6fGEEvi2sBeIL5YuNn0b2Miopy3g2YwwsCAiWVnFDdUKUKPSsbEfOeG69 iHWvdmT+/Qt2gYPRBcltYR7Fi4lDoyS83n5wUuoWsyXqaEcvAWTwj26mg2rsUt4IdDRGZB80Xju AcgbbQTTS4Sd2VeFWsqQa3SA1xBhf9noHnJqVkMwD81/HVBzWH12 X-Google-Smtp-Source: AGHT+IF90Nin8Hbtvj4YU9kFZt7rgFLd7ymI8rD1ZXI3RbCGrtGC5tlrd4m8L7SCyPGpWzFvbg2BdQ== X-Received: by 2002:a17:907:728d:b0:ac6:f4c1:b797 with SMTP id a640c23a62f3a-ace57246309mr202755166b.19.1745487226088; Thu, 24 Apr 2025 02:33:46 -0700 (PDT) Received: from localhost (109-81-174-36.rct.o2.cz. [109.81.174.36]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ace59bb8a07sm78478366b.97.2025.04.24.02.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 02:33:45 -0700 (PDT) From: Antonin Houska To: Sami Imseih cc: pgsql-hackers@postgresql.org Subject: Re: Conflicting updates of command progress In-reply-to: References: <117147.1744380740@localhost> <17632.1745403972@localhost> Comments: In-reply-to Sami Imseih message dated "Wed, 23 Apr 2025 15:20:27 -0500." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4745.1745487225.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Thu, 24 Apr 2025 11:33:45 +0200 Message-ID: <4746.1745487225@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Sami Imseih wrote: > >> pgstat_progress_start_command should only be called once by the entry > >> point for the > >> command. In theory, we could end up in a situation where start_comman= d > >> is called multiple times during the same top-level command; > = > > Not only in theory - it actually happens when CLUSTER is rebuilding in= dexes. > = > In the case of CLUSTER, pgstat_progress_start_command is only called onc= e, > but pgstat_progress_update_param is called in the context of both CLUSTE= R > and CREATE INDEX. pgstat_progress_start_command() is called twice: First with cmdtype=3DPROGRESS_COMMAND_CLUSTER, second with PROGRESS_COMMAND_CREATE_INDEX. The first happens in cluster_rel() the seco= nd in cluster_rel() -> rebuild_relation() -> finish_heap_swap() -> reindex_relation() -> reindex_index(). It does not matter though, the current design only expects one command. > > That's a possible approach. However, if the index build takes long tim= e in the > > CLUSTER case, the user will probably be interested in details about th= e index > > build. > = > I agree, > = > >> Is there a repro that you can share that shows the weird values? It s= ounds like > >> the repro is on top of [1]. Is that right? > = > >> You can reproduce the similar problem by creating a trigger function = that > >> runs a progress-reporting command like COPY, and then COPY data into > >> a table that uses that trigger. > = > >> [2] https://commitfest.postgresql.org/patch/5282/ > = > In this case, pgstat_progress_start_command is actually called > twice in the life of a single COPY command; the upper-level COPY > command calls pgstat_progress_start_command and then the nested COPY > command also does calls pgstat_progress_start_command. > = > > I think that can be implemented by moving the progress related fields = from > > PgBackendStatus into a new structure and by teaching the backend to in= sert a > > new instance of that structure into a shared hash table (dshash.c) > = > I think this is a good idea in general to move the backend progress to > shared memory. > and with a new API that will deal with scenarios as described above. > 1/ an (explicit) nested > command was started by a top-level command, such as the COPY case above. > 2/ a top-level command triggered some other progress code implicitly, su= ch as > CLUSTER triggering CREATE INDEX code. Yes, I mean a new API. I imagine pgstat_progress_start_command() to initia= lize the shared memory to track the "nested" command and to put the existing va= lue of MyBEEntry onto a stack. pgstat_progress_end_command() would then restor= e the original value. However, special care is needed for [2] because that's not necessarily nesting: consider merge-joining two foreign tables, both using file_fdw. I= n this case the pointers to the progress tracking shared memory would probab= ly have to be passed as function arguments. (Note that the current progress tracking system also uses shared memory, however in a less flexible way.) > I also like the shared memory approach because we can then not have to u= se > a message like the one introduced in f1889729dd3ab0 to support parallel = index > vacuum progress 46ebdfe164c61. I didn't know about these patches. I'm not sure though if this needs to be removed. Even if each worker updated the progress information separately (would users appreciate that?), it should still send the progress informat= ion to the leader before it (i.e. the worker) exits. -- = Antonin Houska Web: https://www.cybertec-postgresql.com