Re: Best way to use trigger to email a report ? - Mailing list pgsql-general

From Christophe Pettus
Subject Re: Best way to use trigger to email a report ?
Date
Msg-id 4B42A732-D80F-458A-A62C-FF2E96F5B1BC@thebuild.com
Whole thread Raw
In response to Best way to use trigger to email a report ?  (David Gauthier <davegauthierpg@gmail.com>)
Responses Re: Best way to use trigger to email a report ?  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-general

> On May 8, 2020, at 09:26, David Gauthier <davegauthierpg@gmail.com> wrote:
>
> psql (9.6.0, server 11.3) on linux
>
> Looking for ideas.  I want a trigger to...
> 1) compose an html report based on DB content
> 2) email the report to a dist list (dl = value of a table column)

You probably *don't* want to actually send an email within a trigger; doing an operation that can block on an external
service(DNS, SMTP) within a trigger is asking for hard-to-diagnose trouble.  You probably don't even want to create the
HTML;that's adding a lot of time to the operation that fires the trigger. 

I'd probably set up the trigger to store the minimal data required to produce the HTML into a separate table, and then
havea background job query the table, create the HTML, and mail out the report.  If you don't want to periodically poll
thetable, you can use NOTIFY within the trigger to wake up a process that is waiting on NOTIFY. 

--
-- Christophe Pettus
   xof@thebuild.com




pgsql-general by date:

Previous
From: Alan Hodgson
Date:
Subject: Re: Best way to use trigger to email a report ?
Next
From: "David G. Johnston"
Date:
Subject: Re: Best way to use trigger to email a report ?