Move session_start out of MyProcPort stucture and make it a global called MyStartTime,
authorAndrew Dunstan <andrew@dunslane.net>
Thu, 2 Aug 2007 23:39:45 +0000 (23:39 +0000)
committerAndrew Dunstan <andrew@dunslane.net>
Thu, 2 Aug 2007 23:39:45 +0000 (23:39 +0000)
so that we will be able to create a cookie for all processes for CSVlogs.
It is set wherever MyProcPid is set. Take the opportunity to remove the now
unnecessary session-only restriction on the %s and %c escapes in log_line_prefix.

12 files changed:
doc/src/sgml/config.sgml
src/backend/bootstrap/bootstrap.c
src/backend/postmaster/autovacuum.c
src/backend/postmaster/pgarch.c
src/backend/postmaster/pgstat.c
src/backend/postmaster/postmaster.c
src/backend/postmaster/syslogger.c
src/backend/tcop/postgres.c
src/backend/utils/error/elog.c
src/backend/utils/init/globals.c
src/include/libpq/libpq-be.h
src/include/miscadmin.h

index 5eb927dbe0384197a254cab2ff5d2720cefbfc14..4099fbc32b7bd8960ed06838de68b9299509a531 100644 (file)
@@ -2900,7 +2900,7 @@ SELECT * FROM parent WHERE key = 2400;
             <row>
              <entry><literal>%c</literal></entry>
              <entry>Session ID: see below</entry>
-             <entry>yes</entry>
+             <entry>no</entry>
             </row>
             <row>
              <entry><literal>%l</literal></entry>
@@ -2910,7 +2910,7 @@ SELECT * FROM parent WHERE key = 2400;
             <row>
              <entry><literal>%s</literal></entry>
              <entry>Session start time stamp</entry>
-             <entry>yes</entry>
+             <entry>no</entry>
             </row>
             <row>
              <entry><literal>%x</literal></entry>
index 28694bc374dbce660a1bdf8c05050419a225a4c2..db72935c6adb87ab51deddf6a3b2a1ebce549aa9 100644 (file)
@@ -213,6 +213,8 @@ AuxiliaryProcessMain(int argc, char *argv[])
         */
        MyProcPid = getpid();
 
+       MyStartTime = time(NULL);
+
        /*
         * Fire up essential subsystems: error and memory management
         *
index 2477685037aaea7111e023f3029366d8027bda47..121d40b0acff31ec6b861e0b107a041338dd3f79 100644 (file)
@@ -385,6 +385,9 @@ AutoVacLauncherMain(int argc, char *argv[])
        /* reset MyProcPid */
        MyProcPid = getpid();
 
+       /* record Start Time for logging */
+       MyStartTime = time(NULL);
+
        /* Identify myself via ps */
        init_ps_display("autovacuum launcher process", "", "", "");
 
@@ -1403,6 +1406,9 @@ AutoVacWorkerMain(int argc, char *argv[])
        /* reset MyProcPid */
        MyProcPid = getpid();
 
+       /* record Start Time for logging */
+       MyStartTime = time(NULL);
+
        /* Identify myself via ps */
        init_ps_display("autovacuum worker process", "", "", "");
 
index dbb6dd024475df4ab9a50d4ecab9482f88c1ae92..a2b4f47ab986de06edae642263170b814688bdc1 100644 (file)
@@ -223,6 +223,8 @@ PgArchiverMain(int argc, char *argv[])
 
        MyProcPid = getpid();           /* reset MyProcPid */
 
+       MyStartTime = time(NULL);   /* record Start Time for logging */
+
        /*
         * If possible, make this process a group leader, so that the postmaster
         * can signal any child processes too.
index d128381937fe213849cd57d0c5e924d9ac57fa40..45795d5619a7e8a03ad24bb54e4f1633342f93bc 100644 (file)
@@ -2168,6 +2168,8 @@ PgstatCollectorMain(int argc, char *argv[])
 
        MyProcPid = getpid();           /* reset MyProcPid */
 
+       MyStartTime = time(NULL);       /* record Start Time for logging */
+
        /*
         * If possible, make this process a group leader, so that the postmaster
         * can signal any child processes too.  (pgstat probably never has
index 1f79ea47ccdf85ee1967975cf95902b1581b144d..59830d0bbef59baaec6cadd0f57bfbec33dd30d2 100644 (file)
@@ -386,6 +386,8 @@ PostmasterMain(int argc, char *argv[])
 
        MyProcPid = PostmasterPid = getpid();
 
+       MyStartTime = time(NULL);
+
        IsPostmasterEnvironment = true;
 
        /*
@@ -1103,6 +1105,8 @@ pmdaemonize(void)
 
        MyProcPid = PostmasterPid = getpid();           /* reset PID vars to child */
 
+       MyStartTime = time(NULL);
+
 /* GH: If there's no setsid(), we hopefully don't need silent mode.
  * Until there's a better solution.
  */
