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 1vVufM-009f9M-2f for pgsql-general@arkaria.postgresql.org; Wed, 17 Dec 2025 16:46:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vVufL-00Edna-2T for pgsql-general@arkaria.postgresql.org; Wed, 17 Dec 2025 16:46:20 +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 1vVufL-00EdnP-0K for pgsql-general@lists.postgresql.org; Wed, 17 Dec 2025 16:46:20 +0000 Received: from mail-yx1-xb130.google.com ([2607:f8b0:4864:20::b130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vVufJ-001BDS-32 for pgsql-general@postgresql.org; Wed, 17 Dec 2025 16:46:18 +0000 Received: by mail-yx1-xb130.google.com with SMTP id 956f58d0204a3-6446bae1e17so5269798d50.0 for ; Wed, 17 Dec 2025 08:46:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joeconway.com; s=google; t=1765989976; x=1766594776; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=IDK/cab1aPBX3Z/IdI1A45TYBBCAkiTyuehg1RmxEHI=; b=XL3Qdj+kdCiqmurHxJzmYKmViAqGpbOkS7GZNrcXALB5XHIdJ/5SZA+gBdoHUuZi/s JKMNey+sdu60imRtS9umfzqQFe3nEIQJDW4GM4+Bu2hqb5eJGOYXYWUMKDy27udbmaBo Xpib1qCzTUBzsE34ugKUKX27+KE1s4pNESF4fGIKSLA97IeO6b1fOmmPq+cGJYQuLNMr xXeXCf9DaP9Uph8LdSKQ+l3qcJ6SQVjzb7QjT/AN+mbpWQLzjRC7IqVdkCrb594FIH5i GcHHFdQTNHNbt+14b6vP0dkeL1N8janMLw5vr9NF3Js5/J4nssPMUcjWncDDLd0LSz0k GiVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765989976; x=1766594776; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IDK/cab1aPBX3Z/IdI1A45TYBBCAkiTyuehg1RmxEHI=; b=BBPbHte/AVSutFVQfL7bnzlTjBJ54rj9zugFPSKqYVZ1yrqVjW2fNB+ULU1xHclicO RrkzHNep7O7KAwGHiqV850TdnxmnSd+cMQxJcAXKKvVA177s77Z0IMHMP+C/vBWQvSnJ 5XDrIo143Rkb2qaiFko2S9Sjy0pKDXHBX87LTUdntD7ad9OP8brNkwWk7SGVh1XZYINh 7UDDTHqAtyezOLj//U9rjRZIPU2FH2j5aL6EDUB83VHSCW47q7hevxbs5VV/mBsdAtwv E7dQnDe6ELbZSKZ1qCFyshcRb9o66tDMOiysXK8Jlj2PcuV1107pezpZgasMwy9qgbyG dm6A== X-Forwarded-Encrypted: i=1; AJvYcCXATPPxeW35mytT84eptKfH9xex1DIDFyiei3vMFYdjCEStPTlFZ5YGZdzKw1cVNL3t1TzPr0fsaMI24N48@postgresql.org X-Gm-Message-State: AOJu0YztdZusfBIjbNGv/PU4/CGsQ1H606l2eqbdRd5qvNPE6kXSVjPS IDVJFL7LGsf9rtigHwSvlFCxa7coaf+yc4N/2Wepi0yERpa2SYxmOB16QHteUO5QTkQ= X-Gm-Gg: AY/fxX5jGMjbwB+zRCYPQFhfy12rpTdR2j2DDwf4YRy7t05iBqXGDDB8KpJN72CcF4S PFmIaefM2MlUn99uUiOf7i+Enxkh3lZzhm2/vZSbR3EKMAXCY5HgQgdpvo6LFuRZFARLvbW5LXy C2lGh8Yx/giD1OmRVCSj9eGV+bbDeO8LdB8dnvC2rag9A1gsdPFsq5D3udS4jqTonfnPndQKSHD MKmKPPli/wt6DJvIXmb8sHFpLmX2KEu5DVDNH3sXNT+vx02AUPKSIYl+8k/vOJlW2LtjxeehCgP AmPCqLgblm3HfU9XYQQ8hUbylLkTEYQ1td1uHLTw203jF7jLGDPmcMG8jcZzXN0Pynd5EpcuffJ xkl1DoPIshy2gYuk1TUaebFw2h046wAID+UHcpRmDTIAtZuHUAdcaw4nu24j1kGvpHijrMdmSCM esesXfJSbZGn+xCZQvYlHGoyUZwbQHevI4NGcO5EsRsYN5dJlOw64ZV/hLQ40NfN2kdQ== X-Google-Smtp-Source: AGHT+IEXiIJwC4sjEiQ3BF7RkA4cKcpP+H1e4Az+Topu3vsOyYDb/MJXJFd2vxqgsnzr9mSij7ZlNw== X-Received: by 2002:a05:690e:1484:b0:644:4a82:304e with SMTP id 956f58d0204a3-6455566414cmr13282469d50.80.1765989976056; Wed, 17 Dec 2025 08:46:16 -0800 (PST) Received: from [192.168.4.42] (162-239-31-113.lightspeed.dybhfl.sbcglobal.net. [162.239.31.113]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-64477d583e1sm9166372d50.7.2025.12.17.08.46.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 Dec 2025 08:46:15 -0800 (PST) Message-ID: <91687275-3826-49fc-b705-70ab2b6e0bcf@joeconway.com> Date: Wed, 17 Dec 2025 11:46:14 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Record last SELECT on a row? To: Matthias Leisi , pgsql-general References: <287E4DF6-35A2-4062-AEBA-32DB1DE35C5D@leisi.net> Content-Language: en-US From: Joe Conway 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 12/17/25 11:25, Matthias Leisi wrote: > >> pgaudit might satisfy your needs, since it would only log SELECT >> statements on that one table.  You'd still have to grep the log file, >> so the information wouldn't be real-time, but that's /probably/ not >> important. > > That’s a viable suggestion, thanks a lot. Real-time is indeed not > necessary, a daily (or even a weekly) cleaning of unused data is > sufficient. pgaudit was anyway on the table for some other use cases, so > that would fit in nicely. Possibly try using/abusing RLS? 8<----------------- psql test psql (19devel) Type "help" for help. create table t1(c1 int, c2 text); insert into t1 values(1,'a'),(2,'b'),(3,'c'),(42,'zp'); grant select on table t1 to public; create table a1(c1 int, t1 timestamptz); create or replace function audit(int) returns bool as $$ insert into a1 values($1, now()) returning true $$ security definer language sql; create policy audit_t1 ON t1 for select using (audit(c1)); alter table t1 enable row level security; create user joe; set session authorization joe; select * from t1 where c1=42; c1 | c2 ----+---- 42 | zp (1 row) reset session authorization; select * from a1; c1 | t1 ----+------------------------------- 42 | 2025-12-17 11:42:51.871843-05 (1 row) 8<----------------- HTH, -- Joe Conway PostgreSQL Contributors Team Amazon Web Services: https://aws.amazon.com