pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Cory Tucker <cory.tucker@gmail.com>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: Asynchronous Trigger?
Date: Fri, 30 Mar 2018 07:49:38 +0200
Message-ID: <1522388978.2396.10.camel@cybertec.at> (raw)
In-Reply-To: <CAG_=8kAdbc_DoJWy11xh5J8b+v-ZWSt3Ty-1Ffdn4scgq3wK6Q@mail.gmail.com>
References: <CAG_=8kAdbc_DoJWy11xh5J8b+v-ZWSt3Ty-1Ffdn4scgq3wK6Q@mail.gmail.com>

Cory Tucker wrote:
> Is it possible to have the execution of a trigger (or any function) not block the
> completion of the statement they are associated with?

Constraint triggers can be deferred to the end of the transaction, but I
am certain that is not what you are looking for.

> A pattern I had hoped to implement was to do a quick update of rows that signaled
> they needed attention, and then an async per-row trigger would come and do the
> maintenance (in this case, make an expensive materialized view).
> 
> Any suggestions welcome.

This seems like a really bad idea - even if it happens "in the background", would
you want an expensive materialized view to be updated whenever a row is modified?
If you modify three rows, that would happen three times in a row!

One solution would be to set a flag somewhere that marks the materialized view
dirty, and a regular cron-job that checks the flag and rebuilds the view.
With the asynchronous solution you had in mind, the materialized view would not
be up to date anyway.

Other than that, if your materialized view definition is simple enough, you might
be able to use a regular table and a trigger that updates the table to reflect
the modifications caused by the insert, update or delete.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com




view thread (11+ messages)  latest in thread

Message-ID: <1522388978.2396.10.camel@cybertec.at>
Permalink:  ../1522388978.2396.10.camel@cybertec.at/
Also on:    postgresql.org/message-id/1522388978.2396.10.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, cory.tucker@gmail.com
  Subject: Re: Asynchronous Trigger?
  In-Reply-To: <1522388978.2396.10.camel@cybertec.at>
  References: <CAG_=8kAdbc_DoJWy11xh5J8b+v-ZWSt3Ty-1Ffdn4scgq3wK6Q@mail.gmail.com> <1522388978.2396.10.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox