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 1w5Rui-003GFh-0L for pgsql-general@arkaria.postgresql.org; Wed, 25 Mar 2026 17:21:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5Rug-00FThR-1t for pgsql-general@arkaria.postgresql.org; Wed, 25 Mar 2026 17:21:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w5Rug-00FThJ-0j for pgsql-general@lists.postgresql.org; Wed, 25 Mar 2026 17:21:02 +0000 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w5Rud-000000016ci-1aVx for pgsql-general@postgresql.org; Wed, 25 Mar 2026 17:21:02 +0000 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-38be5d7c27cso782731fa.0 for ; Wed, 25 Mar 2026 10:20:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774459258; cv=none; d=google.com; s=arc-20240605; b=ShPIuxDxFqqo/FrQR5Mh1tN9Ley5lekGzXOfOPPWS5vlgbisRyyhNvHu3uBNnwVfzj cpq1JYOm+Ty52nRWxYzw9w3VsGN/WkTrg/sh0GPSWXMyID+x4dAiv09Lja01vAJNiwut D2Y3QoCQxV4IM4EfG/NTbgy6sc1Zw+YT/HP4zrLZt50Il99fiCmyO4r5QsfBN/tGjJQz plQDJCHI4/rTVefYcLAiCoTh2+3i4oX98urpmVCLYVFwBMcsxKMrPJa3gRvQI/7EqEpH 6B+c+bMx+l4cwMT774UYrtkkvZ62T+WPWFTNQLK/NxrTIyKQeOKzYldmcYd03kyQo8I9 vNtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=rqdMnBtA1QSzYKV503YbvfV/jjtm1+8kB3ySaptOxBU=; fh=BVuptWvcqVGjpLXAcHdZy0e0PQa6XH8krFkuQRq3g8I=; b=iUbiecOExc+Dsl4zkFIOLVcKNP8jS0mI34sc1GOtoLF/l0LI8JV6iqP8AUJkt9nVcr IZ+KxF6ev+zhr8rfyLiKje8AZZ4B7XLX3HdWXRhRJaEg6CED/lHgjkorED10DhF2LctB lgn8eJeebgmqeZFd1dad2taWmyvICfl2uRaMbTbsu+Mkd00HVM1u3OnoaUrC83LKAajS +DF9jIKCXOX/zNfZtbx7xjiepkD7dDFlZ0jNVhVs7xYebmo1yrXpK1/jNmJiWsmd6BX7 z27gtkTQPCuRcaTkCBi8KHg0Adssi/OBGYYt3P0RbiWnC77sUc2Bti+amj5MRvALiHIz oe5w==; 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=1774459258; x=1775064058; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=rqdMnBtA1QSzYKV503YbvfV/jjtm1+8kB3ySaptOxBU=; b=A3ay5iII+wr0lto3S+NnzB5a/vh0v9LcK/ty6dgG44txr+U89c/4mjJ2p0cgmpqK8D KsObHtLYgrqmnizn7M775Rg3GSEl/dli1aomAuCbza7xhbNTP5+xN9oEGWuHh8cY7PzK W75YHIUocaX1yzGoiarWjuhQK9VcwSQy+B1WoKwmVCDsXYEQmcTzhBzUE3mMzUL8ltQu MMN3NKFLiCX0XAcyXw66k6Tj8LcAy7mA0Wl+6QiK6Y0sB3jLoJZiO/b/KnCXumup3yaF f5yIPxmDM+HqQeaaJ7beU/ecMkVvMesq5XCpYoVpN1nkcaDHBUvf+QIh79z0P6WanJd5 UZGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774459258; x=1775064058; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rqdMnBtA1QSzYKV503YbvfV/jjtm1+8kB3ySaptOxBU=; b=c7+S1Hl26MiGBIKHaq0/xf+DjwdjKf/JN7uPd7+q4KR1/xmv2kp1c8CjcP4DBrBjoN a6i7CcLOtnflB9HJY7RGmLTSQKB7yZ9l93k+EJoif23bO1RxGQoWuXVcCxtWHjK5qp2q z4fh3xpVHxvBd77w6tI+Bh/i1BpYiwOzIXAE5VJXTKD/gbzfN9hzfYFAwpYs8sft/HL6 czKopULQDBJmpJq8RMdGQjl6W9cDWIC8irNubdpbODrwvzNYvUgXRo9hsiGea/vkixLy 26hrPj7ZEpusUCQ4Lsv1RO/s+1eaKeKzKjuXzJ3xOxGtTWh4nwjcKeTOYmLyadE56nra goSA== X-Gm-Message-State: AOJu0YyETHGgtL5YNPLN7afFzgGYwLGFKS7PjH1GxTaCsDrHgqiEZAxW l9+F0vnuHWal63aMQMSbjca2BCIaqyAmbqKMX2lZP0NJbiOOAD7o0NBkMw9RSWyANhYwlfSmEHX e+FlqIE8iMI0u/IJiPTU+zn7YMzr2dS9k/w== X-Gm-Gg: ATEYQzwFcJYMSgnbj+92XhNH1ZkS+obGVRQ1icI90MnUNCJtuqMbuZNGaK93EQIs4PE 8N/iLSR1nlSkedJ26zPuzXHwBkUNdAigRSOmU6GQ5oJ0l5TT84cUprJ91XvQRCMfl+wBb9+OK7g VC0VtvsgO23yiXy7ELpwZVinXC7DWfRb4J5nn8YA3Y0BkGD0gb9hmHTuXozHmtVRbTdOdb1Gjxk Hpp733oCNTjwpA2TK97uh8Tk+hf6E+5+IFDKdIUT/qU28PpdohrKT+sTCOvpRdDCdB0athC8fev VKUvat0LMYroLNySrUJpGHOMb8oUfyfIe+r+DsTIww== X-Received: by 2002:a2e:8a87:0:b0:38a:5f1e:5a27 with SMTP id 38308e7fff4ca-38c42e977admr15403321fa.0.1774459258032; Wed, 25 Mar 2026 10:20:58 -0700 (PDT) MIME-Version: 1.0 From: Durumdara Date: Wed, 25 Mar 2026 18:20:46 +0100 X-Gm-Features: AQROBzAiFKqEAen4fcrUC0BqvIEnM3c-2w3NfUwFfLVKS__koRB_TAZWnXsG7E4 Message-ID: Subject: Where to store some session based info? To: Postgres General Content-Type: multipart/alternative; boundary="000000000000be5757064ddc7d8e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000be5757064ddc7d8e Content-Type: text/plain; charset="UTF-8" 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 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 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. Best regards dd --000000000000be5757064ddc7d8e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello!

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

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

In the trigger we try to find this table (in th= e 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 t= his is the safest solution.
If the User=C2=A0 ID is invalid (none or emp= ty) that means this is a background operation, and then we don't need t= o log the changes.

But maybe there is a better way= to somehow store some session based data and use it in the triggers.=C2=A0=
Because if these selects are slow, the trigger is also 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 is not enough= , because the PID is a repeated value.
I logged it and in the Windows s= ystem 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 star= t 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 di= fferent, 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 an= y way to get session based data?
As I read before, we can't set the = session variables onfly.

Best regards
dd

=

--000000000000be5757064ddc7d8e--