pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: hmidi slim <hmidi.slim2@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: When use triggers?
Date: Wed, 16 May 2018 15:36:34 -0700
Message-ID: <3c8d7297-265b-7bd2-3651-188deec0d0d0@aklaver.com> (raw)
In-Reply-To: <CAMsqVxtxHV39JAt8+_+bLDvVXnNJuLpWqv8=fUBapSXJyVg5rg@mail.gmail.com>
References: <CAMsqVxtxHV39JAt8+_+bLDvVXnNJuLpWqv8=fUBapSXJyVg5rg@mail.gmail.com>

On 05/16/2018 03:19 PM, hmidi slim wrote:
> HI,
> 
> I'm working on a microservice application and I avoid using triggers 
> because they will not be easy to maintain and need an experimented 
> person in database administration to manage them. So I prefer to manage 
> the work in the application using ORM and javascript.
> However I want to get some opinions and advices about using triggers: 
> when should I use them? How to manage them when there are some problems?

Two benefits triggers and their associated functions offer, with the 
understanding these are general statements:

1) Are in the database so tasks that always need happen do not need to 
be replicated across the various interfaces that touch the database.

2) Also since they run on the server the data does not necessarily cross 
a network, so less network bandwidth and better performance.

An example of a use case is table auditing. If you need to track what is 
being INSERTed/UPDATEd/DELETEd in a table stick an audit 
trigger/function on the table and push the information to an audit table.

As to managing, they are like any other code. I keep my schema code in 
scripts under version control and deploy them from there. I use 
Sqitch(http://sqitch.org/) which allows me to deploy and revert changes. 
I use a dev database to test and troubleshoot triggers and functions.

-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (9+ messages)  latest in thread

Message-ID: <3c8d7297-265b-7bd2-3651-188deec0d0d0@aklaver.com>
Permalink:  ../3c8d7297-265b-7bd2-3651-188deec0d0d0@aklaver.com/
Also on:    postgresql.org/message-id/3c8d7297-265b-7bd2-3651-188deec0d0d0@aklaver.com

 · 

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: adrian.klaver@aklaver.com, hmidi.slim2@gmail.com
  Subject: Re: When use triggers?
  In-Reply-To: <3c8d7297-265b-7bd2-3651-188deec0d0d0@aklaver.com>
  References: <CAMsqVxtxHV39JAt8+_+bLDvVXnNJuLpWqv8=fUBapSXJyVg5rg@mail.gmail.com> <3c8d7297-265b-7bd2-3651-188deec0d0d0@aklaver.com>

* 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