Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w5SDo-003Gem-0l for pgsql-general@arkaria.postgresql.org; Wed, 25 Mar 2026 17:40:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5SDm-00FhYt-1f for pgsql-general@arkaria.postgresql.org; Wed, 25 Mar 2026 17:40:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w5SDm-00FhYl-00 for pgsql-general@lists.postgresql.org; Wed, 25 Mar 2026 17:40:46 +0000 Received: from mail-yw1-x1130.google.com ([2607:f8b0:4864:20::1130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w5SDk-000000010Qk-22au for pgsql-general@postgresql.org; Wed, 25 Mar 2026 17:40:45 +0000 Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-79a8e873ca1so15922387b3.1 for ; Wed, 25 Mar 2026 10:40:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774460444; cv=none; d=google.com; s=arc-20240605; b=HF2unJiIJFEs0+j8w53I/MYA3Fge0Xg0grTba7zxEazqCyAzvT9gPqGOdyfE2OsfM/ lZVNi7n87uGaV62l8c1GYPU1/syayL8lDQVXW6luk/88OumptOzfkcjWEs4UpZBFxxFo IvsgpvQChLu+U50ZcvhMWwW6Vox1wSbF/P+K9IjsrTc247JsuBUgqrzcpBjyZWgpcgos fhKLsYX/j/TsM8UtXZ6FUO1EwmkIXLwoe5X6+OvcMLHoyxyEbpBp7rNE109NioiQVuYw kj7ZYTbTMNjOE6V6Vi9lXVsifCGIspIqbcIVCa7Bd31R44SWtjLUPyfHLUueN40JYdsm 3CCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=5p5ultII+s4cap+UrnuWcvu62k+gvcpRQEbo3fEGgHk=; fh=Z/wBWswqUZu2vTo3XP3WfhuW8lHt3iadZcCyq5P2Qv8=; b=cgHznnSKMQOyL2sXiwxcYMuJllqFgDih4k2k77ra2C+jDVk8LbCTmRLw2lvj+6nBHz R+uXNNswM41Onl4uO4yayEc/jJWlbf1Bu/3Re75bb5BMCE+QAmp88em0rocpvx2wba3n 91JwKZ2QxAYr65cpPHU7TsbAbAsqY/Eaw0pINjbs1tOluSYULnOdhiRtOMqmtaCJXhhS EcWmEdcBJBll8HlzOm/NYwk3iSyFAzHoWba6CjM2yU/w2kWaALSXTBDKayh59dekt11V ktFcNJdSomQeJbmrLd3An/tWELOAlZSq0wop3Dm9fUnaNdPCZP9m+gjfaouMGbEHUmVR d1pA==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774460444; x=1775065244; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5p5ultII+s4cap+UrnuWcvu62k+gvcpRQEbo3fEGgHk=; b=ooXyOKKFka3P0wMzPVGWGe/f3+b+GfzT8uuc/bq0gJEm9iG7KAwR+q2j1QECi/Zk1H nSYAcGGBl0bk17xof1V+zsQ+znG7LhBRnVkY6pq0MHsCTCPTw7jdKic6kL96ws+mRU6K cSO65j+O8QBN6cU8uwRXgFJ1LxLewcIpnegvDKXPakpiKXy9nTlY40MAPM3JztcCs9Mk 8JkALlccznFa6XN3JXYP0a3hZk9BtjEGOGEeO9tFi8sYqqULCkFVp+7O4i61qlq1yAqn c06YTVHu6r+zw5OKoaVlFJOvMOGHI3aNBSWx9WIuUee00EEU0KubrVuTezgH0WPmcJQp YQoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774460444; x=1775065244; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=5p5ultII+s4cap+UrnuWcvu62k+gvcpRQEbo3fEGgHk=; b=RK1pHIq4LmpBUyVjK/q8wE6B3GfD7l4pjHgjBqg9IOtf4o2u6adiG4T2cpwuDm4M5k +u1O+VDmvFU7i2msa7mm8f5mjzNWXYxAPBYwHV25gr4sD51YmP/T/DfD3Z7Tqgjk9a6X /0R1zoHprsFeXdBexkD9xXHVOrNGl4s7353tCJg9HnGf1I2a26KMgjC+nbERY/tyymXo 5wZMe5EfQMUClyesICm84M6HMtXlx4E2s13+QKxRM7ssrdn2EPgtgcIZ9mu+MOLx4jza QRxuArB0loUHxcz/8FUMDkEGgcz8ImWoxEnwDi6xIU4wq14zx1Vyvy6hyKALHM45XMsc yJhg== X-Gm-Message-State: AOJu0YyACSKmh9ZACi+O3XAQS6qkNhuUaiDyrc6k6nwcDmbiT1ozW38k otXCTblI+wM9zT4hhB6MhiyLP3dtoSGBf1sxdegH0WEqaaj38MbfbGKUfj5vu5Z+8wg6ifmOgDC XgYDoS49iiWcPl2jjr2lDZoEpDZFfelc= X-Gm-Gg: ATEYQzy9bwGtG6YgPYu5/9G7qQcJG1bVeaQaBmjHb51Kh7h9JNdgWepRzhMU24or8Rm egYk2BGBGYPvNQHdz8FZUeMT0Ndj/wBUU6xR9uC5gScXC89m/kciY8K0e0PCqJXpsWXQ/JBaltK aeamrSoRjG4dY0OOLe2L1qBw+EdyaqKkUOL8Da2ChGszlDiVQy2qrX/Mck3C1VUuq3AyBzH9ZGF C3QKjtVn8FWOLwoBTpkhu5vJemcIgv7K/cXA/JsgvBGx0qY8ccdAz++A0PwyICnq3O7G7/3otAl /2BJAerXcI54lj/gHzSGPGBLRYfmy/91ALpaiXochFS52YMrUCFhrM6Rojp1NlP9eWhutDiLEOu jaOrWxIR6kqV9+hwguY3iPm2rjHAqMNH/ULxUgn7t7mevEEN2z4c++jZazg== X-Received: by 2002:a05:690e:d53:b0:64e:df78:5bb6 with SMTP id 956f58d0204a3-64edf7860a9mr6380068d50.27.1774460443617; Wed, 25 Mar 2026 10:40:43 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Pavel Stehule Date: Wed, 25 Mar 2026 18:40:06 +0100 X-Gm-Features: AQROBzCpjYevmPKOT-LJavy_xvwhJ2Fb4rV3cy5IFrU_o-gE8YEA6G-XkwgtBcQ Message-ID: Subject: Re: Where to store some session based info? To: Durumdara Cc: Postgres General Content-Type: multipart/alternative; boundary="00000000000068eb54064ddcc40c" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000068eb54064ddcc40c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi st 25. 3. 2026 v 18:21 odes=C3=ADlatel Durumdara naps= al: > Hello! > > Sometimes we have to use "Current User ID", and "User Name" in the > Triggers to make a log into a table. These values are based on our User, > not in the PSQL role. > > Now we use a temporary table to do this. > When the user logged into the application, we created a temporary table > with the same name (user_info) and structure. This holds the data (id, > name, machine info, ip address). > > In the trigger we try to find this table (in the LOCAL_TEMPORARY schema). > Then we read the row into a JSON record, and then into PLPGSQL variables. > Tables can exist with the same name, so this is the safest solution. > If the User ID is invalid (none or empty) that means this is a backgroun= d > operation, and then we don't need to log the changes. > > But maybe there is a better way to somehow store some session based data > and use it in the triggers. > Because if these selects are slow, the trigger is also slow. So when I > start an UPDATE command in a big table, maybe this slows down the whole > operation. > > Note: > A table with the PID key is not enough, because the PID is a repeated > value. > I logged it and in the Windows system there are many of the same values > (10001, 10004, etc.). > Ok, I can combine with session creation time. But for this I also need to > start a select in the pg_stat_activty table. > > So maybe you have an easier way to point to a record in a session. > Important: the PG servers are different, the lesser version is 11, and we > have only a Database Owner role. We can't configure the server. > > What is your opinion? Is there any way to get session based data? > As I read before, we can't set the session variables onfly. > There are not native session variables, but you can use workaround - custom setting (2026-03-25 18:39:04) postgres=3D# set myvar.xxx to 'hello'; select current_setting('myvar.xxx'); SET =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=90 =E2=94=82 current_setting =E2=94=82 =E2=95=9E=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=A1 =E2=94=82 hello =E2=94=82 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=98 (1 row) Regards Pavel > > Best regards > dd > > > --00000000000068eb54064ddcc40c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

st 25. 3. 2026 v=C2=A018:21 o= des=C3=ADlatel Durumdara <durumda= ra@gmail.com> napsal:
Hello!

Sometimes we have to use "= Current User ID", and "User Name" in the Triggers to make a = log into a table. These values are based on our User, not in the PSQL role.=

Now we use=C2=A0a temporary table to do this.
When the user logged into the application, we created a temporary table wi= th the same name (user_info) and structure. This holds the data (id, name, = machine info, ip address).

In the trigger we try to find this= table (in the LOCAL_TEMPORARY schema).
Then we read the row into a JSO= N record, and then into PLPGSQL variables.
Tables can exist with the sa= me name, so this is the safest solution.
If the User=C2=A0 ID is invalid= (none or empty) that means this is a background operation, and then we don= 't need to log the changes.

But maybe there is= a better way to somehow store some session based data and use it in the tr= iggers.=C2=A0
Because if these selects are slow, the trigger is a= lso slow.=C2=A0So when I start an UPDATE command in a big table, maybe this= slows down the whole operation.

Note:
A table with the PID key i= s not enough, because the PID is a repeated value.
I logged it and in t= he Windows system there are many of the same values (10001, 10004, etc.).
Ok, I can combine with session creation time. But for this I also = need to start a select in the pg_stat_activty table.

So maybe you ha= ve an easier way to point to a record in a session.
Important: the PG se= rvers are different, the lesser version is 11, and we have only a Database = Owner role. We can't configure the server.

What is your opinion?= Is there any way to get session based data?
As I read before, we can= 9;t set the session variables onfly.

<= /div>
There are not native session variables, but you can use workaroun= d - custom setting

(2026-03-25 18:39:04) postgres=3D# set myvar.xxx to 'hello';
s= elect current_setting('myvar.xxx');
SET
=E2=94=8C=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90=
=E2=94=82 current_setting =E2=94=82
=E2=95=9E=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A1
=E2= =94=82 hello =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =E2=94=82
=E2=94=94=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=98
(1 row)

Regards

Pa= vel
=C2=A0

Best regards
dd

=
--00000000000068eb54064ddcc40c--