]> granicus.if.org Git - postgresql/blob - src/include/utils/elog.h
Add GUC option log_error_verbosity to control which fields of error
[postgresql] / src / include / utils / elog.h
1 /*-------------------------------------------------------------------------
2  *
3  * elog.h
4  *        POSTGRES error logging definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: elog.h,v 1.45 2003/06/30 16:47:02 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef ELOG_H
15 #define ELOG_H
16
17 /* Error level codes */
18 #define DEBUG5          10                      /* Debugging messages, in categories of
19                                                                  * decreasing detail. */
20 #define DEBUG4          11
21 #define DEBUG3          12
22 #define DEBUG2          13
23 #define DEBUG1          14                      /* used by GUC debug_* variables */
24 #define LOG                     15                      /* Server operational messages; sent only
25                                                                  * to server log by default. */
26 #define COMMERROR       16                      /* Client communication problems; same as
27                                                                  * LOG for server reporting, but never
28                                                                  * sent to client. */
29 #define INFO            17                      /* Informative messages that are always
30                                                                  * sent to client;      is not affected by
31                                                                  * client_min_messages */
32 #define NOTICE          18                      /* Helpful messages to users about query
33                                                                  * operation;  sent to client and server
34                                                                  * log by default. */
35 #define WARNING         19                      /* Warnings */
36 #define ERROR           20                      /* user error - abort transaction; return
37                                                                  * to known state */
38 #define ERROR           20                      /* user error - abort transaction; return
39                                                                  * to known state */
40 /* Save ERROR value in PGERROR so it can bve restored when Win32 includes
41  * modify it.  We have to use a constant rather than ERROR because macros
42  * are expanded only when referenced outside macros.
43  */
44 #ifdef WIN32
45 #define PGERROR         20
46 #endif
47 #define FATAL           21                      /* fatal error - abort process */
48 #define PANIC           22                      /* take down the other backends with me */
49
50  /*#define DEBUG DEBUG1*/       /* Backward compatibility with pre-7.3 */
51
52
53 /* macros for representing SQLSTATE strings compactly */
54 #define PGSIXBIT(ch)    (((ch) - '0') & 0x3F)
55 #define PGUNSIXBIT(val) (((val) & 0x3F) + '0')
56
57 #define MAKE_SQLSTATE(ch1,ch2,ch3,ch4,ch5)      \
58         (PGSIXBIT(ch1) + (PGSIXBIT(ch2) << 6) + (PGSIXBIT(ch3) << 12) + \
59          (PGSIXBIT(ch4) << 18) + (PGSIXBIT(ch5) << 24))
60
61
62 /* SQLSTATE codes defined by SQL99 */
63 #define ERRCODE_AMBIGUOUS_CURSOR_NAME           MAKE_SQLSTATE('3','C', '0','0','0')
64 #define ERRCODE_CARDINALITY_VIOLATION           MAKE_SQLSTATE('2','1', '0','0','0')
65 #define ERRCODE_CLI_SPECIFIC_CONDITION          MAKE_SQLSTATE('H','Y', '0','0','0')
66 #define ERRCODE_CONNECTION_EXCEPTION            MAKE_SQLSTATE('0','8', '0','0','0')
67 #define ERRCODE_CONNECTION_DOES_NOT_EXIST       MAKE_SQLSTATE('0','8', '0','0','3')
68 #define ERRCODE_CONNECTION_FAILURE                      MAKE_SQLSTATE('0','8', '0','0','6')
69 #define ERRCODE_CONNECTION_NAME_IN_USE          MAKE_SQLSTATE('0','8', '0','0','2')
70 #define ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION             MAKE_SQLSTATE('0','8', '0','0','1')
71 #define ERRCODE_SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION       MAKE_SQLSTATE('0','8', '0','0','4')
72 #define ERRCODE_TRANSACTION_RESOLUTION_UNKNOWN          MAKE_SQLSTATE('0','8', '0','0','7')
73 #define ERRCODE_DATA_EXCEPTION                          MAKE_SQLSTATE('2','2', '0','0','0')
74 #define ERRCODE_ARRAY_ELEMENT_ERROR                     MAKE_SQLSTATE('2','2', '0','2','E')
75 #define ERRCODE_CHARACTER_NOT_IN_REPERTOIRE     MAKE_SQLSTATE('2','2', '0','2','1')
76 #define ERRCODE_DATETIME_FIELD_OVERFLOW         MAKE_SQLSTATE('2','2', '0','0','8')
77 #define ERRCODE_DIVISION_BY_ZERO                        MAKE_SQLSTATE('2','2', '0','1','2')
78 #define ERRCODE_ERROR_IN_ASSIGNMENT                     MAKE_SQLSTATE('2','2', '0','0','5')
79 #define ERRCODE_ESCAPE_CHARACTER_CONFLICT       MAKE_SQLSTATE('2','2', '0','0','B')
80 #define ERRCODE_INDICATOR_OVERFLOW                      MAKE_SQLSTATE('2','2', '0','2','2')
81 #define ERRCODE_INTERVAL_FIELD_OVERFLOW         MAKE_SQLSTATE('2','2', '0','1','5')
82 #define ERRCODE_INVALID_CHARACTER_VALUE_FOR_CAST                MAKE_SQLSTATE('2','2', '0','1','8')
83 #define ERRCODE_INVALID_DATETIME_FORMAT         MAKE_SQLSTATE('2','2', '0','0','7')
84 #define ERRCODE_INVALID_ESCAPE_CHARACTER        MAKE_SQLSTATE('2','2', '0','1','9')
85 #define ERRCODE_INVALID_ESCAPE_OCTET            MAKE_SQLSTATE('2','2', '0','0','D')
86 #define ERRCODE_INVALID_ESCAPE_SEQUENCE         MAKE_SQLSTATE('2','2', '0','2','5')
87 #define ERRCODE_INVALID_INDICATOR_PARAMETER_VALUE               MAKE_SQLSTATE('2','2', '0','1','0')
88 #define ERRCODE_INVALID_LIMIT_VALUE                     MAKE_SQLSTATE('2','2', '0','2','0')
89 #define ERRCODE_INVALID_PARAMETER_VALUE         MAKE_SQLSTATE('2','2', '0','2','3')
90 #define ERRCODE_INVALID_REGULAR_EXPRESSION      MAKE_SQLSTATE('2','2', '0','1','B')
91 #define ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE    MAKE_SQLSTATE('2','2', '0','0','9')
92 #define ERRCODE_INVALID_USE_OF_ESCAPE_CHARACTER         MAKE_SQLSTATE('2','2', '0','0','C')
93 #define ERRCODE_NULL_VALUE_NO_INDICATOR_PARAMETER       MAKE_SQLSTATE('2','2', '0','0','G')
94 #define ERRCODE_MOST_SPECIFIC_TYPE_MISMATCH     MAKE_SQLSTATE('2','2', '0','0','2')
95 #define ERRCODE_NULL_VALUE_NOT_ALLOWED          MAKE_SQLSTATE('2','2', '0','0','4')
96 #define ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE      MAKE_SQLSTATE('2','2', '0','0','3')
97 #define ERRCODE_STRING_DATA_LENGTH_MISMATCH     MAKE_SQLSTATE('2','2', '0','2','6')
98 #define ERRCODE_STRING_DATA_RIGHT_TRUNCATION            MAKE_SQLSTATE('2','2', '0','0','1')
99 #define ERRCODE_SUBSTRING_ERROR                         MAKE_SQLSTATE('2','2', '0','1','1')
100 #define ERRCODE_TRIM_ERROR                                      MAKE_SQLSTATE('2','2', '0','2','7')
101 #define ERRCODE_UNTERMINATED_C_STRING           MAKE_SQLSTATE('2','2', '0','2','4')
102 #define ERRCODE_ZERO_LENGTH_CHARACTER_STRING            MAKE_SQLSTATE('2','2', '0','0','F')
103 #define ERRCODE_DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST             MAKE_SQLSTATE('2','B', '0','0','0')
104 #define ERRCODE_EXTERNAL_ROUTINE_EXCEPTION      MAKE_SQLSTATE('3','8', '0','0','0')
105 #define ERRCODE_EXTERNAL_ROUTINE_EXCEPTION_CONTAINING_SQL_NOT_PERMITTED MAKE_SQLSTATE('3','8', '0','0','1')
106 #define ERRCODE_EXTERNAL_ROUTINE_EXCEPTION_MODIFYING_SQL_DATA_NOT_PERMITTED     MAKE_SQLSTATE('3','8', '0','0','2')
107 #define ERRCODE_EXTERNAL_ROUTINE_EXCEPTION_PROHIBITED_SQL_STATEMENT_ATTEMPTED   MAKE_SQLSTATE('3','8', '0','0','3')
108 #define ERRCODE_EXTERNAL_ROUTINE_EXCEPTION_READING_SQL_DATA_NOT_PERMITTED       MAKE_SQLSTATE('3','8', '0','0','4')
109 #define ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION   MAKE_SQLSTATE('3','9', '0','0','0')
110 #define ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION_INVALID_SQLSTATE_RETURNED MAKE_SQLSTATE('3','9', '0','0','1')
111 #define ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION_NULL_VALUE_NOT_ALLOWED    MAKE_SQLSTATE('3','9', '0','0','4')
112 #define ERRCODE_FEATURE_NOT_SUPPORTED           MAKE_SQLSTATE('0','A', '0','0','0')
113 #define ERRCODE_MULTIPLE_ENVIRONMENT_TRANSACTIONS       MAKE_SQLSTATE('0','A', '0','0','1')
114 #define ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION          MAKE_SQLSTATE('2','3', '0','0','0')
115 #define ERRCODE_RESTRICT_VIOLATION                      MAKE_SQLSTATE('2','3', '0','0','1')
116 #define ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION     MAKE_SQLSTATE('2','8', '0','0','0')
117 #define ERRCODE_INVALID_CATALOG_NAME            MAKE_SQLSTATE('3','D', '0','0','0')
118 #define ERRCODE_INVALID_CONDITION_NUMBER        MAKE_SQLSTATE('3','5', '0','0','0')
119 #define ERRCODE_INVALID_CONNECTION_NAME         MAKE_SQLSTATE('2','E', '0','0','0')
120 #define ERRCODE_INVALID_CURSOR_NAME                     MAKE_SQLSTATE('3','4', '0','0','0')
121 #define ERRCODE_INVALID_CURSOR_STATE            MAKE_SQLSTATE('2','4', '0','0','0')
122 #define ERRCODE_INVALID_GRANTOR_STATE           MAKE_SQLSTATE('0','L', '0','0','0')
123 #define ERRCODE_INVALID_ROLE_SPECIFICATION      MAKE_SQLSTATE('0','P', '0','0','0')
124 #define ERRCODE_INVALID_SCHEMA_NAME                     MAKE_SQLSTATE('3','F', '0','0','0')
125 #define ERRCODE_INVALID_SQL_DESCRIPTOR_NAME     MAKE_SQLSTATE('3','3', '0','0','0')
126 #define ERRCODE_INVALID_SQL_STATEMENT           MAKE_SQLSTATE('3','0', '0','0','0')
127 #define ERRCODE_INVALID_SQL_STATEMENT_NAME      MAKE_SQLSTATE('2','6', '0','0','0')
128 #define ERRCODE_INVALID_TARGET_SPECIFICATION_VALUE      MAKE_SQLSTATE('3','1', '0','0','0')
129 #define ERRCODE_INVALID_TRANSACTION_STATE       MAKE_SQLSTATE('2','5', '0','0','0')
130 #define ERRCODE_ACTIVE_SQL_TRANSACTION          MAKE_SQLSTATE('2','5', '0','0','1')
131 #define ERRCODE_BRANCH_TRANSACTION_ALREADY_ACTIVE       MAKE_SQLSTATE('2','5', '0','0','2')
132 #define ERRCODE_HELD_CURSOR_REQUIRES_SAME_ISOLATION_LEVEL       MAKE_SQLSTATE('2','5', '0','0','8')
133 #define ERRCODE_INAPPROPRIATE_ACCESS_MODE_FOR_BRANCH_TRANSACTION        MAKE_SQLSTATE('2','5', '0','0','3')
134 #define ERRCODE_INAPPROPRIATE_ISOLATION_LEVEL_FOR_BRANCH_TRANSACTION    MAKE_SQLSTATE('2','5', '0','0','4')
135 #define ERRCODE_NO_ACTIVE_SQL_TRANSACTION_FOR_BRANCH_TRANSACTION        MAKE_SQLSTATE('2','5', '0','0','5')
136 #define ERRCODE_READ_ONLY_SQL_TRANSACTION       MAKE_SQLSTATE('2','5', '0','0','6')
137 #define ERRCODE_SCHEMA_AND_DATA_STATEMENT_MIXING_NOT_SUPPORTED  MAKE_SQLSTATE('2','5', '0','0','7')
138 #define ERRCODE_INVALID_TRANSACTION_INITIATION          MAKE_SQLSTATE('0','B', '0','0','0')
139 #define ERRCODE_INVALID_TRANSACTION_TERMINATION         MAKE_SQLSTATE('2','D', '0','0','0')
140 #define ERRCODE_LOCATOR_EXCEPTION                       MAKE_SQLSTATE('0','F', '0','0','0')
141 #define ERRCODE_LOCATOR_EXCEPTION_INVALID_SPECIFICATION         MAKE_SQLSTATE('0','F', '0','0','1')
142 #define ERRCODE_NO_DATA                                         MAKE_SQLSTATE('0','2', '0','0','0')
143 #define ERRCODE_NO_ADDITIONAL_DYNAMIC_RESULT_SETS_RETURNED      MAKE_SQLSTATE('0','2', '0','0','1')
144 #define ERRCODE_REMOTE_DATABASE_ACCESS          MAKE_SQLSTATE('H','Z', '0','0','0')
145 #define ERRCODE_SAVEPOINT_EXCEPTION                     MAKE_SQLSTATE('3','B', '0','0','0')
146 #define ERRCODE_SAVEPOINT_EXCEPTION_INVALID_SPECIFICATION       MAKE_SQLSTATE('3','B', '0','0','1')
147 #define ERRCODE_SAVEPOINT_EXCEPTION_TOO_MANY            MAKE_SQLSTATE('3','B', '0','0','2')
148 #define ERRCODE_SQL_ROUTINE_EXCEPTION           MAKE_SQLSTATE('2','F', '0','0','0')
149 #define ERRCODE_FUNCTION_EXECUTED_NO_RETURN_STATEMENT           MAKE_SQLSTATE('2','F', '0','0','5')
150 #define ERRCODE_MODIFYING_SQL_DATA_NOT_PERMITTED        MAKE_SQLSTATE('2','F', '0','0','2')
151 #define ERRCODE_PROHIBITED_SQL_STATEMENT_ATTEMPTED      MAKE_SQLSTATE('2','F', '0','0','3')
152 #define ERRCODE_READING_SQL_DATA_NOT_PERMITTED          MAKE_SQLSTATE('2','F', '0','0','4')
153 #define ERRCODE_SQL_STATEMENT_NOT_YET_COMPLETE          MAKE_SQLSTATE('0','3', '0','0','0')
154 #define ERRCODE_SUCCESSFUL_COMPLETION           MAKE_SQLSTATE('0','0', '0','0','0')
155 #define ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION           MAKE_SQLSTATE('4','2', '0','0','0')
156 #define ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION_IN_DIRECT_STATEMENT       MAKE_SQLSTATE('2','A', '0','0','0')
157 #define ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION_IN_DYNAMIC_STATEMENT      MAKE_SQLSTATE('3','7', '0','0','0')
158 #define ERRCODE_TRANSACTION_ROLLBACK            MAKE_SQLSTATE('4','0', '0','0','0')
159 #define ERRCODE_TRANSACTION_ROLLBACK_INTEGRITY_CONSTRAINT_VIOLATION     MAKE_SQLSTATE('4','0', '0','0','2')
160 #define ERRCODE_TRANSACTION_ROLLBACK_SERIALIZATION_FAILURE      MAKE_SQLSTATE('4','0', '0','0','1')
161 #define ERRCODE_TRANSACTION_ROLLBACK_STATEMENT_COMPLETION_UNKNOWN       MAKE_SQLSTATE('4','0', '0','0','3')
162 #define ERRCODE_TRIGGERED_DATA_CHANGE_VIOLATION         MAKE_SQLSTATE('2','7', '0','0','0')
163 #define ERRCODE_WARNING                                         MAKE_SQLSTATE('0','1', '0','0','0')
164 #define ERRCODE_CURSOR_OPERATION_CONFLICT       MAKE_SQLSTATE('0','1', '0','0','1')
165 #define ERRCODE_DISCONNECT_ERROR                        MAKE_SQLSTATE('0','1', '0','0','2')
166 #define ERRCODE_DYNAMIC_RESULT_SETS_RETURNED            MAKE_SQLSTATE('0','1', '0','0','C')
167 #define ERRCODE_IMPLICIT_ZERO_BIT_PADDING       MAKE_SQLSTATE('0','1', '0','0','8')
168 #define ERRCODE_NULL_VALUE_ELIMINATED_IN_SET_FUNCTION   MAKE_SQLSTATE('0','1', '0','0','3')
169 #define ERRCODE_PRIVILEGE_NOT_GRANTED           MAKE_SQLSTATE('0','1', '0','0','7')
170 #define ERRCODE_PRIVILEGE_NOT_REVOKED           MAKE_SQLSTATE('0','1', '0','0','6')
171 #define ERRCODE_QUERY_EXPRESSION_TOO_LONG_FOR_INFORMATION_SCHEMA        MAKE_SQLSTATE('0','1', '0','0','A')
172 #define ERRCODE_SEARCH_CONDITION_TOO_LONG_FOR_INFORMATION_SCHEMA        MAKE_SQLSTATE('0','1', '0','0','9')
173 #define ERRCODE_STATEMENT_TOO_LONG_FOR_INFORMATION_SCHEMA       MAKE_SQLSTATE('0','1', '0','0','5')
174 #define ERRCODE_STRING_DATA_RIGHT_TRUNCATION_WARNING    MAKE_SQLSTATE('0','1', '0','0','4')
175 #define ERRCODE_WITH_CHECK_OPTION_VIOLATION     MAKE_SQLSTATE('4','4', '0','0','0')
176
177 /* Implementation-defined error codes for PostgreSQL */
178 #define ERRCODE_INTERNAL_ERROR                          MAKE_SQLSTATE('X','X', '0','0','0')
179
180
181 /* Which __func__ symbol do we have, if any? */
182 #ifdef HAVE_FUNCNAME__FUNC
183 #define PG_FUNCNAME_MACRO       __func__
184 #else
185 #ifdef HAVE_FUNCNAME__FUNCTION
186 #define PG_FUNCNAME_MACRO       __FUNCTION__
187 #else
188 #define PG_FUNCNAME_MACRO       NULL
189 #endif
190 #endif
191
192
193 /*----------
194  * New-style error reporting API: to be used in this way:
195  *              ereport(ERROR,
196  *                              (errcode(ERRCODE_INVALID_CURSOR_NAME),
197  *                               errmsg("portal \"%s\" not found", stmt->portalname),
198  *                               ... other errxxx() fields as needed ...));
199  *
200  * The error level is required, and so is a primary error message (errmsg
201  * or errmsg_internal).  All else is optional.  errcode() defaults to
202  * ERRCODE_INTERNAL_ERROR.
203  *----------
204  */
205 #define ereport(elevel, rest)  \
206         (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO) ? \
207          (errfinish rest) : (void) 0)
208
209 extern bool errstart(int elevel, const char *filename, int lineno,
210                                          const char *funcname);
211 extern void errfinish(int dummy, ...);
212
213 extern int errcode(int sqlerrcode);
214
215 extern int errmsg(const char *fmt, ...)
216 /* This extension allows gcc to check the format string for consistency with
217    the supplied arguments. */
218 __attribute__((format(printf, 1, 2)));
219
220 extern int errmsg_internal(const char *fmt, ...)
221 /* This extension allows gcc to check the format string for consistency with
222    the supplied arguments. */
223 __attribute__((format(printf, 1, 2)));
224
225 extern int errdetail(const char *fmt, ...)
226 /* This extension allows gcc to check the format string for consistency with
227    the supplied arguments. */
228 __attribute__((format(printf, 1, 2)));
229
230 extern int errhint(const char *fmt, ...)
231 /* This extension allows gcc to check the format string for consistency with
232    the supplied arguments. */
233 __attribute__((format(printf, 1, 2)));
234
235 extern int errcontext(const char *fmt, ...)
236 /* This extension allows gcc to check the format string for consistency with
237    the supplied arguments. */
238 __attribute__((format(printf, 1, 2)));
239
240 extern int errfunction(const char *funcname);
241 extern int errposition(int cursorpos);
242
243
244 /*----------
245  * Old-style error reporting API: to be used in this way:
246  *              elog(ERROR, "portal \"%s\" not found", stmt->portalname);
247  *----------
248  */
249 #define elog    errstart(ERROR, __FILE__, __LINE__, PG_FUNCNAME_MACRO), elog_finish
250
251 extern void
252 elog_finish(int elevel, const char *fmt, ...)
253 /* This extension allows gcc to check the format string for consistency with
254    the supplied arguments. */
255 __attribute__((format(printf, 2, 3)));
256
257
258 /* Support for attaching context information to error reports */
259
260 typedef struct ErrorContextCallback
261 {
262         struct ErrorContextCallback *previous;
263         void (*callback) (void *arg);
264         void *arg;
265 } ErrorContextCallback;
266
267 extern DLLIMPORT ErrorContextCallback *error_context_stack;
268
269
270 /* GUC-configurable parameters */
271
272 typedef enum
273 {
274         PGERROR_TERSE,                          /* single-line error messages */
275         PGERROR_DEFAULT,                        /* recommended style */
276         PGERROR_VERBOSE                         /* all the facts, ma'am */
277 } PGErrorVerbosity;
278
279 extern PGErrorVerbosity Log_error_verbosity;
280 extern bool Log_timestamp;
281 extern bool Log_pid;
282 #ifdef HAVE_SYSLOG
283 extern int      Use_syslog;
284 #endif
285
286
287 /* Other exported functions */
288 extern void DebugFileOpen(void);
289
290 #endif   /* ELOG_H */