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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With