2020-08-15 18:03:35.857 CST [1666] ERROR: type "invalidtype" does not exist at character 21 2020-08-15 18:03:35.857 CST [1666] STATEMENT: CREATE TABLE foo(id invalidtype);
现在我们来试试 backtrace 大法。首先我们可以通过搜索源码的方法确定当前错误是来自那个内部的 C 函数。这里我们确定它是由 typenameType() 函数抱出来的。那么我们可以按如下方式进行操作。
1 2 3 4 5 6
postgres=# SET backtrace_functions TO 'typenameType'; SET postgres=# CREATE TABLE foo(id invalidtype); ERROR: type "invalidtype" does not exist LINE 1: CREATE TABLE foo(id invalidtype); ^
/* * Compute backtrace data and add it to the supplied ErrorData. num_skip * specifies how many inner frames to skip. Use this to avoid showing the * internal backtrace support functions in the backtrace. This requires that * this and related functions are not inlined. */ staticvoid set_backtrace(ErrorData *edata, int num_skip) { StringInfoData errtrace;
initStringInfo(&errtrace);
#ifdef HAVE_BACKTRACE_SYMBOLS { void *buf[100]; int nframes; char **strfrms;
for (int i = num_skip; i < nframes; i++) appendStringInfo(&errtrace, "\n%s", strfrms[i]); free(strfrms); } #else appendStringInfoString(&errtrace, "backtrace generation is not supported by this installation"); #endif