Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fJ52L-0001bR-4u for pgsql-general@arkaria.postgresql.org; Wed, 16 May 2018 22:36:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fJ52J-0000IY-IH for pgsql-general@arkaria.postgresql.org; Wed, 16 May 2018 22:36:43 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fJ52I-0000IO-Cf for pgsql-general@lists.postgresql.org; Wed, 16 May 2018 22:36:43 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fJ52E-0005Ok-61 for pgsql-general@postgresql.org; Wed, 16 May 2018 22:36:41 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id BB5C5220BD; Wed, 16 May 2018 18:36:36 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 16 May 2018 18:36:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=fCof3gZqF71ke8LVaZ9/dDEHUfFeF 5b+8BAZP61lq8U=; b=dCWAzbdhzFz3eF8rpsYpH5IzVw/6LBqTDaCAe8VNr3EYR Nlp6q5b4VNTBKvQe7pWTx72Xt+DnvZWRNla2D62FnquL2kyjzolk0vx89yePAAYo 0dPUpzzk5I3f1d1ivVFXihWqoVmcmab6zQQCzKQG2S98McxZz3dlVvhhrwUos/A/ n96de3/oyT1wLokzhRv0+fW5m3xGqfXffXORcSkng02JjUffv6DZudO8FYE2WqVZ SP2SbePS9KcO5uoQBVDhDsqlYlgRORTombuH4/UukTNBEEE7J64KKwayBHv3BV76 3C+BXLajIa8T4ZOOfRG/zBkaLM8pFyxx5F5a+QbOw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=fCof3g ZqF71ke8LVaZ9/dDEHUfFeF5b+8BAZP61lq8U=; b=LmO2DeDc2dZeofmvhC93gn AHfvPWJZmXdR9yxoF8fFPaVw2Rw1VdIWGVvS8P8h3TBLsGRoWHx9RqvtHSWW3LJt g29wkZOs3D3XYkEQeE3H42swYugJyq0CHjmL66qK0x6qfogLN85Yun8ZYj750VCq VPXdz/zembnBZC8zw07CHZVxOh5QeSvLIXSF3hkYf0dIs/79IyQAvHqaoF7Zsn+E 4NHNBJG1L3F/D2WzikrjcBBpybM1uFh2vRN7Gc/TAEpfX9+6w6/9PIk8XWx/XEbr c65c1TkKfJdjpufQ++u4g5vd2LNFlgS0F6Z7/GqiI95lccYMsYH1mhN+zjEyNYFw == X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.2] (unknown [71.212.135.74]) by mail.messagingengine.com (Postfix) with ESMTPA id DA06BE509F; Wed, 16 May 2018 18:36:35 -0400 (EDT) Subject: Re: When use triggers? To: hmidi slim , pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: <3c8d7297-265b-7bd2-3651-188deec0d0d0@aklaver.com> Date: Wed, 16 May 2018 15:36:34 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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