Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I put a lot of RAISE NOTICE in functions for debugging purpose. I think this will affect performance, so they should be removed on production environment. Is there any way to opt-out those logging/assertion functions only under specific conditions?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You could wrap them in an IF clause that tests a custom configuration variable. This will work but it's a bit verbose and each statement in PL/PgSQL has a cost.

I suspect you'll be better off lowering the log level in the RAISE messages so you log on a level like DEBUG that isn't captured by log_min_messages by default. That way you can just turn it on by changing client_min_messages or log_min_messages.

See the expanded form of the RAISE statement, eg:

RAISE DEBUG USING MESSAGE = 'TheMessage';

See the documentation for the RAISE statement.

Alternately, you can leave your messages at RAISE NOTICE and increase the log level, but that may hide other information you'll want to see in the logs. Better to log with a lower priority initially.

So long as the notices aren't doing lots of expensive string formatting or being called huge numbers of times I suspect you won't have too much trouble with their performance impact while logging to file/client is suppressed by log levels.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.