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 1g8pA3-0003Or-8w for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Oct 2018 16:10:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g8pA1-0002kQ-8A for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Oct 2018 16:10:33 +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 1g8pA0-0002k9-Tl for pgsql-hackers@lists.postgresql.org; Sat, 06 Oct 2018 16:10:33 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g8p9y-0006cE-9q for pgsql-hackers@postgresql.org; Sat, 06 Oct 2018 16:10:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w96GAOKn014826; Sat, 6 Oct 2018 12:10:24 -0400 From: Tom Lane To: Konstantin Knizhnik cc: PostgreSQL Hackers , Robert Haas Subject: Re: now() vs transaction_timestamp() In-reply-to: <9c78b24f-4ec9-e1dd-bdf6-e09e9b5f0e31@postgrespro.ru> References: <6406dbd2-5d37-4cb6-6eb2-9c44172c7e7c@postgrespro.ru> <4268.1538747795@sss.pgh.pa.us> <4911.1538774725@sss.pgh.pa.us> <9c78b24f-4ec9-e1dd-bdf6-e09e9b5f0e31@postgrespro.ru> Comments: In-reply-to Konstantin Knizhnik message dated "Sat, 06 Oct 2018 15:51:17 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14824.1538842224.1@sss.pgh.pa.us> Date: Sat, 06 Oct 2018 12:10:24 -0400 Message-ID: <14825.1538842224@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Konstantin Knizhnik writes: > On 06.10.2018 00:25, Tom Lane wrote: >> So maybe the right answer is to change the parallel mode infrastructure >> so it transmits xactStartTimestamp, making transaction_timestamp() >> retroactively safe, and then in HEAD only we could re-mark now() as >> safe. We might as well do the same for statement_timestamp as well. > Attached please find very small patch fixing the problem (propagating > transaction and statement timestamps to workers). That's a bit too small ;-) ... one demonstrable problem with it is that the parallel worker will report the wrong xactStartTimestamp to pgstat_report_xact_timestamp(), since you aren't jamming the transmitted value in soon enough. Also, I found that ParallelWorkerMain executes at least two transactions before it ever gets to the "main" transaction that does real work, and I didn't much care for the fact that those were running with worker-local values of xactStartTimestamp and stmtStartTimestamp. So I rearranged things a bit to ensure that parallel workers wouldn't generate their own values for either timestamp, and pushed it. regards, tom lane