Move session_start out of MyProcPort stucture and make it a global called MyStartTime,

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.
This commit is contained in:
Andrew Dunstan 2007-08-02 23:39:45 +00:00
parent b34903453f
commit 63872601e8
12 changed files with 45 additions and 24 deletions

View 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"> <chapter Id="runtime-config">
<title>Server Configuration</title> <title>Server Configuration</title>
@ -2900,7 +2900,7 @@ SELECT * FROM parent WHERE key = 2400;
<row> <row>
<entry><literal>%c</literal></entry> <entry><literal>%c</literal></entry>
<entry>Session ID: see below</entry> <entry>Session ID: see below</entry>
<entry>yes</entry> <entry>no</entry>
</row> </row>
<row> <row>
<entry><literal>%l</literal></entry> <entry><literal>%l</literal></entry>
@ -2910,7 +2910,7 @@ SELECT * FROM parent WHERE key = 2400;
<row> <row>
<entry><literal>%s</literal></entry> <entry><literal>%s</literal></entry>
<entry>Session start time stamp</entry> <entry>Session start time stamp</entry>
<entry>yes</entry> <entry>no</entry>
</row> </row>
<row> <row>
<entry><literal>%x</literal></entry> <entry><literal>%x</literal></entry>

View File

@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * 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(); MyProcPid = getpid();
MyStartTime = time(NULL);
/* /*
* Fire up essential subsystems: error and memory management * Fire up essential subsystems: error and memory management
* *

View File

@ -55,7 +55,7 @@
* *
* *
* IDENTIFICATION * 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 */ /* reset MyProcPid */
MyProcPid = getpid(); MyProcPid = getpid();
/* record Start Time for logging */
MyStartTime = time(NULL);
/* Identify myself via ps */ /* Identify myself via ps */
init_ps_display("autovacuum launcher process", "", "", ""); init_ps_display("autovacuum launcher process", "", "", "");
@ -1403,6 +1406,9 @@ AutoVacWorkerMain(int argc, char *argv[])
/* reset MyProcPid */ /* reset MyProcPid */
MyProcPid = getpid(); MyProcPid = getpid();
/* record Start Time for logging */
MyStartTime = time(NULL);
/* Identify myself via ps */ /* Identify myself via ps */
init_ps_display("autovacuum worker process", "", "", ""); init_ps_display("autovacuum worker process", "", "", "");

View File

