#native_company# #native_desc#
#native_cta#

A Primer On Postgres Exception Handling for the PHP Developer Page 2

By Robert Bernier
on November 6, 2007

The Postgres parameter, client_min_messages, is set in postgresql.conf. It controls the client (web server) message levels and includes: DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, LOG, NOTICE, WARNING, ERROR, FATAL, and PANIC. For example, the default value for client_min_messages of NOTICE incompasses the messages for WARNING, ERROR, FATAL AND PANIC. Resetting the parameter for example to FATAL means no messages will be sent the client unless they are of a rank FATAL and PANIC. Setting the parameter at PANIC will interdict all messages to the client, which may be an issue if your PHP depends on any error notification from the server.
EXAMPLE: The following example demonstrates 3 levels of client messaging. Create a function that raises messages at different levels:

CREATE OR REPLACE FUNCTION f_msg (
    IN msg text
) RETURNS VOID AS
$body$
BEGIN
    RAISE NOTICE '%, via NOTICE',msg;
    RAISE LOG '%, via LOG',msg;
    RAISE EXCEPTION '%, via EXCEPTION',msg;
END;
$body$
LANGUAGE PLPGSQL;

Case 1:

The server is started, level NOTICE and EXCEPTION messages are sent but not the level LOG.

pg_ctl -D ~/cluster_phpbuilder/ -o '-c client_min_messages=notice' start

The client executes a query against the function:

robert@laptop:~/tmp$ psql -t -c "select f_msg('this message is sent to the client');"
NOTICE:  this message is sent to the client, via NOTICE
ERROR:  this message is sent to the client, via EXCEPTION

Case 2:

NOTICE, EXCEPTION and LOG levels are sent to the client.

pg_ctl -D ~/cluster_phpbuilder/ -o '-c client_min_messages=log' restart

The client executes a query against the function with the parameter client_min_messages=log.

robert@laptop:~/tmp$ psql -t -c "select f_msg('this message is sent to the client');"
NOTICE:  this message is sent to the client, via NOTICE
LOG:  this message is sent to the client, via LOG
ERROR:  this message is sent to the client, via EXCEPTION

Come back next week when we present lots more POSTGRES exception examples, and continue with our article on Postgres exception handling.