Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9fd842c

Browse files
committed
Add GUC variable to print original query to the server logs when there
is an error, warning, etc.Gavin Sherry
1 parent6a8babc commit9fd842c

File tree

7 files changed

+139
-96
lines changed

7 files changed

+139
-96
lines changed

‎doc/src/sgml/runtime.sgml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.132 2002/09/01 23:26:06 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.133 2002/09/02 05:42:54 momjian Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -942,7 +942,6 @@ env PGOPTIONS='-c geqo=off' psql
942942
</para>
943943
</listitem>
944944
</varlistentry>
945-
946945
<varlistentry>
947946
<term><varname>EXPLAIN_PRETTY_PRINT</varname> (<type>boolean</type>)</term>
948947
<listitem>
@@ -978,6 +977,28 @@ env PGOPTIONS='-c geqo=off' psql
978977
</listitem>
979978
</varlistentry>
980979

980+
<varlistentry>
981+
<term><varname>LOG_MIN_ERROR_STATEMENT</varname> (<type>string</type>)</term>
982+
<listitem>
983+
<para>
984+
This controls which log messages are accompanied by the original
985+
query which generated the message. All queries matching the setting
986+
or which are of a higher severity than the setting are logged. The
987+
default is <literal>ERROR</literal>. Valid values are
988+
<literal>DEBUG5</literal>, <literal>DEBUG4</literal>,
989+
<literal>DEBUG3</literal>, <literal>DEBUG2</literal>,
990+
<literal>DEBUG1</literal>, <literal>INFO</literal>,
991+
<literal>NOTICE</literal>, <literal>WARNING</literal>
992+
and <literal>ERROR</literal>.
993+
</para>
994+
<para>
995+
It is recommended you enable <literal>LOG_PID</literal> as well
996+
so you can more easily match the error statement with the error
997+
message.
998+
</para>
999+
</listitem>
1000+
</varlistentry>
1001+
9811002
<varlistentry>
9821003
<term><varname>LOG_PID</varname> (<type>boolean</type>)</term>
9831004
<listitem>
@@ -1005,8 +1026,8 @@ env PGOPTIONS='-c geqo=off' psql
10051026
<listitem>
10061027
<para>
10071028
Prints the duration of every completed query. To use this option,
1008-
enable LOG_STATEMENT and LOG_PID so youcan link the original query
1009-
to the duration using the process id.
1029+
enable<literal>LOG_STATEMENT</> and<literal>LOG_PID</> so you
1030+
can link the original queryto the duration using the process id.
10101031
</para>
10111032
</listitem>
10121033
</varlistentry>

‎src/backend/utils/error/elog.c

Lines changed: 11 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.101 2002/09/0202:47:05 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.102 2002/09/0205:42:54 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -33,17 +33,10 @@
3333
#include"storage/proc.h"
3434
#include"tcop/tcopprot.h"
3535
#include"utils/memutils.h"
36+
#include"utils/guc.h"
3637

3738
#include"mb/pg_wchar.h"
3839

39-
intserver_min_messages;
40-
char*server_min_messages_str=NULL;
41-
constcharserver_min_messages_str_default[]="notice";
42-
43-
intclient_min_messages;
44-
char*client_min_messages_str=NULL;
45-
constcharclient_min_messages_str_default[]="notice";
46-
4740
#ifdefHAVE_SYSLOG
4841
/*
4942
* 0 = only stdout/stderr
@@ -345,6 +338,7 @@ elog(int lev, const char *fmt,...)
345338
}
346339
}
347340

341+
348342
/*
349343
* Message prepared; send it where it should go
350344
*/
@@ -433,6 +427,14 @@ elog(int lev, const char *fmt,...)
433427
if (msg_buf!=msg_fixedbuf)
434428
free(msg_buf);
435429

430+
/* If the user wants this elog() generating query logged,
431+
* do so. We only want to log if the query has been
432+
* written to debug_query_string. Also, avoid infinite loops.
433+
*/
434+
435+
if(lev!=LOG&&lev >=log_min_error_statement&&debug_query_string)
436+
elog(LOG,"statement: %s",debug_query_string);
437+
436438
/*
437439
* Perform error recovery action as specified by lev.
438440
*/
@@ -835,71 +837,4 @@ elog_message_prefix(int lev)
835837
}
836838

