Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gTsVG-00046F-KE for pgsql-general@arkaria.postgresql.org; Mon, 03 Dec 2018 17:59:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gTsVF-0000XO-7O for pgsql-general@arkaria.postgresql.org; Mon, 03 Dec 2018 17:59:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gTsVE-0000XD-Rf for pgsql-general@lists.postgresql.org; Mon, 03 Dec 2018 17:59:28 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gTsVB-0006Qo-4c for pgsql-general@postgresql.org; Mon, 03 Dec 2018 17:59:27 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id D862A2317C; Mon, 3 Dec 2018 12:59:23 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 03 Dec 2018 12:59:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=v howYwfpjpr/C1KJx+fLPwy17ppMLLydharxaaGMUJc=; b=a2pRKnW55IbqAb6eG xCAzQhNCQ8/fUsYyJhm4Ah92yh5SmesRbfxvnL1pJjNYHPJQDr886ohk46zaskFi b2CSckPaaiBkQ7lA8S2JHK9UbntcbSINoqGEPWj/ZTy03+LZ/qVO22Pyk8BrZdaJ E9aBXpfV2MM9FSZ+GHmHE0s9F6Sx89LDuL84exf7b1BicjyeBhtveEYKA2KvJQOH Ocwmlj2dyt8oW0UNuIPq/JE3k5QeMqmbuDI+WlUCtxNNetv52DyTnDKK+1wUa38B 7o8iay5ZKiqVB86t7kX+C4gwDyQZDdAjVECHo+b3MrmC5Y5jKbM5lJNenF7M9HMh nQuPA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=vhowYwfpjpr/C1KJx+fLPwy17ppMLLydharxaaGMU Jc=; b=I43SSNRL1SOrw8Hf956nLBKorVCbdRl0kquJoTj/sM/0DYTrJ6pKwRqy2 85TBAQGEOBOrLVqLdQy80HW4kVLayK2ytc5ObtaO9shyp1+YKCa34uEPg4stbpHt KvHDNqR8U2p2/VmAIakUBa4fTJAvjIjhWwzSP7oK5w2gNmkLuk76Qx5DAXxSptew hDJyoLD1UasTKu9Q+dJnmeByXO5w3dIFQDqdlNdIQrg9PUvHGDs2QQpXdIY+zIQO RCu6FEbif9bOa9MLsnPmXNASqvvrTj6B4jvSwJoqTdFPkFYOGhG6nQJOJRUPotVu GrMTbixumGMC1aXeFgmwigWj+SWNg== X-ME-Sender: X-ME-Proxy: Received: from ranger.suse (unknown [74.94.73.222]) by mail.messagingengine.com (Postfix) with ESMTPA id 36F92102EE; Mon, 3 Dec 2018 12:59:23 -0500 (EST) Subject: Re: How to watch for schema changes To: Igor Korot Cc: pgsql-general References: <53538bab-5f26-247d-15bf-94785fdfb252@aklaver.com> <761d4f03-08f4-e354-9cc0-d3cc5d0319c4@aklaver.com> From: Adrian Klaver Message-ID: <4316b506-95d0-59b2-7857-5ae896e07e60@aklaver.com> Date: Mon, 3 Dec 2018 09:59:22 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.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 12/3/18 9:53 AM, Igor Korot wrote: >> So event triggers are associated with >> events(www.postgresql.org/docs/9.6/event-trigger-matrix.html) in a >> particular database. A rough description is that they are triggers on >> changes to the system catalogs. >> You could, I guess, create and drop them for each connection. To me it >> would seem more efficient to create them once. You then have the choice >> of leaving them running or using the ALTER command I posted previously >> to ENABLE/DISABLE them. > > OK, so how do I do it? > There is no "CREATE EVENT TRIGGER IF NOT EXIST". > > As I say - I'm trying to make it work from both ODBC and libpq > connection (one at a time) Why? Just create the trigger once in a script. Event triggers are an attribute of the database and stay with it until they are dropped. If you want to turn then on and off use the ALTER EVENT TRIGGER ENABLE/DISABLE. If you insist on recreating them on each connection then: https://www.postgresql.org/docs/10/sql-dropeventtrigger.html DROP EVENT TRIGGER [ IF EXISTS ] name [ CASCADE | RESTRICT ] CREATE EVENT TRIGGER ... > >> >>> >>> Now the other question is - how to make it work? >>> I can write the function code, compile it and place in the folder >>> where my executable is (or it should be in some postgreSQL dir?) and >>> then executing above code >>> will be enough. Is this correct? > > Also - what about this? > > And why did you say that saving the SQL commend is not a good idea. > > What's better? See above. > > Thank you. > >>> >>>> >>>>> >>>>> And then in my C++ code I will continuously query this temporary table. >>>> >>>> Why a temporary table? They are session specific and if the session >>>> aborts prematurely you will lose the information. >>> >>> Is there a better alternative? >>> >>> Thank you. >>> >>>> >>>>> >>>>> Or there is a better alternative on the algorithm? >>>>> >>>>> Thank you. >>>>> >>>>>>>> >>>>>>> Thank you. >>>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Adrian Klaver >>>>>> adrian.klaver@aklaver.com >>>>> >>>> >>>> >>>> -- >>>> Adrian Klaver >>>> adrian.klaver@aklaver.com >>> >> >> >> -- >> Adrian Klaver >> adrian.klaver@aklaver.com -- Adrian Klaver adrian.klaver@aklaver.com