@@ -2661,6 +2665,8 @@ BackendStartup(Port *port)
 
                MyProcPid = getpid();   /* reset MyProcPid */
 
+               MyStartTime = time(NULL);
+
                /* We don't want the postmaster's proc_exit() handlers */
                on_exit_reset();
 
@@ -2803,7 +2809,7 @@ BackendInitialize(Port *port)
 
        /* save process start time */
        port->SessionStartTime = GetCurrentTimestamp();
-       port->session_start = timestamptz_to_time_t(port->SessionStartTime);
+       MyStartTime = timestamptz_to_time_t(port->SessionStartTime);
 
        /* set these to empty in case they are needed before we set them up */
        port->remote_host = "";
@@ -3385,6 +3391,8 @@ SubPostmasterMain(int argc, char *argv[])
 
        MyProcPid = getpid();           /* reset MyProcPid */
 
+       MyStartTime = time(NULL);
+
        /* make sure stderr is in binary mode before anything can
         * possibly be written to it, in case it's actually the syslogger pipe,
         * so the pipe chunking protocol isn't disturbed. Non-logpipe data
index 2cae0e01094133e7be4b787b3a9b1db98070b8e9..786a358e4063d932efe2b7d8cb4561f9b6679809 100644 (file)
@@ -162,6 +162,8 @@ SysLoggerMain(int argc, char *argv[])
 
        MyProcPid = getpid();           /* reset MyProcPid */
 
+       MyStartTime = time(NULL);   /* set our start time in case we call elog */
+
 #ifdef EXEC_BACKEND
        syslogger_parseArgs(argc, argv);
 #endif   /* EXEC_BACKEND */
index 8f03d450a7545331038fb6ad98881d1e08192fda..a9e0d3fb7bb273f7bde46e287d34e4aa9a3cc156 100644 (file)
@@ -2786,6 +2786,8 @@ PostgresMain(int argc, char *argv[], const char *username)
         */
        MyProcPid = getpid();
 
+       MyStartTime = time(NULL);
+
        /*
         * Fire up essential subsystems: error and memory management
         *
index 11d37997171a2e54d210fc62abd2654e4a8570a9..60f3620c29a43a95bf41772ad510a21c04e47e91 100644 (file)
@@ -1485,12 +1485,7 @@ log_line_prefix(StringInfo buf)
                                }
                                break;
                        case 'c':
-                               if (MyProcPort)
-                               {
-                                       appendStringInfo(buf, "%lx.%x",
-                                                                        (long) (MyProcPort->session_start),
-                                                                        MyProcPid);
-                               }
+                               appendStringInfo(buf, "%lx.%x", (long)(MyStartTime),MyProcPid);
                                break;
                        case 'p':
                                appendStringInfo(buf, "%d", MyProcPid);
@@ -1552,7 +1547,6 @@ log_line_prefix(StringInfo buf)
                                }
                                break;
                        case 's':
-                               if (MyProcPort)
                                {
                                        char            strfbuf[128];
 
@@ -1563,7 +1557,7 @@ log_line_prefix(StringInfo buf)
 #else
                                                         "%Y-%m-%d %H:%M:%S",
 #endif
-                                                        localtime(&MyProcPort->session_start));
+                                                        localtime(&MyStartTime));
                                        appendStringInfoString(buf, strfbuf);
                                }
                                break;
index 1d755dbca758a26dde8f5be92911789d9e049592..1e2ec36e7b638f77f5a14830f8db858a29f39eb7 100644 (file)
@@ -33,6 +33,7 @@ volatile uint32 InterruptHoldoffCount = 0;
 volatile uint32 CritSectionCount = 0;
 
 int                    MyProcPid;
+time_t      MyStartTime;
 struct Port *MyProcPort;
 long           MyCancelKey;
 
index 8d69641472d4b3b381c1bbb50e3f40a284507eaa..1744e80202b1bb61ee42b024d74bffa1f012a218 100644 (file)
@@ -130,7 +130,6 @@ typedef struct Port
         * other members of this struct, we may as well keep it here.
         */
        TimestampTz SessionStartTime;           /* backend start time */
-       time_t          session_start;  /* same, in time_t format */
 
        /*
         * TCP keepalive settings.
index ee203163d099687991f50fbb1037aec38e7b6668..0a4daf25d70b370b189b3fc051a8ea7cb5a506d1 100644 (file)
@@ -23,6 +23,8 @@
 #ifndef MISCADMIN_H
 #define MISCADMIN_H
 
+#include <time.h> /* for time_t */
+
 
 #define PG_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
 
@@ -132,6 +134,7 @@ extern int  MaxBackends;
 extern int     MaxConnections;
 
 extern PGDLLIMPORT int MyProcPid;
+extern PGDLLIMPORT time_t MyStartTime;
 extern PGDLLIMPORT struct Port *MyProcPort;
 extern long MyCancelKey;