Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kGe7O-0002gB-Uu for pgsql-bugs@arkaria.postgresql.org; Fri, 11 Sep 2020 08:09:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kGe7N-0001ce-5M for pgsql-bugs@arkaria.postgresql.org; Fri, 11 Sep 2020 08:09:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kGe7M-0001cW-Mv for pgsql-bugs@lists.postgresql.org; Fri, 11 Sep 2020 08:09:12 +0000 Received: from mail.dalibo.com ([212.85.157.172]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kGe7F-0000ch-JW for pgsql-bugs@lists.postgresql.org; Fri, 11 Sep 2020 08:09:11 +0000 Received: from firost (larco.ioguix.net [82.66.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id 9E2482004E; Fri, 11 Sep 2020 10:09:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1599811741; bh=H0H7tuJ4GOUwiuOY96lG2ZehCWemlvtFD349CPpY3pM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=i1wdYqCLEDofBrrkcIeo6g1x0UruGjxxYOtIxvyCfK9oWhXycO2f5eOFuBHlineTC AZ2BKwlfIWFsw7RJZpYbiQXEZYa6tYUC5efZ0LBwY6xiGjurddMV4CI2f1G+A4+P9u XDdsIVDNSFxUAGFCEUOqVwNyU1Xqin0kwttK3OLo= Date: Fri, 11 Sep 2020 10:09:00 +0200 From: Jehan-Guillaume de Rorthais To: Michael Paquier Cc: Alvaro Herrera , pgsql-bugs@lists.postgresql.org Subject: Re: [BUG v13] Crash with event trigger in extension Message-ID: <20200911100900.56770d84@firost> In-Reply-To: <20200911061441.GG2743@paquier.xyz> References: <20200908190759.12405fe5@firost> <20200908173222.GA781@alvherre.pgsql> <20200909125840.132229b6@firost> <20200911061441.GG2743@paquier.xyz> Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 11 Sep 2020 15:14:41 +0900 Michael Paquier wrote: > On Wed, Sep 09, 2020 at 12:58:40PM +0200, Jehan-Guillaume de Rorthais wrote: > > According to extension.c:execute_sql_string(), queries from > > extension script are executed as PROCESS_UTILITY_QUERY context. So > > isCompleteQuery is indeed always true in ProcessUtilitySlow. A breakpoint > > here while running my test case confirm this. > > > > Maybe you were talking about isTopLevel? But this one doesn't seem > > considered while defining if event triggers should trigger or not. > > > > Anyway, if event trigger should not trigger during create/alter extension, I > > suppose the original memory context bug that starts this discussion > > shouldn't happen in the first place (but need to be fixed anyway), isn't > > it? > > If I read correctly the code of event_trigger.c, command collection > and execution are and should be two different things, meaning that we > should still collect the commands and then at execution time we decide > if the event trigger associated to the commands should be fired or > not. > > Anyway, based on your example in [1], I can see that the event trigger > for ddl_command_end is correctly triggered for the ALTER TABLE command > included in the extension upgrade script if the event trigger is > enabled at the time the extension script triggers, which is the > behavior I would expect. What may be a problem though is that the > NOTICE you are trying to print does not show up, but I think that this > is caused by the particular context where the SQL queries from an > extension script are triggered within the backend in this case. > Also, if you want to make sure of the event trigger execution, you can > just change the notice to an exception in _evt_ext_ddl_fnct() and you > would see ALTER EXTENSION fail, pg_event_trigger_ddl_commands > capturing correctly the information associated to ALTER TABLE for > table "t": > ERROR: P0001: called "ALTER TABLE": public."public.t" > CONTEXT: PL/pgSQL function _evt_ext_ddl_fnct() line 5 at RAISE > LOCATION: exec_stmt_raise, pl_exec.c:3878 Thank for your investigation, explanation and time. > FWIW, I think that the fix proposed is fine as-is, and that we had > better apply it. +1