1

We have set up a Postgres instance that is writing logs directly to AWS CloudWatch. We would like to be able to write our own logs for the purpose of automated processing. Unfortunately our current experiments seemed to generate logs only on the client (caller) side:

CREATE or replace FUNCTION logInfo() RETURNS void AS $$
    BEGIN
       raise notice 'Hello World!';
       raise info 'Hello World!';
    END;
$$ LANGUAGE plpgsql;

select logInfo();

Is there a way to write logs on the server side too?

1 Answers1

1

Keep in mind your log_min_messages and client_min_messages settings. plpgsql raise is able to use levels DEBUG, LOG, INFO, NOTICE, WARNING, and EXCEPTION (produces ERROR in terms of these settings). If you want to write something to the log, you need to raise it at a level higher than specified in log_min_messages.

For example,

raise log 'hello world'

will write lines like below (log_line_prefix removed by me):

LOG:  Hello World!
CONTEXT:  PL/pgSQL function loginfo() line 3 at RAISE
STATEMENT:  select logInfo();
Melkij
  • 3,912
  • 8
  • 17