Index: src/include/catalog/pg_proc.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/catalog/pg_proc.h,v
retrieving revision 1.349
diff -c -r1.349 pg_proc.h
*** src/include/catalog/pg_proc.h	31 Dec 2004 22:03:25 -0000	1.349
--- src/include/catalog/pg_proc.h	5 Jan 2005 21:33:49 -0000
***************
*** 3604,3609 ****
--- 3604,3612 ----
  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");
  
+ DATA(insert OID = 2557 ( pg_starttime       PGNSP PGUID 12 f f t f i 0 1184 "0" _null_ pg_starttime - _null_ ));
+ DESCR("returns the starttime of the PostgreSQL Server");
+ 
  
  /*
   * Symbolic values for provolatile column: these indicate whether the result
Index: src/include/utils/timestamp.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/utils/timestamp.h,v
retrieving revision 1.40
diff -c -r1.40 timestamp.h
*** src/include/utils/timestamp.h	31 Dec 2004 22:03:46 -0000	1.40
--- src/include/utils/timestamp.h	5 Jan 2005 21:33:49 -0000
***************
*** 248,253 ****
--- 248,254 ----
  extern Datum timestamptz_part(PG_FUNCTION_ARGS);
  
  extern Datum now(PG_FUNCTION_ARGS);
+ extern Datum pg_starttime(PG_FUNCTION_ARGS);
  
  /* Internal routines (not fmgr-callable) */
  
Index: src/backend/utils/adt/timestamp.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v
retrieving revision 1.117
diff -c -r1.117 timestamp.c
*** src/backend/utils/adt/timestamp.c	31 Dec 2004 22:01:22 -0000	1.117
--- src/backend/utils/adt/timestamp.c	5 Jan 2005 21:33:54 -0000
***************
*** 50,55 ****
--- 50,58 ----
  static void AdjustIntervalForTypmod(Interval *interval, int32 typmod);
  static TimestampTz timestamp2timestamptz(Timestamp timestamp);
  
+ /* postmaster startup-time */
+ extern TimestampTz starttime;
+ 
  
  /*****************************************************************************
   *	 USER I/O ROUTINES														 *
***************
*** 941,946 ****
--- 944,956 ----
  	PG_RETURN_TIMESTAMPTZ(result);
  }
  
+ Datum
+ pg_starttime(PG_FUNCTION_ARGS)
+ {
+ 
+ 	PG_RETURN_TIMESTAMPTZ(starttime);
+ }
+ 
  void
  dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
  {
Index: src/backend/postmaster/postmaster.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/postmaster/postmaster.c,v
retrieving revision 1.442
diff -c -r1.442 postmaster.c
*** src/backend/postmaster/postmaster.c	31 Dec 2004 22:00:40 -0000	1.442
--- src/backend/postmaster/postmaster.c	5 Jan 2005 21:34:01 -0000
***************
*** 175,180 ****
--- 175,184 ----
   */
  static char ExtraOptions[MAXPGPATH];
  
+ 
+ /* postmaster startup-time */
+ TimestampTz starttime;
+ 
  /*
   * These globals control the behavior of the postmaster in case some
   * backend dumps core.	Normally, it kills all peers of the dead backend
***************
*** 339,344 ****
--- 343,349 ----
  	char ExtraOptions[MAXPGPATH];
  	char lc_collate[MAXPGPATH];
  	char lc_ctype[MAXPGPATH];
+ 	TimestampTz starttime;
  } BackendParameters;
  
  static void read_backend_variables(char *id, Port *port);
***************
*** 370,375 ****
--- 375,387 ----
  	char	   *userDoption = NULL;
  	int			i;
  
+ 	AbsoluteTime 		starttime_sec;
+ 	int			starttime_usec;
+ 
+ 	/* need to do this pretty early, since we're dealing with time ... */
+ 	starttime_sec = GetCurrentAbsoluteTimeUsec(&starttime_usec);
+ 	starttime = AbsoluteTimeUsecToTimestampTz(starttime_sec, starttime_usec); 
+ 
  	/* This will call exit() if strdup() fails. */
  	progname = get_progname(argv[0]);	
  
***************
*** 3685,3690 ****
--- 3697,3703 ----
  	StrNCpy(param->lc_collate, setlocale(LC_COLLATE, NULL), MAXPGPATH);
  	StrNCpy(param->lc_ctype, setlocale(LC_CTYPE, NULL), MAXPGPATH);
  
+ 	param->starttime = starttime;
  	return true;
  }
  
***************
*** 3884,3889 ****
--- 3897,3905 ----
  
  	setlocale(LC_COLLATE, param->lc_collate);
  	setlocale(LC_CTYPE, param->lc_ctype);
+ 
+ 	starttime = param->starttime;
+ 
  }
  
  
