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 1fdSyS-0005rn-Qm for pgsql-general@arkaria.postgresql.org; Thu, 12 Jul 2018 04:13:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fdSyR-0006Xd-0l for pgsql-general@arkaria.postgresql.org; Thu, 12 Jul 2018 04:12:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdSyP-0006XW-4w for pgsql-general@lists.postgresql.org; Thu, 12 Jul 2018 04:12:58 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdSyK-0005YZ-4r for pgsql-general@postgresql.org; Thu, 12 Jul 2018 04:12:56 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id B711621AFD; Thu, 12 Jul 2018 00:12:48 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 12 Jul 2018 00:12:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc: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=fm3; bh=LH4AvkKHt7y8dsfzi8HP6ZKYFIf6a 6HCLgc2Nsa9D2E=; b=QuHIO0pG1fvGSmmqv53OIXafFAzR9KPf0E4Mq14y7l2/h 3WU+ZG8gRwDYvarE06IwvoiyxvedShvV09Nz1nmESuCTrIxbVa03lk9xXmDwUdyD bcRjaYJo7/a6heLHwsRxBSRsEEnhzT86FYHFuPy47OQquyMxT6Q+fCcHhEjYpH3T 7141UgJcMTQPJT0+GBK+4wzTtIf1mCeHfOuyTBlQA83gt0fB09suDfTF4ya0KhFy lVeydmITSIoKRzumoQnh00uOD4ab4bAyE5sIVJ33QqD41hfgECjXiIYbxKpRELBv PDjnrdRI90UUTNq+beG4X6zKWMTNkw7p1c23bo4Nw== 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-sender:x-me-sender:x-sasl-enc; s=fm3; bh=LH4Avk KHt7y8dsfzi8HP6ZKYFIf6a6HCLgc2Nsa9D2E=; b=NKQQGoxF8uh4eClgHeBT/I F8Is+dIT6sffuT69chu3dh2WMDqsmbnoT1HXwIavDIP2D4llTWmcDH3dQmDPoWYa 6ICSxyKggtSKK9PSyY6GYW6H8IBQZLTxe5I/HI8aPEra571u9RE1SMk/APowijS1 VtPBLCYvOg9S9eO35xf2KWYzb/JmstFqFNWy3Or4OIFhSpAqYF2OBs0mmyKtELEo J0AzFheCW2PbXtBVsMm8qoWIj9X0V2xu/4WhtZNBPCjx1Vz0yNN3+AdJc24Vqf5q 6o0ZGf7Su9BmItei3+Y2vOHm5ngVkKb4hqaT304jM2vtObutwtEXRiUY2nzEZjjw == X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.134.181]) by mail.messagingengine.com (Postfix) with ESMTPA id 15D831026E; Thu, 12 Jul 2018 00:12:47 -0400 (EDT) Subject: Re: How to watch for schema changes To: Igor Korot Cc: pgsql-general References: <7fc929ec-8e34-5824-6511-d1dd1188434f@aklaver.com> <7faddf4c-3a58-d7f6-cef8-c65098fc16f5@aklaver.com> From: Adrian Klaver Message-ID: Date: Wed, 11 Jul 2018 21:12:47 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.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 07/11/2018 08:46 PM, Igor Korot wrote: > Hi, guys, > > > On Mon, Jul 9, 2018 at 5:38 PM, Adrian Klaver wrote: >> On 07/09/2018 01:49 PM, Igor Korot wrote: >>> >>> Hi, Adrian >>> >>> On Tue, Jul 3, 2018 at 1:24 PM, Adrian Klaver >>> wrote: >>>> >>>> On 07/03/2018 11:15 AM, Igor Korot wrote: >>>>> >>>>> >>>>> Adrian, >>>>> >>>>> On Tue, Jul 3, 2018 at 12:32 PM, Adrian Klaver >>>>> wrote: >>>>>> >>>>>> >>>>>> On 07/03/2018 10:21 AM, Igor Korot wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>> Hi, ALL, >>>>>>> Is there any trigger or some other means I can do on the server >>>>>>> which will watch for CREATE/ALTER/DROP TABLE command and after >>>>>>> successful >>>>>>> execution of those will issue a NOTIFY statement? >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> https://www.postgresql.org/docs/10/static/event-triggers.html >>>>> >>>>> >>>>> >>>>> According to the documentation the lowest version it supports is 9.3. >>>>> Anything prior to that? >>>>> >>>>> I'm working with OX 10.8 and it has 9.1 installed. >>>> >>>> >>>> 9.1 went EOL almost two years ago. The oldest supported version is 9.3, >>>> though it will go EOL this September: >>>> >>>> https://www.postgresql.org/support/versioning/ >>>> >>>> Are you forced to work with 9.1 or can you use something from here: >>>> >>>> https://www.postgresql.org/download/macosx/ >>>> >>>> to get a newer version? FYI that will be a major upgrade so will require >>>> a >>>> dump/restore or use of pg_upgrade. >>> >>> >>> Just a thought... >>> Is it possible to create a trigger for a system table? Or this >>> operation is restricted >> >> >> Easy enough to test. As postgres super user: >> >> test_(postgres)# create trigger info_test before insert on pg_class execute >> procedure ts_update(); >> >> ERROR: permission denied: "pg_class" is a system catalog > > But > > draft=# CREATE TRIGGER info_test AFTER INSERT ON > information_schema.tables EXECUTE PROCEDURE test(); > ERROR: function test() does not exist > > So it looks like this should be possible? No, see: https://www.postgresql.org/docs/10/static/sql-createtrigger.html AFTER trigger on views are STATEMENT level only. https://www.postgresql.org/docs/10/static/plpgsql-trigger.html "NEW Data type RECORD; variable holding the new database row for INSERT/UPDATE operations in row-level triggers. This variable is unassigned in statement-level triggers and for DELETE operations. OLD Data type RECORD; variable holding the old database row for UPDATE/DELETE operations in row-level triggers. This variable is unassigned in statement-level triggers and for INSERT operations. " So you won't know what was INSERTed in row. > > Thank you. > >> >> >>> for when the server is actually being set-up? >>> >>> Successful "CREATE TABLE..." statement creates a row inside the >>> information_schema.tables >>> so if I can create a trigger after this record is inserted or deleted >>> that should be fine. >>> >>> Thank you. >>> >>>> >>>>> >>>>> And a second question - how do I work with it? >>>>> I presume that function will have to be compiled in its own module >>>>> (either dll, so or dylib). >>>>> But then from the libpq interface how do I call it? >>>> >>>> >>>> >>>> It can use functions written in PL languages. See below: >>>> >>>> https://www.postgresql.org/docs/10/static/sql-createeventtrigger.html >>>> >>>> for an example written in plpgsql. >>>> >>>> >>>> >>>> >>>> >>>>> >>>>> 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