Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cfmge-00086y-4W for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Feb 2017 12:03:24 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cfmgd-0001en-M5 for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Feb 2017 12:03:23 +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.84_2) (envelope-from ) id 1cfmgc-0001eU-OO for pgsql-hackers@postgresql.org; Mon, 20 Feb 2017 12:03:22 +0000 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cfmga-0007ca-0Z for pgsql-hackers@postgresql.org; Mon, 20 Feb 2017 12:03:21 +0000 Received: by mail-wm0-x231.google.com with SMTP id r141so50732777wmg.1 for ; Mon, 20 Feb 2017 04:03:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to; bh=YdiPnBFfmqtcMIrDjiWaz5y+0VlQ6E3gA/SzGlkryls=; b=jTaeimLkKWbdX7hQBipyKRdcrBEL7YA8cWW3uHsHnLq4mwwAm3gs39h7zhY7RYJG3t 7+kUL1zwu+9xQFf4WC0LuSw+eDfzlUqY5Md9fBdj5h/18E6zR63H3hGwScums0EKZLUK ayz9xuoJvVj8K5+E9mcrT2YAbY82eAdj6jsXes1N6+VsKMt+jdWXj8SFDjUGFn5OTMS9 z+EXgaGl47YFzKfjz1nZ++tpNk+vMeqIZRFPsMPfolQ5WCrttnm+s3zLuXNe8Dx9EeiJ 716T++1VbOdZMO4w8UZhVxQhr74PQnPa/VTmR2e72d6fmk/YM531wX04N6UcFCjOlAr8 iY0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to; bh=YdiPnBFfmqtcMIrDjiWaz5y+0VlQ6E3gA/SzGlkryls=; b=VBdICWztUm69Q+jXcYgTwpwMi3xh7rf03BT++BcqigPf1CU7w26uRVQORq81iy99xS nOOTDxU2CgqdXCYQJ17V3hu0mumM92ZrwgQOKREQwbE4+gpuLRXRkwLeQWeq4FrT6EpJ L5y5Gp0f2fWAPVSD05s0RsXWtqPJr5PT/NlYsHUVsLAtU/xed+eLx47KOCNIYq241lvy OIuNgnX6t/XVhysZ9vvHogaJ2bnpeWh8szLJfDzhqnvgsZ8P+1DKVHbSksL02WAKH6ke +/0WPZktmM+r+H6QnwTvxzujeZM6ZpX1jj/bCOtwnSK/drryfaqL+uttTo67lW/5B52W TXGQ== X-Gm-Message-State: AMke39nC+HZgUuWGEsRmAH/JPKSq7rywj5OCMhta42bKzmpJuuqwxA2eEfBx1mzXUav8EcyVSOFUt04Vr8kXt5tjsPVSlyy7a85ePSHyqaoYAO30qNQRjecxCLrNmd3r6E6A18y9WDq3AbSkBGBugW1jh+efvni7ad/FnqG3XgDS+0jcxMg9JBRX6+R5yLeneIC6mcKml+5h X-Received: by 10.28.172.68 with SMTP id v65mr10727601wme.49.1487592197552; Mon, 20 Feb 2017 04:03:17 -0800 (PST) Received: from [192.168.0.105] (150.123.broadband11.iol.cz. [90.178.123.150]) by smtp.gmail.com with ESMTPSA id y145sm13184467wmc.17.2017.02.20.04.03.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Feb 2017 04:03:16 -0800 (PST) Subject: Re: Replication vs. float timestamps is a disaster To: Andres Freund References: <26788.1487455319@sss.pgh.pa.us> <1691.1487519369@sss.pgh.pa.us> <20170220070311.gscn7ppqbwlgdpjq@alap3.anarazel.de> <3bd3c551-8b23-45c8-27a2-97b5a922b130@2ndquadrant.com> <20170220110456.2jupmfhxlizykmmc@alap3.anarazel.de> Cc: Tom Lane , Robert Haas , "pgsql-hackers@postgresql.org" From: Petr Jelinek Message-ID: <452dabb1-713b-ceef-7307-9315690935d6@2ndquadrant.com> Date: Mon, 20 Feb 2017 13:03:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: <20170220110456.2jupmfhxlizykmmc@alap3.anarazel.de> Content-Type: multipart/mixed; boundary="------------BFDE6530130A46B0C40884A8" X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------BFDE6530130A46B0C40884A8 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 20/02/17 12:04, Andres Freund wrote: > On 2017-02-20 11:58:12 +0100, Petr Jelinek wrote: >> That being said, I did wonder myself if we should just deprecate float >> timestamps as well. > > I think we need a proper deprecation period for that, given that the > conversion away will be painful for pg_upgrade using people with big > clusters. So I think we should fix this regardless... :( > That's a good point. Attached should fix the logical replication problems. I am not quite sure if there is anything in physical that needs changing. I opted for GetCurrentIntegerTimestamp() in the reply code as that's the same coding walreceiver uses. -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services --------------BFDE6530130A46B0C40884A8 Content-Type: text/x-diff; name="logical-rep-int-timestamps.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="logical-rep-int-timestamps.diff" diff --git a/src/backend/replication/logical/proto.c b/src/backend/replication/logical/proto.c index 142cd99..dd5bdcc 100644 --- a/src/backend/replication/logical/proto.c +++ b/src/backend/replication/logical/proto.c @@ -46,7 +46,7 @@ logicalrep_write_begin(StringInfo out, ReorderBufferTXN *txn) /* fixed fields */ pq_sendint64(out, txn->final_lsn); - pq_sendint64(out, txn->commit_time); + pq_sendint64(out, TimestampTzToIntegerTimestamp(txn->commit_time)); pq_sendint(out, txn->xid, 4); } @@ -60,7 +60,7 @@ logicalrep_read_begin(StringInfo in, LogicalRepBeginData *begin_data) begin_data->final_lsn = pq_getmsgint64(in); if (begin_data->final_lsn == InvalidXLogRecPtr) elog(ERROR, "final_lsn not set in begin message"); - begin_data->committime = pq_getmsgint64(in); + begin_data->committime = IntegerTimestampToTimestampTz(pq_getmsgint64(in)); begin_data->xid = pq_getmsgint(in, 4); } @@ -82,7 +82,7 @@ logicalrep_write_commit(StringInfo out, ReorderBufferTXN *txn, /* send fields */ pq_sendint64(out, commit_lsn); pq_sendint64(out, txn->end_lsn); - pq_sendint64(out, txn->commit_time); + pq_sendint64(out, TimestampTzToIntegerTimestamp(txn->commit_time)); } /* @@ -100,7 +100,7 @@ logicalrep_read_commit(StringInfo in, LogicalRepCommitData *commit_data) /* read fields */ commit_data->commit_lsn = pq_getmsgint64(in); commit_data->end_lsn = pq_getmsgint64(in); - commit_data->committime = pq_getmsgint64(in); + commit_data->committime = IntegerTimestampToTimestampTz(pq_getmsgint64(in)); } /* diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index 0b19fec..225ea4c 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -1183,7 +1183,7 @@ send_feedback(XLogRecPtr recvpos, bool force, bool requestReply) pq_sendint64(reply_message, recvpos); /* write */ pq_sendint64(reply_message, flushpos); /* flush */ pq_sendint64(reply_message, writepos); /* apply */ - pq_sendint64(reply_message, now); /* sendTime */ + pq_sendint64(reply_message, GetCurrentIntegerTimestamp()); /* sendTime */ pq_sendbyte(reply_message, requestReply); /* replyRequested */ elog(DEBUG2, "sending feedback (force %d) to recv %X/%X, write %X/%X, flush %X/%X", diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 9b4c012..1dd469d 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -1749,6 +1749,20 @@ IntegerTimestampToTimestampTz(int64 timestamp) #endif /* + * TimestampTzToIntegerTimestamp -- convert a native format timestamp to int64 + * + * When compiled with --enable-integer-datetimes, this is implemented as a + * no-op macro. + */ +#ifndef HAVE_INT64_TIMESTAMP +int64 +TimestampTzToIntegerTimestamp(TimestampTz timestamp) +{ + return timestamp * USECS_PER_SEC; +} +#endif + +/* * GetSQLCurrentTimestamp -- implements CURRENT_TIMESTAMP, CURRENT_TIMESTAMP(n) */ TimestampTz diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h index 21651b1..765fa81 100644 --- a/src/include/utils/timestamp.h +++ b/src/include/utils/timestamp.h @@ -108,9 +108,11 @@ extern bool TimestampDifferenceExceeds(TimestampTz start_time, #ifndef HAVE_INT64_TIMESTAMP extern int64 GetCurrentIntegerTimestamp(void); extern TimestampTz IntegerTimestampToTimestampTz(int64 timestamp); +extern int64 TimestampTzToIntegerTimestamp(TimestampTz timestamp); #else #define GetCurrentIntegerTimestamp() GetCurrentTimestamp() #define IntegerTimestampToTimestampTz(timestamp) (timestamp) +#define TimestampTzToIntegerTimestamp(timestamp) (timestamp) #endif extern TimestampTz time_t_to_timestamptz(pg_time_t tm); --------------BFDE6530130A46B0C40884A8 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --------------BFDE6530130A46B0C40884A8--