Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check current logging level in plpgsql

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?

like image 748
EM0 Avatar asked Oct 21 '25 14:10

EM0


1 Answers

You can use SHOW to retrieve the debug level into a variable and then test it as a piece of text.
Example in 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;
like image 116
Daniel Vérité Avatar answered Oct 23 '25 05:10

Daniel Vérité



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!