--- postgresql-8.0.1/src/backend/utils/adt/timestamp.c Fri Dec 31 14:01:22 2004 +++ patched-postgresql-8.0.1/src/backend/utils/adt/timestamp.c Thu Feb 24 14:04:12 2005 @@ -50,6 +50,11 @@ static void AdjustIntervalForTypmod(Interval *interval, int32 typmod); static TimestampTz timestamp2timestamptz(Timestamp timestamp); +/* + * Set by MarkServerStartTime(). + */ +static AbsoluteTime serverStartTime = 0; +static int serverStartTimeUsec = 0; /***************************************************************************** * USER I/O ROUTINES * @@ -941,6 +946,28 @@ PG_RETURN_TIMESTAMPTZ(result); } +/* MarkServerStartTime() + * Marks the time of server startup. + */ +void +MarkServerStartTime(void) +{ + serverStartTime = GetCurrentAbsoluteTimeUsec(&(serverStartTimeUsec)); +} + +/* server_start_time() + * Returns the time when the server was started. + */ +Datum +server_start_time(PG_FUNCTION_ARGS) +{ + TimestampTz result; + + result = AbsoluteTimeUsecToTimestampTz(serverStartTime, serverStartTimeUsec); + + PG_RETURN_TIMESTAMPTZ(result); +} + void dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec) { @@ -4002,3 +4029,4 @@ PG_RETURN_TIMESTAMP(result); } /* timestamptz_izone() */ +