@ -19,7 +19,7 @@
* *
* *
* IDENTIFICATION * 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 */ MyProcPid = getpid(); /* reset MyProcPid */
MyStartTime = time(NULL); /* record Start Time for logging */
/* /*
* If possible, make this process a group leader, so that the postmaster * If possible, make this process a group leader, so that the postmaster
* can signal any child processes too. * can signal any child processes too.

View File

@ -13,7 +13,7 @@
* *
* Copyright (c) 2001-2007, PostgreSQL Global Development Group * 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" #include "postgres.h"
@ -2168,6 +2168,8 @@ PgstatCollectorMain(int argc, char *argv[])
MyProcPid = getpid(); /* reset MyProcPid */ MyProcPid = getpid(); /* reset MyProcPid */
MyStartTime = time(NULL); /* record Start Time for logging */
/* /*
* If possible, make this process a group leader, so that the postmaster * If possible, make this process a group leader, so that the postmaster
* can signal any child processes too. (pgstat probably never has * can signal any child processes too. (pgstat probably never has

View File

@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* *
@ -386,6 +386,8 @@ PostmasterMain(int argc, char *argv[])
MyProcPid = PostmasterPid = getpid(); MyProcPid = PostmasterPid = getpid();
MyStartTime = time(NULL);
IsPostmasterEnvironment = true; IsPostmasterEnvironment = true;
/* /*
@ -1103,6 +1105,8 @@ pmdaemonize(void)
MyProcPid = PostmasterPid = getpid(); /* reset PID vars to child */ MyProcPid = PostmasterPid = getpid(); /* reset PID vars to child */
MyStartTime = time(NULL);
/* GH: If there's no setsid(), we hopefully don't need silent mode. /* GH: If there's no setsid(), we hopefully don't need silent mode.
* Until there's a better solution. * Until there's a better solution.
*/ */
@ -2661,6 +2665,8 @@ BackendStartup(Port *port)
MyProcPid = getpid(); /* reset MyProcPid */ MyProcPid = getpid(); /* reset MyProcPid */
MyStartTime = time(NULL);
/* We don't want the postmaster's proc_exit() handlers */ /* We don't want the postmaster's proc_exit() handlers */
on_exit_reset(); on_exit_reset();
@ -2803,7 +2809,7 @@ BackendInitialize(Port *port)
/* save process start time */ /* save process start time */
port->SessionStartTime = GetCurrentTimestamp(); 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 */ /* set these to empty in case they are needed before we set them up */
port->remote_host = ""; port->remote_host = "";
@ -3385,6 +3391,8 @@ SubPostmasterMain(int argc, char *argv[])
MyProcPid = getpid(); /* reset MyProcPid */ MyProcPid = getpid(); /* reset MyProcPid */
MyStartTime = time(NULL);
/* make sure stderr is in binary mode before anything can /* make sure stderr is in binary mode before anything can
* possibly be written to it, in case it's actually the syslogger pipe, * possibly be written to it, in case it's actually the syslogger pipe,
* so the pipe chunking protocol isn't disturbed. Non-logpipe data * so the pipe chunking protocol isn't disturbed. Non-logpipe data

View File

@ -18,7 +18,7 @@
* *
* *
* IDENTIFICATION * 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 */ MyProcPid = getpid(); /* reset MyProcPid */
MyStartTime = time(NULL); /* set our start time in case we call elog */
#ifdef EXEC_BACKEND #ifdef EXEC_BACKEND
syslogger_parseArgs(argc, argv); syslogger_parseArgs(argc, argv);
#endif /* EXEC_BACKEND */ #endif /* EXEC_BACKEND */

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
@ -2786,6 +2786,8 @@ PostgresMain(int argc, char *argv[], const char *username)
*/ */
MyProcPid = getpid(); MyProcPid = getpid();
MyStartTime = time(NULL);
/* /*
* Fire up essential subsystems: error and memory management * Fire up essential subsystems: error and memory management
* *

View File

@ -42,7 +42,7 @@
* *
* *
* IDENTIFICATION * 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; break;
case 'c': case 'c':
if (MyProcPort) appendStringInfo(buf, "%lx.%x", (long)(MyStartTime),MyProcPid);
{
appendStringInfo(buf, "%lx.%x",
(long) (MyProcPort->session_start),
MyProcPid);
}
break; break;
case 'p': case 'p':
appendStringInfo(buf, "%d", MyProcPid); appendStringInfo(buf, "%d", MyProcPid);
@ -1552,7 +1547,6 @@ log_line_prefix(StringInfo buf)
} }
break; break;
case 's': case 's':
if (MyProcPort)
{ {
char strfbuf[128]; char strfbuf[128];
@ -1563,7 +1557,7 @@ log_line_prefix(StringInfo buf)
#else #else
"%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M:%S",
#endif #endif
localtime(&MyProcPort->session_start)); localtime(&MyStartTime));
appendStringInfoString(buf, strfbuf); appendStringInfoString(buf, strfbuf);
} }
break; break;

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* Globals used all over the place should be declared here and not * Globals used all over the place should be declared here and not
@ -33,6 +33,7 @@ volatile uint32 InterruptHoldoffCount = 0;
volatile uint32 CritSectionCount = 0; volatile uint32 CritSectionCount = 0;
int MyProcPid; int MyProcPid;
time_t MyStartTime;
struct Port *MyProcPort; struct Port *MyProcPort;
long MyCancelKey; long MyCancelKey;

View File

@ -11,7 +11,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2007, 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/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. * other members of this struct, we may as well keep it here.
*/ */
TimestampTz SessionStartTime; /* backend start time */ TimestampTz SessionStartTime; /* backend start time */
time_t session_start; /* same, in time_t format */
/* /*
* TCP keepalive settings. * TCP keepalive settings.

View File

@ -13,7 +13,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2007, 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/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 * NOTES
* some of the information in this file should be moved to other files. * some of the information in this file should be moved to other files.
@ -23,6 +23,8 @@
#ifndef MISCADMIN_H #ifndef MISCADMIN_H
#define MISCADMIN_H #define MISCADMIN_H
#include <time.h> /* for time_t */
#define PG_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n" #define PG_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
@ -132,6 +134,7 @@ extern int MaxBackends;
extern int MaxConnections; extern int MaxConnections;
extern PGDLLIMPORT int MyProcPid; extern PGDLLIMPORT int MyProcPid;
extern PGDLLIMPORT time_t MyStartTime;
extern PGDLLIMPORT struct Port *MyProcPort; extern PGDLLIMPORT struct Port *MyProcPort;
extern long MyCancelKey; extern long MyCancelKey;