2

A performance-critical plpgsql function in PostgreSQL 9.2 has a "RAISE DEBUG" statement that calls an expensive function for one of the arguments, ie.

RAISE DEBUG 'Details: %', expensive_function(...);

It appears that the function is called even when DEBUG logging is disabled. Is there a way I can check what the current logging level is (both log_min_messages and client_min_messages) in an IF statement or some other way I can call the function only if needed?

4

1 回答 1

3

您可以使用SHOW将调试级别检索到变量中,然后将其作为一段文本进行测试。
plpgsql 中的示例:

DECLARE
  dbg_level text;
BEGIN
  SHOW client_min_messages INTO dbg_level;
  IF (dbg_level ilike 'debug%') THEN
    RAISE DEBUG 'details: %', expensive_function();
  END IF;
END;
于 2013-08-11T17:16:04.090 回答