837839

838-
/*
839-
* GUC support routines
840-
*/
841-
constchar*
842-
assign_server_min_messages(constchar*newval,
843-
booldoit,boolinteractive)
844-
{
845-
if (strcasecmp(newval,"debug")==0)
846-
{if (doit)server_min_messages=DEBUG1; }
847-
elseif (strcasecmp(newval,"debug5")==0)
848-
{if (doit)server_min_messages=DEBUG5; }
849-
elseif (strcasecmp(newval,"debug4")==0)
850-
{if (doit)server_min_messages=DEBUG4; }
851-
elseif (strcasecmp(newval,"debug3")==0)
852-
{if (doit)server_min_messages=DEBUG3; }
853-
elseif (strcasecmp(newval,"debug2")==0)
854-
{if (doit)server_min_messages=DEBUG2; }
855-
elseif (strcasecmp(newval,"debug1")==0)
856-
{if (doit)server_min_messages=DEBUG1; }
857-
elseif (strcasecmp(newval,"info")==0)
858-
{if (doit)server_min_messages=INFO; }
859-
elseif (strcasecmp(newval,"notice")==0)
860-
{if (doit)server_min_messages=NOTICE; }
861-
elseif (strcasecmp(newval,"warning")==0)
862-
{if (doit)server_min_messages=WARNING; }
863-
elseif (strcasecmp(newval,"error")==0)
864-
{if (doit)server_min_messages=ERROR; }
865-
elseif (strcasecmp(newval,"log")==0)
866-
{if (doit)server_min_messages=LOG; }
867-
elseif (strcasecmp(newval,"fatal")==0)
868-
{if (doit)server_min_messages=FATAL; }
869-
elseif (strcasecmp(newval,"panic")==0)
870-
{if (doit)server_min_messages=PANIC; }
871-
else
872-
returnNULL;/* fail */
873-
returnnewval;/* OK */
874-
}
875840

876-
constchar*
877-
assign_client_min_messages(constchar*newval,
878-
booldoit,boolinteractive)
879-
{
880-
if (strcasecmp(newval,"debug")==0)
881-
{if (doit)client_min_messages=DEBUG1; }
882-
elseif (strcasecmp(newval,"debug5")==0)
883-
{if (doit)client_min_messages=DEBUG5; }
884-
elseif (strcasecmp(newval,"debug4")==0)
885-
{if (doit)client_min_messages=DEBUG4; }
886-
elseif (strcasecmp(newval,"debug3")==0)
887-
{if (doit)client_min_messages=DEBUG3; }
888-
elseif (strcasecmp(newval,"debug2")==0)
889-
{if (doit)client_min_messages=DEBUG2; }
890-
elseif (strcasecmp(newval,"debug1")==0)
891-
{if (doit)client_min_messages=DEBUG1; }
892-
elseif (strcasecmp(newval,"log")==0)
893-
{if (doit)client_min_messages=LOG; }
894-
elseif (strcasecmp(newval,"info")==0)
895-
{if (doit)client_min_messages=INFO; }
896-
elseif (strcasecmp(newval,"notice")==0)
897-
{if (doit)client_min_messages=NOTICE; }
898-
elseif (strcasecmp(newval,"warning")==0)
899-
{if (doit)client_min_messages=WARNING; }
900-
elseif (strcasecmp(newval,"error")==0)
901-
{if (doit)client_min_messages=ERROR; }
902-
else
903-
returnNULL;/* fail */
904-
returnnewval;/* OK */
905-
}

‎src/backend/utils/misc/guc.c

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* command, configuration file, and command line options.
66
* See src/backend/utils/misc/README for more information.
77
*
8-
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.91 2002/09/0201:05:06 tgl Exp $
8+
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.92 2002/09/02 05:42:54 momjian Exp $
99
*
1010
* Copyright 2000 by PostgreSQL Global Development Group
1111
* Written by Peter Eisentraut <peter_e@gmx.net>.
@@ -71,6 +71,9 @@ static const char *assign_facility(const char *facility,
7171
booldoit,boolinteractive);
7272
#endif
7373

