pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: Andreas Brandl <abrandl@gitlab.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: commit timestamps and replication
Date: Fri, 14 Sep 2018 15:02:42 -0700
Message-ID: <20180914220242.wxp62zyexuulpcwm@alap3.anarazel.de> (raw)
In-Reply-To: <CACTZmE+A8o77akr_X8zXrfVrhru-cCKSOq8D2OgBExDZDvpoKA@mail.gmail.com>
References: <CACTZmE+A8o77akr_X8zXrfVrhru-cCKSOq8D2OgBExDZDvpoKA@mail.gmail.com>

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




view thread (2+ messages)

Message-ID: <20180914220242.wxp62zyexuulpcwm@alap3.anarazel.de>
Permalink:  ../20180914220242.wxp62zyexuulpcwm@alap3.anarazel.de/
Also on:    postgresql.org/message-id/20180914220242.wxp62zyexuulpcwm@alap3.anarazel.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: andres@anarazel.de, abrandl@gitlab.com
  Subject: Re: commit timestamps and replication
  In-Reply-To: <20180914220242.wxp62zyexuulpcwm@alap3.anarazel.de>
  References: <CACTZmE+A8o77akr_X8zXrfVrhru-cCKSOq8D2OgBExDZDvpoKA@mail.gmail.com> <20180914220242.wxp62zyexuulpcwm@alap3.anarazel.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox