6
Debug Messages
Not only debugging
monitoring long-running processes
writing an application log
Implementation strategies
directing debug output to the terminal or to the server log file
saving messages in a table or in a file
passing information to other processes
Another debugging approach consists in adding debug messages to the key 
parts of the code to provide the current context. As you analyze these 
messages, you can understand what exactly has gone wrong.
Apart from the debugging itself, debug messages can also perform other 
functions. They can indicate the execution stage of a long-running process. 
Similar to a database system, an application can write its own log. Having 
such a log with important data (e.g., report-related data: the name of the 
report, the user who has collected it, date, parameters, etc.) can greatly 
facilitate technical support.
We can single out several strategies of implementing debug messages in 
PL/pgSQL. Apart from using the already familiar RAISE command, which 
can display messages in the terminal (or save them into the server log), it is 
also possible to send messages to another process, as well as write them 
into a table or into a file.
When choosing the approach to use, you have to take a lot of different 
aspects into account. Are messages transactional (are they sent before the 
end of the transaction or only after it has been committed)? Can you send 
them from several sessions simultaneously? How can you set up access to 
the log file and clean up old log entries? How does logging affect 
performance? Do you have to modify the source code?