74+
staticconstchar*assign_msglvl(int*var,constchar*newval,
75+
booldoit,boolinteractive);
76+
7477
/*
7578
* Debugging options
7679
*/
@@ -99,6 +102,19 @@ boolAustralian_timezones = false;
99102

100103
boolPassword_encryption= true;
101104

105+
intlog_min_error_statement;
106+
char*log_min_error_statement_str=NULL;
107+
constcharlog_min_error_statement_str_default[]="error";
108+
109+
intserver_min_messages;
110+
char*server_min_messages_str=NULL;
111+
constcharserver_min_messages_str_default[]="notice";
112+
113+
intclient_min_messages;
114+
char*client_min_messages_str=NULL;
115+
constcharclient_min_messages_str_default[]="notice";
116+
117+
102118
#ifndefPG_KRB_SRVTAB
103119
#definePG_KRB_SRVTAB ""
104120
#endif
@@ -726,6 +742,11 @@ static struct config_string
726742
client_min_messages_str_default,assign_client_min_messages,NULL
727743
},
728744

745+
{
746+
{"log_min_error_statement",PGC_USERSET },&log_min_error_statement_str,
747+
log_min_error_statement_str_default,assign_min_error_statement,NULL
748+
},
749+
729750
{
730751
{"DateStyle",PGC_USERSET,GUC_LIST_INPUT },&datestyle_string,
731752
"ISO, US",assign_datestyle,show_datestyle
@@ -2877,3 +2898,54 @@ GUCArrayDelete(ArrayType *array, const char *name)
28772898

28782899
returnnewarray;
28792900
}
2901+
2902+
constchar*
2903+
assign_server_min_messages(constchar*newval,
2904+
booldoit,boolinteractive)
2905+
{
2906+
return(assign_msglvl(&server_min_messages,newval,doit,interactive));
2907+
}
2908+
2909+
constchar*
2910+
assign_client_min_messages(constchar*newval,
2911+
booldoit,boolinteractive)
2912+
{
2913+
return(assign_msglvl(&client_min_messages,newval,doit,interactive));
2914+
}
2915+
2916+
constchar*
2917+
assign_min_error_statement(constchar*newval,booldoit,boolinteractive)
2918+
{
2919+
return(assign_msglvl(&log_min_error_statement,newval,doit,interactive));
2920+
}
2921+
2922+
staticconstchar*
2923+
assign_msglvl(int*var,constchar*newval,booldoit,boolinteractive)
2924+
{
2925+
if (strcasecmp(newval,"debug")==0)
2926+
{if (doit) (*var)=DEBUG1; }
2927+
elseif (strcasecmp(newval,"debug5")==0)
2928+
{if (doit) (*var)=DEBUG5; }
2929+
elseif (strcasecmp(newval,"debug4")==0)
2930+
{if (doit) (*var)=DEBUG4; }
2931+
elseif (strcasecmp(newval,"debug3")==0)
2932+
{if (doit) (*var)=DEBUG3; }
2933+
elseif (strcasecmp(newval,"debug2")==0)
2934+
{if (doit) (*var)=DEBUG2; }
2935+
elseif (strcasecmp(newval,"debug1")==0)
2936+
{if (doit) (*var)=DEBUG1; }
2937+
elseif (strcasecmp(newval,"log")==0)
2938+
{if (doit) (*var)=LOG; }
2939+
elseif (strcasecmp(newval,"info")==0)
2940+
{if (doit) (*var)=INFO; }
2941+
elseif (strcasecmp(newval,"notice")==0)
2942+
{if (doit) (*var)=NOTICE; }
2943+
elseif (strcasecmp(newval,"warning")==0)
2944+
{if (doit) (*var)=WARNING; }
2945+
elseif (strcasecmp(newval,"error")==0)
2946+
{if (doit) (*var)=ERROR; }
2947+
else
2948+
returnNULL;/* fail */
2949+
returnnewval;/* OK */
2950+
}
2951+

