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 1g0wAz-0002nr-3O for pgsql-general@arkaria.postgresql.org; Fri, 14 Sep 2018 22:02:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g0wAw-0000UU-No for pgsql-general@arkaria.postgresql.org; Fri, 14 Sep 2018 22:02:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0wAw-0000UN-FR for pgsql-general@lists.postgresql.org; Fri, 14 Sep 2018 22:02:54 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0wAp-00068r-KC for pgsql-general@lists.postgresql.org; Fri, 14 Sep 2018 22:02:54 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id EBC9A3DA; Fri, 14 Sep 2018 18:02:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 14 Sep 2018 18:02:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=01PHIYgkqHLGzhx827NpkMpKCrgtZaTYp8WCm/xKdHA=; b=kfJF1huO UNsLRUf43k32n7HWnp4ZXloQJ75e4VSRX8MA1nEVOwL2yeXbsd7JT2t9WoyNV4AS JC1QmImT/5Us+bw2UIB2sOvxCNvGNzFVdA4LAgf7Vr68cMNHyR4ZyK0BdjMQ/6aZ 3PbR+5mgbwFxgbdaxnv6zj+KerFZ18rVmi67MY0vCqh1eISteApGDWHcCGCriMtz BNKhIHAn0b7tmKOT3/ovfrMrtSWUgTS2lhd9wg3EQiQ/kskK6UB//1bUGgkfse2c J1qjjbLHcmqGH3LfRIdrtZqw+vfHJRr/KRa5jFt715i1DtVqXpYg+Vb716wRH9qQ DuFlqIysx+KG0A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=01PHIYgkqHLGzhx827NpkMpKCrgtZ aTYp8WCm/xKdHA=; b=DohIsCToqu9IfNjH9V/jhZMwIVcN12INiUfHk66QcDy2S exBMItyxQklNATDq1koS1XJAq+SLmY/N6ezm+12dFqsgDixq1BPFGK1rNGkUE2PI IxwVHmYH6suA7GLmhhot4E6M8ehN1J+en8okAGPR3TXrg5emiivJJpchJ1pSFhQA eNxD0WFOaAb54+ePClV5kr52h0iXDOr1POEpnBOkRFDQ6+UA+9RBpOvp1MJiFoTy Rx1L6bpayzp65lIMDZL/ADR7jDIFKlSa+EHgp8rLivH8HhY1lgc1cuB8kLCiGZme HiYkxOya4/5n10wCOThriUPttabpz0z9te4lr/gTg== X-ME-Proxy: X-ME-Sender: Received: from intern.anarazel.de (unknown [12.2.149.250]) by mail.messagingengine.com (Postfix) with ESMTPA id C9304E49C8; Fri, 14 Sep 2018 18:02:43 -0400 (EDT) Date: Fri, 14 Sep 2018 15:02:42 -0700 From: Andres Freund To: Andreas Brandl Cc: pgsql-general@lists.postgresql.org Subject: Re: commit timestamps and replication Message-ID: <20180914220242.wxp62zyexuulpcwm@alap3.anarazel.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2018-09-14 21:01:54 +0200, Andreas Brandl wrote: > we're discussing a system design and it boils down to a question > regarding commit timestamps (in the sense of [1], > track_commit_timestamp='on'): > > We have a insert-only (append-only) table. Do commit timestamps on > this table constitute the same order in which records become visible > on a secondary (streaming replication)? Is there any reason why this > might not be the case? > > To put this differently: If a client reads from a secondary and reads > the "latest" record by commit timestamp (commit time T). Is it safe to > assume that there won't ever be another record with a lower commit > timestamp < T, that only shows up on the secondary after that read? No, that's not safe to assume. The order of visibility on the standby is determined by the point the WAL record is inserted into the log. The commit timestamp has to *previously* be determined to be part of the WAL log: SetCurrentTransactionStopTimestamp(); XactLogCommitRecord(xactStopTimestamp, nchildren, children, nrels, rels, nmsgs, invalMessages, RelcacheInitFileInval, forceSyncCommit, MyXactFlags, InvalidTransactionId, NULL /* plain commit */ ); Those two things happen sequentially, *WITHOUT* a lock preventing concurrent transactions to do the same. > I'm aware of concerns regarding physical time, time adjustments and so > on, so the question here assumes those things never happen. Note that in addition to that you cannot be certain that concurrent transactions *in the same postgres cluster* have perfectly coherent timestamp - clock drift between CPU sockets does still sometimes occur, and was extremely common. Greetings, Andres Freund