Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g5C9O-00073s-Fh for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Sep 2018 15:54:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g5C9L-0006vp-SW for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Sep 2018 15:54:51 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g5C9L-0006vh-98 for pgsql-hackers@lists.postgresql.org; Wed, 26 Sep 2018 15:54:51 +0000 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g5C9G-0004TJ-Jt for pgsql-hackers@postgresql.org; Wed, 26 Sep 2018 15:54:49 +0000 Received: by mail-qt1-x843.google.com with SMTP id n6-v6so17756094qtl.4 for ; Wed, 26 Sep 2018 08:54:46 -0700 (PDT) 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:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=AN165lKNle6PN0rE1UZgz6J0rqfH38xjedHusWVQvLw=; b=Xyf/GIgA2jKRW2J82568s+whHGrOVpygHhWttKbYIm8Odmd+7jYghMfeea/IO0XS47 JaxtaBx8e/4DIeBKyUPEz57W2dNhJFQsM7odEOWNuGLB9UvvdIhRO70rkrWJS6qXpUqL esdWu/j6ug2Jns5x7oU7wZJolMhefuAF2In/HPVWz5mq1n4l5f+yBwTk83OXikF5EWsT z55LUi92NF1XGgkw6CGBvu/y6/Rwmk0X7iQ1iQNQxdDn+RaBGfX8RPHnimh7CzL/dqEV /kMijiAOlQ+VpBvOiXDiV8AdT3bpOiMlpfb1zmtff+U+EGjvDq72PJzOrw4agG63ZDIm YxbA== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=AN165lKNle6PN0rE1UZgz6J0rqfH38xjedHusWVQvLw=; b=K30KK1llvV07CPA5ArV6KEmbT5wVbXpqJZO2v1wPyiZfMaNzb75NyEwkbsifnh5Hgy B3CxY8pQ/XRFOkjZNNv8uZK9uwd5KD93AdROxxjWu5hQZ8txJLV9woNPOCyPctb+jVmM xK/ujU2su2yJbAz291K6bUZu+czLJqOipyru0E/gFhKroGIX55WqZe2VpZCW6o49+avA juJZLA5d6HBqqO/JYCiYs38acM5vVTEt72fqIOBrGHQqjWng3BUPtMuDMgL9R5zC7F5C Ebv6dYLqCG0Oy6QFcJctsMaGr+6d91Y7eHUxCXR8H76EVbQ4lYJ3WoFZvASYu5AzwzRP XlEQ== X-Gm-Message-State: ABuFfoiATigHxSpxWJg/Z7X1fkF7I/DOKq5U6V6Omlr6elLfTKByXQQX WRvwuOcRvDU446EsRIhmRV3aTQ== X-Google-Smtp-Source: ACcGV629Lz4s4iLdmU+2q9otmN9GwdXuu2dLn7M+ORsShR4ucYySCpgL9DPe9oP/z6Xb/OBgiGN3/A== X-Received: by 2002:a0c:ae15:: with SMTP id y21-v6mr4711637qvc.233.1537977285610; Wed, 26 Sep 2018 08:54:45 -0700 (PDT) Received: from alvin.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id t15-v6sm1566203qke.74.2018.09.26.08.54.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 26 Sep 2018 08:54:45 -0700 (PDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 3B7AE6B9; Wed, 26 Sep 2018 12:54:43 -0300 (-03) Date: Wed, 26 Sep 2018 12:54:43 -0300 From: Alvaro Herrera To: Tom Lane Cc: Bruce Momjian , Peter Eisentraut , Michael Paquier , Andres Freund , PostgreSQL-development Subject: Re: transction_timestamp() inside of procedures Message-ID: <20180926155443.u4zh7jactzflys3z@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3264.1537972561@sss.pgh.pa.us> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2018-Sep-26, Tom Lane wrote: > Alvaro Herrera writes: > > On 2018-Sep-26, Tom Lane wrote: > >> I agree that it would be surprising for transaction timestamp to be newer > >> than statement timestamp. So for now at least, I'd be satisfied with > >> documenting the behavior. > > > Really? I thought it was practically obvious that for transaction- > > controlling procedures, the transaction timestamp would not necessarily > > be aligned with the statement timestamp. The surprise would come > > together with the usage of the new feature, so existing users would not > > be surprised in any way. > > Nope. That's the same poor reasoning we've fallen into in some other > cases, of assuming that "the user" is a point source of knowledge. > But DBMSes tend to interact with lots of different code. If some part > of application A starts using intraprocedure transactions, and then > application B breaks because it wasn't expecting to see xact_start > later than query_start in pg_stat_activity, you've still got a problem. While that's true, I think it's also highly hypothetical. What could be the use for the transaction timestamp? I think one of the most important uses (at least in pg_stat_activity) is to verify that transactions are not taking excessively long time to complete; that's known to cause all sorts of trouble in Postgres, and probably other DBMSs too. If we don't accurately measure what it really is, and instead keep the compatibility behavior, we risk panicking people because they think some transaction has been running for a long time when in reality it's just a very long procedure which commits frequently enough not to be a problem. > I'm also a bit hesitant to invent new semantics here based on the > assumption that we've got only one, nonoverlapping, top-level transaction > at a time. It's not terribly hard to imagine suspend-and-resume- > transaction features coming down the pike at some point. What will > we do then? We'll already have a definitional issue for xact_start, > but it'll get worse the more different kinds of xact_start we have. This is even more hypothetical. If we can have a list or stack of running transactions, clearly a single timestamp value is not sufficient. We could report a single value for "the oldest transaction", or perhaps "the transaction that's currently active". But if we wanted to be really thorough about it, we'd need to report the list of timestamps for each running transaction in the current session. However, I don't think those future developments would change what the transaction timestamp is, namely, the start of the current transaction, not the start of the statement that (after possibly many iterations) gave rise to the current transaction. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services