Add pg_postmaster_start_time() function.
Euler Taveira de Oliveira Matthias Schmidt
This commit is contained in:
parent
b5e65c8325
commit
f5835b4b8d
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.254 2005/06/13 02:40:04 neilc Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.255 2005/06/14 21:04:38 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -8119,6 +8119,12 @@ select current_date + s.a as dates from generate_series(0,14,7) as s(a);
|
|||||||
<entry>session user name</entry>
|
<entry>session user name</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
|
<row>
|
||||||
|
<entry><function>pg_postmaster_start_time()</function></entry>
|
||||||
|
<entry><type>timestamp with time zone</type></entry>
|
||||||
|
<entry><command>postmaster</> start time</entry>
|
||||||
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><function>user</function></entry>
|
<entry><function>user</function></entry>
|
||||||
<entry><type>name</type></entry>
|
<entry><type>name</type></entry>
|
||||||
@ -8216,6 +8222,15 @@ SET search_path TO <replaceable>schema</> <optional>, <replaceable>schema</>, ..
|
|||||||
Unix-domain socket.
|
Unix-domain socket.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<indexterm zone="functions-info">
|
||||||
|
<primary>pg_postmaster_start_time</primary>
|
||||||
|
</indexterm>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
<function>pg_postmaster_start_time()</function> returns the timestamp with time zone
|
||||||
|
when the <command>postmaster</> started.
|
||||||
|
</para>
|
||||||
|
|
||||||
<indexterm zone="functions-info">
|
<indexterm zone="functions-info">
|
||||||
<primary>version</primary>
|
<primary>version</primary>
|
||||||
</indexterm>
|
</indexterm>
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.452 2005/06/09 22:01:12 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.453 2005/06/14 21:04:39 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
*
|
*
|
||||||
@ -222,6 +222,9 @@ static bool FatalError = false; /* T if recovering from backend crash */
|
|||||||
bool ClientAuthInProgress = false; /* T during new-client
|
bool ClientAuthInProgress = false; /* T during new-client
|
||||||
* authentication */
|
* authentication */
|
||||||
|
|
||||||
|
/* Backend startup time */
|
||||||
|
TimestampTz StartTime;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* State for assigning random salts and cancel keys.
|
* State for assigning random salts and cancel keys.
|
||||||
* Also, the global MyCancelKey passes the cancel key assigned to a given
|
* Also, the global MyCancelKey passes the cancel key assigned to a given
|
||||||
@ -330,6 +333,7 @@ typedef struct
|
|||||||
InheritableSocket pgStatPipe0;
|
InheritableSocket pgStatPipe0;
|
||||||
InheritableSocket pgStatPipe1;
|
InheritableSocket pgStatPipe1;
|
||||||
pid_t PostmasterPid;
|
pid_t PostmasterPid;
|
||||||
|
TimestampTz StartTime;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
HANDLE PostmasterHandle;
|
HANDLE PostmasterHandle;
|
||||||
HANDLE initial_signal_pipe;
|
HANDLE initial_signal_pipe;
|
||||||
@ -372,6 +376,9 @@ PostmasterMain(int argc, char *argv[])
|
|||||||
char *userDoption = NULL;
|
char *userDoption = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
AbsoluteTime StartTimeSec; /* integer part */
|
||||||
|
int StartTimeUSec; /* microsecond part */
|
||||||
|
|
||||||
/* This will call exit() if strdup() fails. */
|
/* This will call exit() if strdup() fails. */
|
||||||
progname = get_progname(argv[0]);
|
progname = get_progname(argv[0]);
|
||||||
|
|
||||||
@ -914,6 +921,12 @@ PostmasterMain(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
StartupPID = StartupDataBase();
|
StartupPID = StartupDataBase();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get start up time
|
||||||
|
*/
|
||||||
|
StartTimeSec = GetCurrentAbsoluteTimeUsec(&StartTimeUSec);
|
||||||
|
StartTime = AbsoluteTimeUsecToTimestampTz(StartTimeSec, StartTimeUSec);
|
||||||
|
|
||||||
status = ServerLoop();
|
status = ServerLoop();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3603,6 +3616,7 @@ save_backend_variables(BackendParameters *param, Port *port,
|
|||||||
write_inheritable_socket(¶m->pgStatPipe1, pgStatPipe[1], childPid);
|
write_inheritable_socket(¶m->pgStatPipe1, pgStatPipe[1], childPid);
|
||||||
|
|
||||||
param->PostmasterPid = PostmasterPid;
|
param->PostmasterPid = PostmasterPid;
|
||||||
|
param->StartTime = StartTime;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
param->PostmasterHandle = PostmasterHandle;
|
param->PostmasterHandle = PostmasterHandle;
|
||||||
@ -3805,6 +3819,7 @@ restore_backend_variables(BackendParameters *param, Port *port)
|
|||||||
read_inheritable_socket(&pgStatPipe[1], ¶m->pgStatPipe1);
|
read_inheritable_socket(&pgStatPipe[1], ¶m->pgStatPipe1);
|
||||||
|
|
||||||
PostmasterPid = param->PostmasterPid;
|
PostmasterPid = param->PostmasterPid;
|
||||||
|
StartTime = param->StartTime;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
PostmasterHandle = param->PostmasterHandle;
|
PostmasterHandle = param->PostmasterHandle;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.447 2005/06/03 23:05:29 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.448 2005/06/14 21:04:40 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* this is the "main" module of the postgres backend and
|
* this is the "main" module of the postgres backend and
|
||||||
@ -149,6 +149,9 @@ static int UseNewLine = 0; /* Use EOF as query delimiters */
|
|||||||
#endif /* TCOP_DONTUSENEWLINE */
|
#endif /* TCOP_DONTUSENEWLINE */
|
||||||
|
|
||||||
|
|
||||||
|
/* Backend startup time */
|
||||||
|
TimestampTz StartTime;
|
||||||
|
|
||||||
/* ----------------------------------------------------------------
|
/* ----------------------------------------------------------------
|
||||||
* decls for routines only used in this file
|
* decls for routines only used in this file
|
||||||
* ----------------------------------------------------------------
|
* ----------------------------------------------------------------
|
||||||
@ -2380,6 +2383,9 @@ PostgresMain(int argc, char *argv[], const char *username)
|
|||||||
sigjmp_buf local_sigjmp_buf;
|
sigjmp_buf local_sigjmp_buf;
|
||||||
volatile bool send_rfq = true;
|
volatile bool send_rfq = true;
|
||||||
|
|
||||||
|
AbsoluteTime StartTimeSec; /* integer part */
|
||||||
|
int StartTimeUSec; /* microsecond part */
|
||||||
|
|
||||||
#define PendingConfigOption(name,val) \
|
#define PendingConfigOption(name,val) \
|
||||||
(guc_names = lappend(guc_names, pstrdup(name)), \
|
(guc_names = lappend(guc_names, pstrdup(name)), \
|
||||||
guc_values = lappend(guc_values, pstrdup(val)))
|
guc_values = lappend(guc_values, pstrdup(val)))
|
||||||
@ -2969,6 +2975,15 @@ PostgresMain(int argc, char *argv[], const char *username)
|
|||||||
*/
|
*/
|
||||||
pgstat_bestart();
|
pgstat_bestart();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get stand-alone backend startup time
|
||||||
|
*/
|
||||||
|
if (!IsUnderPostmaster)
|
||||||
|
{
|
||||||
|
StartTimeSec = GetCurrentAbsoluteTimeUsec(&StartTimeUSec);
|
||||||
|
StartTime = AbsoluteTimeUsecToTimestampTz(StartTimeSec, StartTimeUSec);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* POSTGRES main processing loop begins here
|
* POSTGRES main processing loop begins here
|
||||||
*
|
*
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.124 2005/05/26 02:04:13 neilc Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.125 2005/06/14 21:04:40 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -938,6 +938,12 @@ now(PG_FUNCTION_ARGS)
|
|||||||
PG_RETURN_TIMESTAMPTZ(result);
|
PG_RETURN_TIMESTAMPTZ(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Datum
|
||||||
|
pgsql_postmaster_start_time(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
|
PG_RETURN_TIMESTAMPTZ(StartTime);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
|
dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.366 2005/06/13 02:26:50 tgl Exp $
|
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.367 2005/06/14 21:04:41 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* The script catalog/genbki.sh reads this file and generates .bki
|
* The script catalog/genbki.sh reads this file and generates .bki
|
||||||
@ -3651,6 +3651,10 @@ DESCR("convert boolean to int4");
|
|||||||
DATA(insert OID = 2559 ( lastval PGNSP PGUID 12 f f t f v 0 20 "" _null_ _null_ _null_ lastval - _null_ ));
|
DATA(insert OID = 2559 ( lastval PGNSP PGUID 12 f f t f v 0 20 "" _null_ _null_ _null_ lastval - _null_ ));
|
||||||
DESCR("current value from last used sequence");
|
DESCR("current value from last used sequence");
|
||||||
|
|
||||||
|
/* start time function */
|
||||||
|
DATA(insert OID = 2560 ( pg_postmaster_start_time PGNSP PGUID 12 f f t f s 0 1184 "" _null_ _null_ _null_ pgsql_postmaster_start_time - _null_ ));
|
||||||
|
DESCR("postmaster start time");
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Symbolic values for provolatile column: these indicate whether the result
|
* Symbolic values for provolatile column: these indicate whether the result
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.43 2005/05/25 21:40:42 momjian Exp $
|
* $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.44 2005/06/14 21:04:42 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -256,6 +256,10 @@ extern Datum timestamptz_part(PG_FUNCTION_ARGS);
|
|||||||
|
|
||||||
extern Datum now(PG_FUNCTION_ARGS);
|
extern Datum now(PG_FUNCTION_ARGS);
|
||||||
|
|
||||||
|
extern Datum pgsql_postmaster_start_time(PG_FUNCTION_ARGS);
|
||||||
|
|
||||||
|
extern TimestampTz StartTime;
|
||||||
|
|
||||||
/* Internal routines (not fmgr-callable) */
|
/* Internal routines (not fmgr-callable) */
|
||||||
|
|
||||||
extern int tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *dt);
|
extern int tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *dt);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user