*** ./doc/src/sgml/func.sgml.orig 2005-01-20 18:23:48.000000000 -0200
--- ./doc/src/sgml/func.sgml 2005-01-20 16:44:52.000000000 -0200
***************
*** 8060,8065 ****
--- 8060,8077 ----
+ start_time()
+ timestamp with time zone
+ PostgreSQL startup date and time
+
+
+
+ uptime()
+ interval
+ PostgreSQL uptime information
+
+
+
user
name
equivalent to current_user
***************
*** 8157,8162 ****
--- 8169,8192 ----
+ start_time
+
+
+
+ start_time() returns the timestamp with time zone
+ which the PostgreSQL was started.
+
+
+
+ uptime
+
+
+
+ uptime() returns the PostgreSQL>
+ uptime information.
+
+
+
version
*** ./src/backend/postmaster/postmaster.c.orig 2005-01-20 18:24:36.000000000 -0200
--- ./src/backend/postmaster/postmaster.c 2005-01-20 16:44:52.000000000 -0200
***************
*** 221,226 ****
--- 221,229 ----
bool ClientAuthInProgress = false; /* T during new-client
* authentication */
+ /* Backend startup time */
+ TimestampTz StartTime;
+
/*
* State for assigning random salts and cancel keys.
* Also, the global MyCancelKey passes the cancel key assigned to a given
***************
*** 329,334 ****
--- 332,338 ----
InheritableSocket pgStatPipe0;
InheritableSocket pgStatPipe1;
pid_t PostmasterPid;
+ TimestampTz StartTime;
#ifdef WIN32
HANDLE PostmasterHandle;
HANDLE initial_signal_pipe;
***************
*** 371,376 ****
--- 375,383 ----
char *userDoption = NULL;
int i;
+ AbsoluteTime StartTimeSec; /* integer part */
+ int StartTimeUSec; /* microsecond part */
+
/* This will call exit() if strdup() fails. */
progname = get_progname(argv[0]);
***************
*** 915,920 ****
--- 922,933 ----
*/
StartupPID = StartupDataBase();
+ /*
+ * Get start up time
+ */
+ StartTimeSec = GetCurrentAbsoluteTimeUsec(&StartTimeUSec);
+ StartTime = AbsoluteTimeUsecToTimestampTz(StartTimeSec, StartTimeUSec);
+
status = ServerLoop();
/*
***************
*** 3669,3674 ****
--- 3682,3688 ----
write_inheritable_socket(¶m->pgStatPipe1, pgStatPipe[1], childPid);
param->PostmasterPid = PostmasterPid;
+ param->StartTime = StartTime;
#ifdef WIN32
param->PostmasterHandle = PostmasterHandle;
***************
*** 3871,3876 ****
--- 3885,3891 ----
read_inheritable_socket(&pgStatPipe[1], ¶m->pgStatPipe1);
PostmasterPid = param->PostmasterPid;
+ StartTime = param->StartTime;
#ifdef WIN32
PostmasterHandle = param->PostmasterHandle;
*** ./src/backend/tcop/postgres.c.orig 2005-01-20 18:39:18.000000000 -0200
--- ./src/backend/tcop/postgres.c 2005-01-20 18:15:07.000000000 -0200
***************
*** 144,149 ****
--- 144,152 ----
#endif /* TCOP_DONTUSENEWLINE */
+ /* Backend startup time */
+ TimestampTz StartTime;
+
/* ----------------------------------------------------------------
* decls for routines only used in this file
* ----------------------------------------------------------------
***************
*** 2217,2222 ****
--- 2220,2228 ----
sigjmp_buf local_sigjmp_buf;
volatile bool send_rfq = true;
+ AbsoluteTime StartTimeSec; /* integer part */
+ int StartTimeUSec; /* microsecond part */
+
#define PendingConfigOption(name,val) \
(guc_names = lappend(guc_names, pstrdup(name)), \
guc_values = lappend(guc_values, pstrdup(val)))
***************
*** 2896,2901 ****
--- 2902,2916 ----
send_rfq = true; /* initially, or after error */
/*
+ * Get stand-alone backend startup time
+ */
+ if (!IsUnderPostmaster)
+ {
+ StartTimeSec = GetCurrentAbsoluteTimeUsec(&StartTimeUSec);
+ StartTime = AbsoluteTimeUsecToTimestampTz(StartTimeSec, StartTimeUSec);
+ }
+
+ /*
* Non-error queries loop here.
*/
*** ./src/backend/utils/adt/timestamp.c.orig 2005-01-20 18:42:00.000000000 -0200
--- ./src/backend/utils/adt/timestamp.c 2005-01-20 16:44:52.000000000 -0200
***************
*** 941,946 ****
--- 941,967 ----
PG_RETURN_TIMESTAMPTZ(result);
}
+ Datum
+ pgsql_start_time(PG_FUNCTION_ARGS)
+ {
+ PG_RETURN_TIMESTAMPTZ(StartTime);
+ }
+
+ Datum
+ pgsql_uptime(PG_FUNCTION_ARGS)
+ {
+ TimestampTz tznow;
+ AbsoluteTime sec;
+ int usec;
+
+ sec = GetCurrentTransactionStartTimeUsec(&usec);
+ tznow = AbsoluteTimeUsecToTimestampTz(sec, usec);
+
+ PG_RETURN_DATUM(DirectFunctionCall2(timestamptz_age,
+ TimestampTzGetDatum(tznow),
+ TimestampTzGetDatum(StartTime)));
+ }
+
void
dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
{
*** ./src/include/catalog/pg_proc.h.orig 2005-01-20 18:43:28.000000000 -0200
--- ./src/include/catalog/pg_proc.h 2005-01-20 16:44:52.000000000 -0200
***************
*** 3604,3609 ****
--- 3604,3615 ----
DATA(insert OID = 2556 ( pg_tablespace_databases PGNSP PGUID 12 f f t t s 1 26 "26" _null_ pg_tablespace_databases - _null_));
DESCR("returns database oids in a tablespace");
+ /* startuptime/uptime functions */
+ DATA(insert OID = 2557 ( start_time PGNSP PGUID 12 f f t f s 0 1184 "" _null_ pgsql_start_time - _null_ ));
+ DESCR("PostgreSQL start time");
+ DATA(insert OID = 2558 ( uptime PGNSP PGUID 12 f f t f s 0 1186 "" _null_ pgsql_uptime - _null_ ));
+ DESCR("PostgreSQL uptime");
+
/*
* Symbolic values for provolatile column: these indicate whether the result
*** ./src/include/utils/timestamp.h.orig 2005-01-20 18:45:58.000000000 -0200
--- ./src/include/utils/timestamp.h 2005-01-20 16:44:52.000000000 -0200
***************
*** 249,254 ****
--- 249,259 ----
extern Datum now(PG_FUNCTION_ARGS);
+ extern Datum pgsql_start_time(PG_FUNCTION_ARGS);
+ extern Datum pgsql_uptime(PG_FUNCTION_ARGS);
+
+ extern TimestampTz StartTime;
+
/* Internal routines (not fmgr-callable) */
extern int tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *dt);