Commit b399805e authored by Tom Lane's avatar Tom Lane

Eliminate elog()'s hardwired limit on length of an error message.

This change seems necessary in conjunction with long queries, and it
cleans up some bogosity in connection with long EXPLAIN texts anyway.
Note that current libpq will accept any length error message (at least
until it runs out of memory); prior versions have a limit of 8K, but
will cleanly discard excess error text, so there shouldn't be any
big compatibility problems with old clients.
parent 1e4f0197
......@@ -4,7 +4,7 @@
*
* Copyright (c) 1994-5, Regents of the University of California
*
* $Id: explain.c,v 1.46 1999/08/31 01:28:28 tgl Exp $
* $Id: explain.c,v 1.47 1999/09/11 19:06:36 tgl Exp $
*
*/
......@@ -28,7 +28,6 @@ typedef struct ExplainState
} ExplainState;
static char *Explain_PlanToString(Plan *plan, ExplainState *es);
static void printLongNotice(const char *header, const char *message);
static void ExplainOneQuery(Query *query, bool verbose, CommandDest dest);
/* Convert a null string pointer into "<>" */
......@@ -110,7 +109,7 @@ ExplainOneQuery(Query *query, bool verbose, CommandDest dest)
s = nodeToString(plan);
if (s)
{
printLongNotice("QUERY DUMP:\n\n", s);
elog(NOTICE, "QUERY DUMP:\n\n%s", s);
pfree(s);
}
}
......@@ -120,7 +119,7 @@ ExplainOneQuery(Query *query, bool verbose, CommandDest dest)
s = Explain_PlanToString(plan, es);
if (s)
{
printLongNotice("QUERY PLAN:\n\n", s);
elog(NOTICE, "QUERY PLAN:\n\n%s", s);
pfree(s);
}
}
......@@ -332,7 +331,6 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
}
es->rtable = saved_rtable;
}
return;
}
static char *
......@@ -346,22 +344,3 @@ Explain_PlanToString(Plan *plan, ExplainState *es)
explain_outNode(&str, plan, 0, es);
return str.data;
}
/*
* Print a message that might exceed the size of the elog message buffer.
* This is a crock ... there shouldn't be an upper limit to what you can elog().
*/
static void
printLongNotice(const char *header, const char *message)
{
int len = strlen(message);
elog(NOTICE, "%.20s%.*s", header, ELOG_MAXLEN - 64, message);
len -= ELOG_MAXLEN - 64;
while (len > 0)
{
message += ELOG_MAXLEN - 64;
elog(NOTICE, "%.*s", ELOG_MAXLEN - 64, message);
len -= ELOG_MAXLEN - 64;
}
}
This diff is collapsed.
......@@ -2,22 +2,21 @@
*
* trace.c
*
* Conditional trace ans logging functions.
* Conditional trace and logging functions.
*
* Massimo Dal Zotto <dz@cs.unitn.it>
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include <unistd.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "postgres.h"
#ifdef USE_SYSLOG
#include <syslog.h>
#endif
......@@ -25,6 +24,13 @@
#include "miscadmin.h"
#include "utils/trace.h"
/*
* We could support trace messages of indefinite length, as elog() does,
* but it's probably not worth the trouble. Instead limit trace message
* length to this.
*/
#define TRACEMSG_MAXLEN 1024
#ifdef USE_SYSLOG
/*
* Global option to control the use of syslog(3) for logging:
......@@ -87,15 +93,14 @@ int
tprintf(int flag, const char *fmt,...)
{
va_list ap;
char line[ELOG_MAXLEN + TIMESTAMP_SIZE + 1];
char line[TRACEMSG_MAXLEN + TIMESTAMP_SIZE + 1];
#ifdef USE_SYSLOG
int log_level;
#endif
if ((flag == TRACE_ALL) || (pg_options[TRACE_ALL] > 0))
{
/* uconditional trace or trace all option set */
/* unconditional trace or trace all option set */
}
else if (pg_options[TRACE_ALL] == 0)
{
......@@ -105,11 +110,11 @@ tprintf(int flag, const char *fmt,...)
else if (pg_options[TRACE_ALL] < 0)
return 0;
va_start(ap, fmt);
#ifdef ELOG_TIMESTAMPS
strcpy(line, tprintf_timestamp());
#endif
vsnprintf(line + TIMESTAMP_SIZE, ELOG_MAXLEN, fmt, ap);
va_start(ap, fmt);
vsnprintf(line + TIMESTAMP_SIZE, TRACEMSG_MAXLEN, fmt, ap);
va_end(ap);
#ifdef USE_SYSLOG
......@@ -134,13 +139,13 @@ int
tprintf1(const char *fmt,...)
{
va_list ap;
char line[ELOG_MAXLEN + TIMESTAMP_SIZE + 1];
char line[TRACEMSG_MAXLEN + TIMESTAMP_SIZE + 1];
va_start(ap, fmt);
#ifdef ELOG_TIMESTAMPS
strcpy(line, tprintf_timestamp());
#endif
vsnprintf(line + TIMESTAMP_SIZE, ELOG_MAXLEN, fmt, ap);
va_start(ap, fmt);
vsnprintf(line + TIMESTAMP_SIZE, TRACEMSG_MAXLEN, fmt, ap);
va_end(ap);
#ifdef USE_SYSLOG
......@@ -164,13 +169,13 @@ int
eprintf(const char *fmt,...)
{
va_list ap;
char line[ELOG_MAXLEN + TIMESTAMP_SIZE + 1];
char line[TRACEMSG_MAXLEN + TIMESTAMP_SIZE + 1];
va_start(ap, fmt);
#ifdef ELOG_TIMESTAMPS
strcpy(line, tprintf_timestamp());
#endif
vsnprintf(line + TIMESTAMP_SIZE, ELOG_MAXLEN, fmt, ap);
va_start(ap, fmt);
vsnprintf(line + TIMESTAMP_SIZE, TRACEMSG_MAXLEN, fmt, ap);
va_end(ap);
#ifdef USE_SYSLOG
......
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: elog.h,v 1.11 1999/07/13 21:17:42 momjian Exp $
* $Id: elog.h,v 1.12 1999/09/11 19:06:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -14,36 +14,16 @@
#define ELOG_H
#define NOTICE 0 /* random info - no special action */
#define ERROR -1 /* user error - return to known state */
#define FATAL 1 /* Fatal error - abort process */
#define DEBUG -2 /* debug message */
#define NOIND -3 /* debug message, don't indent as far */
#ifdef NOT_USED
#define PTIME 0x100 /* prepend time to message */
#define POS 0x200 /* prepend source position to message */
#define USERMSG 0x400 /* send message to user */
#define TERM 0x800 /* send message to terminal */
#define DBLOG 0x1000 /* put message in per db log */
#define SLOG 0x2000 /* put message in system log */
#define ABORTX 0x4000 /* abort process after logging */
#endif
/* Increase this to be able to use postmaster -d 3 with complex
* view definitions (which are transformed to very, very large INSERT statements
* and if -d 3 is used the query string of these statements is printed using
* vsprintf which expects enough memory reserved! */
#define ELOG_MAXLEN 12288
#define ERROR (-1) /* user error - return to known state */
#define FATAL 1 /* fatal error - abort process */
#define REALLYFATAL 2 /* take down the other backends with me */
#define DEBUG (-2) /* debug message */
#define NOIND (-3) /* debug message, don't indent as far */
/* uncomment the following if you want your elog's to be timestamped */
/* #define ELOG_TIMESTAMPS */
extern void elog(int lev, const char *fmt,...);
extern void elog(int lev, const char *fmt, ...);
#ifndef PG_STANDALONE
int DebugFileOpen(void);
extern int DebugFileOpen(void);
#endif
#endif /* ELOG_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment