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 1jxfFK-0006Yp-A5 for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Jul 2020 23:30:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jxfFH-00087j-De for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Jul 2020 23:30:55 +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 1jxfFH-00087b-1x for pgsql-hackers@lists.postgresql.org; Mon, 20 Jul 2020 23:30:55 +0000 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jxfFD-0005dT-VL for pgsql-hackers@postgresql.org; Mon, 20 Jul 2020 23:30:53 +0000 Received: by mail-io1-xd41.google.com with SMTP id d18so19463534ion.0 for ; Mon, 20 Jul 2020 16:30:51 -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=1Q8hQw3nfK+zyr7nHAnxV8JgbBZFtEkyHD+RhbGtOL4=; b=MAtKpd9a44dNV2kLsS4fhJ0UoB6ANgUvSUKSwMUsooYOEVOPz/krszWy6OIOaARQkA 35dAJArl6bCCJcHayJMFRZlXmb6vWT00+K1sQjqSxNYNVnFksrvqxFpXRIqWjhXAuHYT cVx8KelT8+/awcvet9O3WRlIjwbKhgPOlBiloFvK6Fl0wkOqs1G3lcG4GDhXqAt8Arnr tu6JvjM6c0x1hWZcJp3wh1tB2nhjsDgJKlTwoM7pnFR5peFc/XHWxcnlKudLHju0b16Y gAF2Ccq2s8ZpsLUZJ+aPbz3Lajj2O/loWwaBMYnhl67bx2ko03EP9O2MH2DmcWLAE+mG deiw== 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=1Q8hQw3nfK+zyr7nHAnxV8JgbBZFtEkyHD+RhbGtOL4=; b=mtJHD02q0s87VGgAf5tEkulhQKbipU4/xpWFp/Hcfn+QJWH1jGGMRHZQxh9bajpKez ZRLEc5bmwQ0H839uczihdwaCVfhJQsxnF1iSBKla8HRn256fubtT+lYEvjKMtZi7j037 rXvkKZUU4GA1M9QOXfjbjQcFD1B8uJXMK6j2Kfu0Kjg8QG8MeRTHOrZXXisHnyXiI6hU Q0/OJ/yjSzdoIfzBVTQP5xWFum/nrquFGJXf0X1YMucnEOp4XIppxcl4H7p/8AeNoV+C dRbfiXlYf7aYObj2ifXFLfxWryybuXTP2HZg2IhHVJBS8nT1aPguZZ2faK7VEJLEHHj2 NUOA== X-Gm-Message-State: AOAM531XtxVJ1LR2ZCMlE39W7GjYQTFG8Us5YN0nkov+UwQO8JTxhoAo 8im61SFxYpwW0VUllKkTDH/sJg== X-Google-Smtp-Source: ABdhPJymszP2BzqLh8eR3pocIiwAZTGeMa6PeisY5RAxd0QsMTKjuhJ58kR95VGLfAv+wBEc4rCukQ== X-Received: by 2002:a05:6638:381:: with SMTP id y1mr29033574jap.85.1595287850867; Mon, 20 Jul 2020 16:30:50 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id x12sm9580440ile.14.2020.07.20.16.30.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jul 2020 16:30:49 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id B3252800272; Mon, 20 Jul 2020 18:30:48 -0500 (CDT) Date: Mon, 20 Jul 2020 18:30:48 -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: <20200720233048.GC5748@telsasoft.com> References: <20200717205421.GR23581@telsasoft.com> <20200717212721.GA3827@alvherre.pgsql> <20200717223236.GT23581@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200717223236.GT23581@telsasoft.com> 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:32:36PM -0500, Justin Pryzby wrote: > 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); This thread is about a new feature that I proposed which isn't yet committed (logging leader_pid). But it raises a question which is immediately relevant to pg_stat_activity.leader_pid, which is committed for v13. So feel free to move to a new thread or to the thread for commit b025f3. I added this to the Opened Items list so it's not lost. I see a couple options: - Update the documentation only, saying something like "leader_pid: the lock group leader. For a process involved in parallel query, this is the parallel leader. In particular, for the leader process itself, leader_pid = pid, and it is not reset until the leader terminates (it does not change when parallel workers exit). This leaves in place the "raw" view of the data structure, which can be desirable, but can be perceived as exposing unfriendly implementation details. - Functional change to show leader_pid = NULL for the leader itself. Maybe the columns should only be not-NULL when st_backendType == B_BG_WORKER && bgw_type='parallel worker'. Update documentation to say: "leader_pid: for parallel workers, the PID of their leader process". (not a raw view of the "lock group leader"). - ?? -- Justin