From add6c3179a4d4fa3e62dd3e86a00f23303336bac Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Wed, 7 Nov 2012 18:59:12 +0200 Subject: Make the streaming replication protocol messages architecture-independent. We used to send structs wrapped in CopyData messages, which works as long as the client and server agree on things like endianess, timestamp format and alignment. That's good enough for running a standby server, which has to run on the same platform anyway, but it's useful for tools like pg_receivexlog to work across platforms. This breaks protocol compatibility of streaming replication, but we never promised that to be compatible across versions, anyway. --- src/backend/utils/adt/timestamp.c | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/backend/utils/adt/timestamp.c') diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 50ef8976bed..6ff7385233e 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -1285,6 +1285,50 @@ GetCurrentTimestamp(void) return result; } +/* + * GetCurrentIntegerTimestamp -- get the current operating system time as int64 + * + * Result is the number of milliseconds since the Postgres epoch. If compiled + * with --enable-integer-datetimes, this is identical to GetCurrentTimestamp(), + * and is implemented as a macro. + */ +#ifndef HAVE_INT64_TIMESTAMP +int64 +GetCurrentIntegerTimestamp(void) +{ + int64 result; + struct timeval tp; + + gettimeofday(&tp, NULL); + + result = (int64) tp.tv_sec - + ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY); + + result = (result * USECS_PER_SEC) + tp.tv_usec; + + return result; +} +#endif + +/* + * IntegetTimestampToTimestampTz -- convert an int64 timestamp to native format + * + * When compiled with --enable-integer-datetimes, this is implemented as a + * no-op macro. + */ +#ifndef HAVE_INT64_TIMESTAMP +TimestampTz +IntegerTimestampToTimestampTz(int64 timestamp) +{ + TimestampTz result; + + result = timestamp / USECS_PER_SEC; + result += (timestamp % USECS_PER_SEC) / 1000000.0; + + return result; +} +#endif + /* * TimestampDifference -- convert the difference between two timestamps * into integer seconds and microseconds -- cgit v1.2.3