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">
<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>

View 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
*

View 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", "", "", "");

View 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.

View 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

View 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

View 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 */

View 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
*

View 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;

View 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;

View 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.

View 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;