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 1jwXNE-0002xR-UC for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Jul 2020 20:54:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jwXND-00087z-U3 for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Jul 2020 20:54:27 +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 1jwXND-00087M-Ir for pgsql-hackers@lists.postgresql.org; Fri, 17 Jul 2020 20:54:27 +0000 Received: from mail-il1-x141.google.com ([2607:f8b0:4864:20::141]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jwXNB-0006tk-2A for pgsql-hackers@postgresql.org; Fri, 17 Jul 2020 20:54:26 +0000 Received: by mail-il1-x141.google.com with SMTP id s21so8462006ilk.5 for ; Fri, 17 Jul 2020 13:54:24 -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=1ycFiazQrNO6AMUq8ABRhOwQK5drzAkUKJDlEiwwQDY=; b=AE9eK4M2X46d+HOsjWrin1JsJPbrXqdAkAGfZuE9b0CLN4rUF9GB8UYo9l0WVdlQJ5 SHkQrgp6mIzWOKG3sHE370KAtdXeCpdeFLMLH9RNOG/lLBNlmqtnhMjvzTF5qKwNujbi CYRQOiULuXf80IQke9LXx3ZnCr0qvK2FgeW0Fh4KsMTvQ8wWGcomD/fR4pDlT7BJSc5P 5WAgFkTstdMhx09nYlTzY9/vnpO9BU5C8wTDUQ7fgRLlqMyARZoHqP+bHFvx2s3dEfHD AKco+u6T9myL3oR1yCicad4nOJNHy2bIyFfGWaNQf0m/nKrvRHsKW+CYQL74BKPfnaC5 R0wQ== 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=1ycFiazQrNO6AMUq8ABRhOwQK5drzAkUKJDlEiwwQDY=; b=KjztMNn3WNimvzET10Atmqsxn4QZLrG6n/MGvdM4LrL2yyZ2EF8fDSI2ZV5P0TxBgs baZJwreCQaD2Xe7JvwINr1RobPlund7vSlui/z7ldy26KCAsNsKfTnxGj3TVS40Ak4+P yjfP+g/XVTpSSdwkDY7oXZK4AAOj16m5KWZI+wgo3G4eTdlukOOZAgubDU4+4ptOXpVX fhnkN7OQrbISvm13x8kayZarHDCPoRHoscFezQlioYVoxe82K/vY0Sqls30jy03gp3yW jBNEGC7GPj4iqFvOQsiogvLEBu7s+haH3fvY7Zuq8t71sFzQ9dgAG7PT9Or05fn276wD W1XQ== X-Gm-Message-State: AOAM530MhGmP3cGr0Ui1541CzsHdVFU5FPsuFT1SZvUHEkcQpOsEibpW ifB2Rp+mc3jQMBLGlilXyRr8Tw== X-Google-Smtp-Source: ABdhPJxdlt6lV/4x55B7TTh7zgXlfIbfWovF/Xa859HW9h9wQk1DhwPDXhkuZ8smo0lcLnFV/mv8AA== X-Received: by 2002:a92:50f:: with SMTP id q15mr11952717ile.38.1595019264007; Fri, 17 Jul 2020 13:54:24 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id g1sm4757319ilk.51.2020.07.17.13.54.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jul 2020 13:54:22 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id D424580016D; Fri, 17 Jul 2020 15:54:21 -0500 (CDT) Date: Fri, 17 Jul 2020 15:54:21 -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: <20200717205421.GR23581@telsasoft.com> References: <20200717153540.GA17100@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200717153540.GA17100@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 11:35:40AM -0400, Alvaro Herrera wrote: > > On Fri, Jul 17, 2020 at 7:01 AM Michael Paquier wrote: > > > > > Hmm. Knowing if a leader is actually running parallel query or not > > > requires a lookup at lockGroupMembers, that itself requires a LWLock. > > > I think that it would be better to not require that. So what if > > > instead we logged %P only if Myproc has lockGroupLeader set and it > > > does *not* match MyProcPid? > > That's what I said first, so +1 for that approach. 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. It's unnatural to define a leader PID for the leader itself, and I'm guessing that at least 30% of people who use pg_stat_activity.leader_pid will be surprised by rows with | backend_type='client backend' AND leader_pid IS NOT NULL And maybe additionally confused if PSA doesn't match CSV or other log. Right now, PSA will include processes "were leader" queries like: | SELECT pid FROM pg_stat_activity WHERE pid=leader_pid If we change it, I think you can get the same thing for a *current* leader like: | SELECT pid FROM pg_stat_activity a WHERE EXISTS (SELECT 1 FROM pg_stat_activity b WHERE b.leader_pid=a.pid); But once the children die, you can't get that anymore. Is that a problem ? I didn't think of it until now, but it would be useful to query logs for processes which were involved in parallel process. (It would be more useful if it indicated the query, and not just the process) I agree that showing the PID as the leader PID while using a connection pooler is "noisy". But I think that's maybe just a consequence of connection pooling. As an analogy, I would normally use a query like: | SELECT session_line, message, query FROM postgres_log WHERE session_id='..' ORDER BY 1 But that already doesn't work usefully with connection pooling (and I'm not sure how to resolve that other than by not using pooling when logs are useful) I'm not sure what the answer. Probably we should either make both expose lockGroupLeader exactly (and not filtered) or make both show lockGroupLeader only if lockGroupLeader!=getpid(). -- Justin