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 1kHqnA-0004VS-SO for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Sep 2020 15:53:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kHqn9-0003h9-CI for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Sep 2020 15:53:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kHqn9-0003ee-2C for pgsql-hackers@lists.postgresql.org; Mon, 14 Sep 2020 15:53:19 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kHqn2-0006Tn-HK for pgsql-hackers@postgresql.org; Mon, 14 Sep 2020 15:53:18 +0000 Received: from [192.168.27.200] (unknown [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 47F9621C3436; Mon, 14 Sep 2020 18:53:10 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1600098790; bh=S6er94MA1PcZRchDVRWQc0lzCPJBYLSWc0HYyIGbkrQ=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=gtWnOPN9VhZPO5JeKF6H12yfNmgcxb1RJNmgojt29vggEs9Dr3+ULAnffKcjYDq0G wQf0RBJPrA0yhQ/24W6ZOMjEH4HUIYK8CvgyDjwT03LdaJ9i2VdrBclpbY+sOOjbP/ dIf5h+JTfOKbVK9riFAJ1bxbQOVx5DbvMsotw/E4= Subject: Re: On login trigger: take three To: Pavel Stehule Cc: PostgreSQL Hackers References: <0d46d29f-4558-3af9-9c85-7774e14a7709@postgrespro.ru> <8d3b01bc-ed93-4f7d-0b2e-661e055fad2e@postgrespro.ru> <5706c7f5-98cd-bc20-cf1e-dd3f363e2c99@postgrespro.ru> From: Konstantin Knizhnik Message-ID: <5a3f33c8-6cda-2660-06f4-56482e1b3511@postgrespro.ru> Date: Mon, 14 Sep 2020 18:53:10 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------643B81D58E7B0D9AB3C45AC7" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------643B81D58E7B0D9AB3C45AC7 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 14.09.2020 17:34, Pavel Stehule wrote: > If we introduce buildin session trigger , we should to define what is > the session. Your design is much more related to the process than to > session. So the correct name should be "process_start" trigger, or > some should be different. I think there are two different events - > process_start, and session_start, and there should be two different > event triggers. Maybe the name "session_start" is just ambiguous and > should be used with a different name. I agree. I can rename trigger to backend_start or process_start or whatever else. > > 5. I do not quite understand your concern. If I define trigger > procedure which is  blocked (for example as in your example), then > I can > use pg_cancel_backend to interrupt execution of login trigger and > superuser can login. What should be changed here? > > > You cannot run pg_cancel_backend, because you cannot open a new > session. There is a cycle. It is always possible to login by disabling startup triggers using disable_session_start_trigger GUC: psql "dbname=postgres options='-c disable_session_start_trigger=true'" --------------643B81D58E7B0D9AB3C45AC7 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

On 14.09.2020 17:34, Pavel Stehule wrote:
If we introduce buildin session trigger , we should to define what is the session. Your design is much more related to the process than to session. So the correct name should be "process_start" trigger, or some should be different. I think there are two different events - process_start, and session_start, and there should be two different event triggers. Maybe the name "session_start" is just ambiguous and should be used with a different name. 

I agree.
I can rename trigger to backend_start or process_start or whatever else.

 

5. I do not quite understand your concern. If I define  trigger
procedure which is  blocked (for example as in your example), then I can
use pg_cancel_backend to interrupt execution of login trigger and
superuser can login. What should be changed here?

You cannot run pg_cancel_backend, because you cannot open a new session. There is a cycle.

It is always possible to login by disabling startup triggers using disable_session_start_trigger GUC:

psql "dbname=postgres options='-c disable_session_start_trigger=true'"


--------------643B81D58E7B0D9AB3C45AC7--