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 1jwYuQ-0006nq-Q8 for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Jul 2020 22:32:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jwYuO-0001jH-HS for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Jul 2020 22:32:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jwYuO-0001eA-6L for pgsql-hackers@lists.postgresql.org; Fri, 17 Jul 2020 22:32:48 +0000 Received: from mail-io1-xd43.google.com ([2607:f8b0:4864:20::d43]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jwYuF-0003YT-S5 for pgsql-hackers@postgresql.org; Fri, 17 Jul 2020 22:32:46 +0000 Received: by mail-io1-xd43.google.com with SMTP id p205so12000289iod.8 for ; Fri, 17 Jul 2020 15:32:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=rQ9WgJZqdroznXqrPpAt7pLvBGvxHSF8qATIBGDQ22Q=; b=N+/DHNSEousxe98k0hRbkqaeLRWcwOfSJtQC1PYygk5rs1h9srTjLBlX6Tpz9ZD9bo GcZtFOBoHb7TLPjO0s+Xv+qDhICP2HF3oQc1BF3RaI2b8lD97SfH2/YWaUCpPj/Ax4bE YCSeQPk2GwDSXkpWlqanE3XPe8P8glb2e0eAbgEvaaXWSL3PlrA5vIeBR36fA1oh3UTM sny872800j/u+uuQxdbE0NEj3/tjPUgpzB0nXBpzcaBgYvVjM63smlmE1DF8gxnR55fZ 56FK1LtzIiSv5icBl5EvavV80D5N67dnp9sLRS6SknYDzBRc60Zu99bS7Ot/augsIcT3 PGfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=rQ9WgJZqdroznXqrPpAt7pLvBGvxHSF8qATIBGDQ22Q=; b=txoh2b7coC155DgOSU8rcy94sF9LsEjjsgbOm3qYLe6fTo7xXeVHzb3fsa8FpWbB9I C8IOySau6iZhtslVNM7tCZzN0HdeFz5wqXEOXXwzqIA05MGMtEwWrO35DTPI0JWiC1xY j9rSNYrv6hdxpI1H0ebAapTHW+w/0NhhtQLpvX7013B8sRV4j6V3QayHriMrzmEckxho kebSyb/RJzfSuWjQ9YMFMpuPAGUrjEsbmqN7SR+wMPvpMbFg+90bDJpEhfjTR/w7IihV UpjywBg6ljSa0RVbpE7e1hsRBcKs3pZUt2pCOsdwzJEcW5VjA1iMmcLTKZKIYyECGPld /3Jw== X-Gm-Message-State: AOAM5322uxA6x7hDvKenZZAmiWzKR0uk6BR58dNg5KrrW8X2RmGF6zUk vxsoL8jnYSi1ptucYCPswMcmFEmjono= X-Google-Smtp-Source: ABdhPJwCHWgg/8YAFuT34tzLCiUm2iL6Du4x2EPaErfKNQwIoFdTDy0BA1eyJzh1LmDzBKRVbwZa8g== X-Received: by 2002:a05:6602:6c4:: with SMTP id n4mr11661635iox.202.1595025158318; Fri, 17 Jul 2020 15:32:38 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id h1sm5048694iob.8.2020.07.17.15.32.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jul 2020 15:32:37 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 578B580016D; Fri, 17 Jul 2020 17:32:36 -0500 (CDT) Date: Fri, 17 Jul 2020 17:32:36 -0500 From: Justin Pryzby To: Alvaro Herrera Cc: Julien Rouhaud , Michael Paquier , Tomas Vondra , pgsql-hackers Subject: Re: expose parallel leader in CSV and log_line_prefix Message-ID: <20200717223236.GT23581@telsasoft.com> References: <20200717205421.GR23581@telsasoft.com> <20200717212721.GA3827@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200717212721.GA3827@alvherre.pgsql> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Jul 17, 2020 at 05:27:21PM -0400, Alvaro Herrera wrote: > On 2020-Jul-17, Justin Pryzby wrote: > > Ok, but should we then consider changing pg_stat_activity for consistency ? > > Probably in v13 to avoid changing it a year later. > > https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=b025f32e0b5d7668daec9bfa957edf3599f4baa8 > > > > I think the story is that we're exposing to the user a "leader pid" what's > > internally called (and used as) the "lock group leader", which for the leader > > process is set to its own PID. But I think what we're exposing as leader_pid > > will seem like an implementation artifact to users. > > IMO it *is* an implementation artifact if, as you say, the leader PID > remains set after the parallel query is done. I mentioned the pgbouncer > case before: if you run a single parallel query, then the process > remains a "parallel leader" for days or weeks afterwards even if it > hasn't run a parallel query ever since. That doesn't sound great to me. > > I think it's understandable and OK if there's a small race condition > that means you report a process as a leader shortly before or shortly > after a parallel query is actually executed. But doing so until backend > termination seems confusing as well as useless. I'm not sure that connection pooling is the strongest argument against the current behavior, but we could change it as suggested to show as NULL the leader_pid for the leader's own process. I think that's the intuitive behavior a user expects. Parallel processes are those with leader_pid IS NOT NULL. If we ever used lockGroupLeader for something else, you'd also have to say AND backend_type='parallel worker'. We should talk about doing that for PSA and for v13 as well. Here or on the other thread or a new thread ? It's a simple enough change, but the question is if we want to provide a more "cooked" view whcih hides the internals, and if so, is this really enough. --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -737,3 +737,4 @@ pg_stat_get_activity(PG_FUNCTION_ARGS) leader = proc->lockGroupLeader; - if (leader) + if (leader && leader->pid != beentry->st_procpid) { values[29] = Int32GetDatum(leader->pid); -- Justin