commit 13817de092ee53f2af2d73270ddc3e02556d7c0c
Author: Anastasia <a.lubennikova@postgrespro.ru>
Date:   Wed Feb 28 14:04:00 2018 +0300

    Add function pg_shmem_init_time() which returns the time shared memory was last initialized

diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 2f59af2..bebdddf 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -15924,6 +15924,12 @@ SELECT * FROM pg_ls_dir('.') WITH ORDINALITY AS t(ls,n);
       </row>
 
       <row>
+       <entry><literal><function>pg_shmem_init_time()</function></literal></entry>
+       <entry><type>timestamp with time zone</type></entry>
+       <entry>shared memory initialization time</entry>
+      </row>
+
+      <row>
        <entry><literal><function>pg_current_logfile(<optional><type>text</type></optional>)</function></literal></entry>
        <entry><type>text</type></entry>
        <entry>Primary log file name, or log in the requested format,
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index a397260..7cc9780 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -512,6 +512,7 @@ typedef struct
 	pid_t		PostmasterPid;
 	TimestampTz PgStartTime;
 	TimestampTz PgReloadTime;
+	TimestampTz PgShmemInitTime;
 	pg_time_t	first_syslogger_file_time;
 	bool		redirection_done;
 	bool		IsBinaryUpgrade;
@@ -2555,6 +2556,8 @@ reset_shared(int port)
 	 * objects if the postmaster crashes and is restarted.
 	 */
 	CreateSharedMemoryAndSemaphores(false, port);
+
+	PgShmemInitTime = GetCurrentTimestamp();
 }
 
 
@@ -6058,6 +6061,7 @@ save_backend_variables(BackendParameters *param, Port *port,
 	param->PostmasterPid = PostmasterPid;
 	param->PgStartTime = PgStartTime;
 	param->PgReloadTime = PgReloadTime;
+	param->PgShmemInitTime = PgShmemInitTime;
 	param->first_syslogger_file_time = first_syslogger_file_time;
 
 	param->redirection_done = redirection_done;
@@ -6290,6 +6294,7 @@ restore_backend_variables(BackendParameters *param, Port *port)
 	PostmasterPid = param->PostmasterPid;
 	PgStartTime = param->PgStartTime;
 	PgReloadTime = param->PgReloadTime;
+	PgShmemInitTime = param->PgShmemInitTime;
 	first_syslogger_file_time = param->first_syslogger_file_time;
 
 	redirection_done = param->redirection_done;
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 103f91a..e3132eb 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -51,6 +51,9 @@ TimestampTz PgStartTime;
 /* Set at configuration reload */
 TimestampTz PgReloadTime;
 
+/* Set at shared memory (re)initialization */
+TimestampTz PgShmemInitTime;
+
 typedef struct
 {
 	Timestamp	current;
@@ -1560,6 +1563,12 @@ pg_conf_load_time(PG_FUNCTION_ARGS)
 	PG_RETURN_TIMESTAMPTZ(PgReloadTime);
 }
 
+Datum
+pg_shmem_init_time(PG_FUNCTION_ARGS)
+{
+	PG_RETURN_TIMESTAMPTZ(PgShmemInitTime);
+}
+
 /*
  * GetCurrentTimestamp -- get the current operating system time
  *
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index c00d055..3f50b50 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -4334,6 +4334,9 @@ DESCR("postmaster start time");
 /* config reload time function */
 DATA(insert OID = 2034 (  pg_conf_load_time			PGNSP PGUID 12 1 0 0 0 f f f f t f s r 0 0 1184 "" _null_ _null_ _null_ _null_ _null_ pg_conf_load_time _null_ _null_ _null_ ));
 DESCR("configuration load time");
+/* shared memory (re)init time function */
+DATA(insert OID = 2579 (  pg_shmem_init_time		PGNSP PGUID 12 1 0 0 0 f f f f t f s r 0 0 1184 "" _null_ _null_ _null_ _null_ _null_ pg_shmem_init_time _null_ _null_ _null_ ));
+DESCR("shared memory (re)init time");
 
 /* new functions for Y-direction rtree opclasses */
 DATA(insert OID = 2562 (  box_below		   PGNSP PGUID 12 1 0 0 0 f f f f t f i s 2 0 16 "603 603" _null_ _null_ _null_ _null_ _null_ box_below _null_ _null_ _null_ ));
diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h
index 2b3b357..3c34b48 100644
--- a/src/include/utils/timestamp.h
+++ b/src/include/utils/timestamp.h
@@ -62,6 +62,8 @@ extern TimestampTz PgStartTime;
 /* Set at configuration reload */
 extern TimestampTz PgReloadTime;
 
+/* Set at shared memory (re)initialization */
+extern TimestampTz PgShmemInitTime;
 
 /* Internal routines (not fmgr-callable) */
 
