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 37afd9845aa756c74ffcdbe5a6f5b9061e61848d..adac32931df89a9f2b6bb356baac10274bda8bf7 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.134 2007/08/01 22:45:07 tgl Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.135 2007/08/02 23:39:43 adunstan Exp $ -->
 
 <chapter Id="runtime-config">
   <title>Server Configuration</title>
@@ -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 3ffff2a2cce3fe0ee2bb50fd079a758bcf2b747b..c142085637559733860808a1b417241d04e979be 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.235 2007/07/24 04:54:09 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.236 2007/08/02 23:39:44 adunstan Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -213,6 +213,8 @@ AuxiliaryProcessMain(int argc, char *argv[])
     */
    MyProcPid = getpid();
 
+   MyStartTime = time(NULL);
+
    /*
     * Fire up essential subsystems: error and memory management
     *
index aa674e54f9200f9aec1236c822bd8f965a462f6c..7b6da97b57bf5a9f46536b62700ae6c936b08ae9 100644 (file)
@@ -55,7 +55,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.55 2007/07/01 18:30:54 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.56 2007/08/02 23:39:44 adunstan Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 991a22191f93c7a3be9212539f424b2af53c4f69..13b146ce53705576a54bf35653c68fc391d8c46d 100644 (file)
@@ -19,7 +19,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/postmaster/pgarch.c,v 1.29 2007/02/10 14:58:54 petere Exp $
+ *   $PostgreSQL: pgsql/src/backend/postmaster/pgarch.c,v 1.30 2007/08/02 23:39:44 adunstan Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 4097787ec69721e2619dea22a46ee1c87f69d56e..9b1ee702e7488d4152d2c9da316ca74aa4d77db9 100644 (file)
@@ -13,7 +13,7 @@
  *
  * Copyright (c) 2001-2007, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.161 2007/07/08 22:23:16 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.162 2007/08/02 23:39:44 adunstan Exp $
  * ----------
  */
 #include "postgres.h"
@@ -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 f187393e4366e33e8a3f7d442a14386ae2b0d1c8..8db5b2a9afe9ced61bcbbed13ae969d41c4b300f 100644 (file)
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.536 2007/08/02 23:15:26 adunstan Exp $
+ *   $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.537 2007/08/02 23:39:44 adunstan Exp $
  *
  * NOTES
  *
@@ -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 8dc7353a67172cb9964824f9b344ae7d95a4c0ca..00480600690db1e31b125623a4f0423106ef1781 100644 (file)
@@ -18,7 +18,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.34 2007/08/02 23:15:27 adunstan Exp $
+ *   $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.35 2007/08/02 23:39:44 adunstan Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 58f1613975d24d9f3fbff29ecf72fa564c704c1f..b5ecea2d06474de2702ead2d6682ed404e2b6a1e 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.536 2007/07/09 01:15:14 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.537 2007/08/02 23:39:44 adunstan Exp $
  *
  * NOTES
  *   this is the "main" module of the postgres backend and
@@ -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 3b86de353b59b52300759ec647e71b53f1e55bc1..78993a24ebe8fe7b2164474811c3715558684ab8 100644 (file)
@@ -42,7 +42,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.190 2007/07/21 22:12:04 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.191 2007/08/02 23:39:44 adunstan Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 b5b115005662f55f80586d2e0ef1fd622b90197b..37ce52401c6a2f63ccbecec4f5c06a4280e51858 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.101 2007/04/16 18:29:54 alvherre Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.102 2007/08/02 23:39:44 adunstan Exp $
  *
  * NOTES
  *   Globals used all over the place should be declared here and not
@@ -33,6 +33,7 @@ volatile uint32 InterruptHoldoffCount = 0;
 volatile uint32 CritSectionCount = 0;
 
 int            MyProcPid;
+time_t      MyStartTime;
 struct Port *MyProcPort;
 long       MyCancelKey;
 
index 319e5e861004d57e186160a1dd9badeccf8d9d3c..0259b4343ebcb0aa47a24474a12a697ada7a6206 100644 (file)
@@ -11,7 +11,7 @@
  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/libpq/libpq-be.h,v 1.62 2007/07/23 10:16:54 mha Exp $
+ * $PostgreSQL: pgsql/src/include/libpq/libpq-be.h,v 1.63 2007/08/02 23:39:45 adunstan Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 c276742277ae8f2d5c1f6cbc3392ba7f0d2f712d..200c8df0d4090dde12a0e1c2d21dd9ef6aca1ef7 100644 (file)
@@ -13,7 +13,7 @@
  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.195 2007/07/25 12:22:53 mha Exp $
+ * $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.196 2007/08/02 23:39:44 adunstan Exp $
  *
  * NOTES
  *   some of the information in this file should be moved to other files.
@@ -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;