Skip to content

Commit 50cf19c

Browse files
committed
ereport() instead of elog()
More informative logging.
1 parent e9acc38 commit 50cf19c

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

pg_show_plans.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ append_query_plan(ExplainState *es)
289289
if (space_left < new_plan->len+1) {
290290
ereport(WARNING,
291291
errcode(ERRCODE_OUT_OF_MEMORY),
292-
errmsg("not enough memory to append new query plans"));
292+
errmsg("not enough memory to append new query plans"),
293+
errhint("Try increasing 'pg_show_plans.max_plan_length'."));
293294
return;
294295
}
295296

@@ -364,7 +365,10 @@ show_format()
364365
else if (pgsp->plan_format == EXPLAIN_FORMAT_XML)
365366
return "xml";
366367
else
367-
elog(ERROR, "unexpected plan_format value: %d", pgsp->plan_format);
368+
ereport(ERROR,
369+
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
370+
errmsg("unexpected plan_format value: %d", pgsp->plan_format),
371+
errhint("Valid values are 'text', 'json', 'yaml', 'xml'."));
368372
}
369373

370374
static inline void
@@ -374,9 +378,10 @@ shmem_safety_check(void)
374378
return;
375379

376380
ereport(ERROR,
377-
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
378-
errmsg("pg_show_plans must be loaded"
379-
" via shared_preload_libraries")));
381+
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
382+
errmsg("shared library not found"),
383+
errhint("Add 'pg_show_plans' to 'shared_preload_libraries', "
384+
"and restart the server."));
380385
}
381386

382387
static bool
@@ -455,7 +460,8 @@ pgsp_ExecutorStart(QueryDesc *queryDesc, int eflags)
455460
if (!ensure_cached()) {
456461
ereport(WARNING,
457462
errcode(ERRCODE_OUT_OF_MEMORY),
458-
errmsg("not enough memory to store new query plans"));
463+
errmsg("not enough memory to append new query plans"),
464+
errhint("Try increasing 'pg_show_plans.max_plan_length'."));
459465
return;
460466
}
461467

@@ -543,9 +549,9 @@ pg_show_plans(PG_FUNCTION_ARGS)
543549

544550
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
545551
ereport(ERROR,
546-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
547-
errmsg("function returning record called in context "
548-
"that cannot accept type record") ));
552+
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
553+
errmsg("function returning record called in context "
554+
"that cannot accept type record"));
549555
funcctx->tuple_desc = BlessTupleDesc(tupdesc);
550556

551557
MemoryContextSwitchTo(oldcontext);

0 commit comments

Comments
 (0)