‎src/backend/utils/misc/postgresql.conf.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@
127127
#log_duration = false
128128
#log_timestamp = false
129129

130+
#log_min_error_statement = error# Values in order of increasing severity:
131+
# debug5, debug4, debug3, debug2, debug1,
132+
# info, notice, warning, error
130133
#debug_print_parse = false
131134
#debug_print_rewritten = false
132135
#debug_print_plan = false

‎src/bin/psql/tab-complete.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000-2002 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.61 2002/09/01 23:26:06 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.62 2002/09/02 05:42:54 momjian Exp $
77
*/
88

99
/*----------------------------------------------------------------------
@@ -271,7 +271,7 @@ psql_completion(char *text, int start, int end)
271271
"default_transaction_isolation",
272272
"search_path",
273273
"statement_timeout",
274-
274+
"log_min_error_statement",
275275
NULL
276276
};
277277

‎src/include/utils/elog.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: elog.h,v 1.38 2002/06/20 20:29:52 momjian Exp $
10+
* $Id: elog.h,v 1.39 2002/09/02 05:42:54 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -47,22 +47,12 @@ extern intUse_syslog;
4747
externboolLog_timestamp;
4848
externboolLog_pid;
4949

50-
externchar*server_min_messages_str;
51-
externchar*client_min_messages_str;
52-
externconstcharserver_min_messages_str_default[];
53-
externconstcharclient_min_messages_str_default[];
54-
5550
externvoid
5651
elog(intlev,constchar*fmt,...)
5752
/* This extension allows gcc to check the format string for consistency with
5853
the supplied arguments. */
5954
__attribute__((format(printf,2,3)));
6055

61-
externintDebugFileOpen(void);
62-
63-
externconstchar*assign_server_min_messages(constchar*newval,
64-
booldoit,boolinteractive);
65-
externconstchar*assign_client_min_messages(constchar*newval,
66-
booldoit,boolinteractive);
56+
externintDebugFileOpen(void);
6757

6858
#endif/* ELOG_H */

‎src/include/utils/guc.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* External declarations pertaining to backend/utils/misc/guc.c and
55
* backend/utils/misc/guc-file.l
66
*
7-
* $Id: guc.h,v 1.21 2002/09/01 23:26:06 momjian Exp $
7+
* $Id: guc.h,v 1.22 2002/09/02 05:42:54 momjian Exp $
88
*/
99
#ifndefGUC_H
1010
#defineGUC_H
@@ -100,6 +100,13 @@ extern void ProcessGUCArray(ArrayType *array, GucSource source);
100100
externArrayType*GUCArrayAdd(ArrayType*array,constchar*name,constchar*value);
101101
externArrayType*GUCArrayDelete(ArrayType*array,constchar*name);
102102

103+
externconstchar*assign_min_error_statement(constchar*newval,booldoit,
104+
boolinteractive);
105+
106+
externconstchar*assign_server_min_messages(constchar*newval,
107+
booldoit,boolinteractive);
108+
externconstchar*assign_client_min_messages(constchar*newval,
109+
booldoit,boolinteractive);
103110
externboolLog_statement;
104111
externboolLog_duration;
105112
externboolDebug_print_plan;
@@ -118,4 +125,19 @@ extern bool Explain_pretty_print;
118125
externboolSQL_inheritance;
119126
externboolAustralian_timezones;
120127

128+
externchar*debug_query_string;
129+
130+
externintlog_min_error_statement;
131+
externchar*log_min_error_statement_str;
132+
externconstcharlog_min_error_statement_str_default[];
133+
134+
externintserver_min_messages;
135+
externchar*server_min_messages_str;
136+
externconstcharserver_min_messages_str_default[];
137+
138+
externintclient_min_messages;
139+
externchar*client_min_messages_str;
140+
141+
externconstcharclient_min_messages_str_default[];
142+
121143
#endif/* GUC_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp