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 1oZfYZ-000638-Ja for pgsql-general@arkaria.postgresql.org; Sat, 17 Sep 2022 21:41:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oZfYW-00026l-RT for pgsql-general@arkaria.postgresql.org; Sat, 17 Sep 2022 21:40:56 +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 1oZfYV-00026b-9w for pgsql-general@lists.postgresql.org; Sat, 17 Sep 2022 21:40:56 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oZfYM-0001qW-Ft for pgsql-general@postgresql.org; Sat, 17 Sep 2022 21:40:54 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 33FF75C0264; Sat, 17 Sep 2022 17:40:42 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sat, 17 Sep 2022 17:40:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1663450842; x= 1663537242; bh=7jQsuPVn/LDdx0nZbfM4jn1gqIzBfv/wT1n8xYY/0Ew=; b=o 3sZaQds3oYulw/inReg7Sj8IxLHFWr68nYS6nqokTI4gEWPJ5hUWEv2okXTYXia5 /lORzJ99BEbXErzb5wR5E+lErGbmdbglw71Eu8PV0U7EO/naZ/J1dVi14xP5UloN ih/knvEPMfcRPVmkcpIb9SwpsyF89wqb54SI0b+pU4ZrE2+64pNMUyg3cL3abu/r obImroubhVVGgVgfo8r4n4vwWpHShSnYpBp6u2l2l0WIoUqK01UJ5oFbxK37hDBw wTj5BLJ71dNWluDAOPRZO6AYFwnCdCxxI1Hjtl7HkSWZ6lj7Jfsvy8/uluLr3gxR jHuWkkYxeFFKfyZhaedCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1663450842; x= 1663537242; bh=7jQsuPVn/LDdx0nZbfM4jn1gqIzBfv/wT1n8xYY/0Ew=; b=C 7wkY1XaVZIkIzNRnvccVlkjK9unWaN4loRvNOtIlIToNabfZQoOTUTQdI+KBkpja IzFrmv8WK+0EUhGgBXkMn0Jn3XZwqCIJu6AH6Ux4cBNtsSfFxOnhPoaGOaLXYDZA xMVoS1gbJOb571S0KFRFR6k0Vjk4Wxw0i7HboJ7f79Q4F09qMUVQBL6EwE2tqyzm UkjTaKJNp2A8vavecLalyi24cbpsiJWunSf+iak1CBCOqkJL2r5F4Dz3v726MGwk HKkQHwwvrcZZrxGnHGeMEDYE1uFtiVffM1sIkVFqFzj/eabc3dmxv/gSPq2Op8Ul 8HMjXkB4fkqkEIXM8f/eg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfedvfedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhephedugfethfettdehieevteeukedtjedvhfevkefg udefgeevteduvdeuvdeggeegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 17 Sep 2022 17:40:41 -0400 (EDT) Message-ID: <27304245-1e4e-a99a-ffe9-4d4ef80394c2@aklaver.com> Date: Sat, 17 Sep 2022 14:40:40 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: get user info on log Content-Language: en-US To: Ganesh Korde , Marcos Pegoraro Cc: Postgres General References: From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 9/16/22 19:22, Ganesh Korde wrote: > Hi, > >   You can use log_line_prefix in postgresql.conf to log the user name > into the logs. That uses the session user, the user that established the connection. What the OP is after is the role name that is set by SET ROLE or SET SESSION AUTHORIZATION. To illustrate: psql -d test -U postgres test(5432)=# select session_user, current_user; session_user | current_user --------------+-------------- postgres | postgres test(5432)=# set role aklaver; SET test(5432)=> select session_user, current_user; session_user | current_user --------------+-------------- postgres | aklaver (1 row) test(5432)=> select 1/0; ERROR: division by zero From log with log_line_prefix of log_line_prefix = '%a-%u-%m-%x' : psql-postgres-2022-09-17 14:36:06.635 PDT-0ERROR: division by zero psql-postgres-2022-09-17 14:36:06.635 PDT-0STATEMENT: select 1/0; Ganesh is looking for psql- not psql-, in this case psql-aklaver. > > Regards, > Ganesh Korde. > > On Fri, 16 Sep 2022, 6:31 pm Marcos Pegoraro, > wrote: > > Em qui., 15 de set. de 2022 às 12:59, Adrian Klaver > > escreveu: > > test(5432)=# set role maura; > ERROR:  role "maura" does not exist > test(5432)=# SET SESSION AUTHORIZATION 'maura'; > ERROR:  role "maura" does not exist > > No, I was asking about an error occurring later, not on set session > authorization command. > > set role maura; > --user Maura exists and set was done correctly > --now I´m working as Maura > select 1/0; -- I would like to see this exception on log being > logged as maura > > thanks > Marcos > -- Adrian Klaver adrian.klaver@aklaver.com