Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iee8b-0003eQ-G0 for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Dec 2019 11:57:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iee8Z-0002Be-VF for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Dec 2019 11:57:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iee8Z-0002BX-Dj for pgsql-hackers@lists.postgresql.org; Tue, 10 Dec 2019 11:57:07 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iee8S-0008Ob-DD for pgsql-hackers@postgresql.org; Tue, 10 Dec 2019 11:57:06 +0000 Received: by mail-wm1-x342.google.com with SMTP id c20so2838930wmb.0 for ; Tue, 10 Dec 2019 03:57:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=TpBwsAUhTQ+vzpf6eBGf1K17te0eRHsPOV20AkXZG+c=; b=S8f6MFKMEgVHPufDhpPrYcSHXhYj+m0MQeNfVLlsxO2J7Z4SkHUoNn5JeKeRmN8GJv UTIo16JNSrh50agGaJMJIUe7CLfbZVKXx1F4vcAnESk1Ui5F7OshVd1qPu+VGI3ZbbH9 IfTBSuS2vxxQNOYdkX6AC/kUUHm0ssm9ufPzyaXxhPpITBoEFV0HAFbCTdl91BN1yJ1I EadyqnxFkC4khGg9CE+VxjpgMqyDEjVVxS34sUmYwE9UNdQ82RZFanFfUIayzstaCgEq Kd1/8Ns7LG1evDzqweW4OKy34oopLvoMfrJ5Tvtd246rC7ViaRXzji/rsbZDHeMZ2lUR gERw== 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; bh=TpBwsAUhTQ+vzpf6eBGf1K17te0eRHsPOV20AkXZG+c=; b=k1UTltsk8thxfjpH9e+0/03r89VIRfiBZ3fUx92MxaSwqaluFkY1FYaAQ07uNZXgQT Rm+VztfmitpRwuXu0RNPCKlHLVialQxjbDg2F1YxyCAqUpkkSLXyMhxV7TgQliexMZjl oDfBHB6y4yzeVYq2KSXlZ5QKkDUOVXnnrI76zaCu7E8t7U5/g/JAF57QPYOPAFJxYyGW Be0/sxHmSckVgpVt+kK7CdpDOknArfr3sxwHPHFoX7fHu5/21Ol9/PWH61P1OEYAq271 Fki3wz6qqJhOjw0psVMr0m2IpOsPH6u9qijfYa5snDGtD+dEziokvkjHQHp1wB2nPF1U UC4g== X-Gm-Message-State: APjAAAV+fCHxT3lVzsXOT5t6ITUxE4QHFfLCr/mfkTbKBEdkk5ZJDMVe LN6HMAb1C+HjWs0zNsDaXHphNl/H3BU= X-Google-Smtp-Source: APXvYqwIbPBPsskGXT2nE9vIE5CfTZiAYNka+K1EJIGBPYebYzxMyKEoONtphMttPCm5YSAS3Zl9xQ== X-Received: by 2002:a7b:c416:: with SMTP id k22mr4527618wmi.10.1575979018762; Tue, 10 Dec 2019 03:56:58 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id b10sm3042868wrt.90.2019.12.10.03.56.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 03:56:57 -0800 (PST) Date: Tue, 10 Dec 2019 12:56:56 +0100 From: Tomas Vondra To: Andres Freund Cc: pgsql-hackers@postgresql.org Subject: Re: xact_start for walsender & logical decoding not updated Message-ID: <20191210115656.6nmx6cndqfa4dami@development> References: <20191209234409.exe7osmyalwkt5j4@development> <20191210000440.daqpb6nvk3dpcblr@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20191210000440.daqpb6nvk3dpcblr@alap3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Dec 09, 2019 at 04:04:40PM -0800, Andres Freund wrote: >Hi, > >On 2019-12-10 00:44:09 +0100, Tomas Vondra wrote: >> I think there's a minor bug in pg_stat_activity tracking of walsender >> processes. The issue is that xact_start is only updated at the very >> beginning when the walsender starts (so it's almost exactly equal to >> backend_start) and then just flips between NULL and that value. >> >> Reproducing this is trivial - just create a publication/subscription >> with the built-in logical replication, and run arbitrary workload. >> You'll see that the xact_start value never changes. >> >> I think the right fix is calling SetCurrentStatementStartTimestamp() >> right before StartTransactionCommand() in ReorderBufferCommit, per the >> attached patch. > >> -- >> Tomas Vondra http://www.2ndQuadrant.com >> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services > >> diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c >> index 53affeb877..5235fb31b8 100644 >> --- a/src/backend/replication/logical/reorderbuffer.c >> +++ b/src/backend/replication/logical/reorderbuffer.c >> @@ -1554,7 +1554,10 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid, >> if (using_subtxn) >> BeginInternalSubTransaction("replay"); >> else >> + { >> + SetCurrentStatementStartTimestamp(); >> StartTransactionCommand(); >> + } > >I'm quite doubtful this is useful. To me this seems to do nothing but >add the overhead of timestamp computation - which isn't always that >cheap. I don't think you really can draw meaning from this? > I don't want to use this timestamp directly, but it does interfere with monitoring of long-running transactiosn looking at pg_stat_activity. With the current behavior, the walsender entries have ancient timestamps and produce random blips in monitoring. Of course, it's possible to edit the queries to skip entries with backend_type = walsender, but that's a bit inconvenient. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services