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.94.2) (envelope-from ) id 1v1jTd-00C3Zt-W8 for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Sep 2025 10:45:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v1jTc-001u9W-N5 for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Sep 2025 10:45:28 +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.94.2) (envelope-from ) id 1v1jTc-001u9O-Bs for pgsql-hackers@lists.postgresql.org; Thu, 25 Sep 2025 10:45:28 +0000 Received: from udcm-wwu1.uni-muenster.de ([128.176.118.7]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v1jTY-002Lkh-2M for pgsql-hackers@postgresql.org; Thu, 25 Sep 2025 10:45:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=uni-muenster.de; i=@uni-muenster.de; q=dns/txt; s=uniout; t=1758797126; x=1790333126; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=bn+HC9oKPS5Apxs9EX023ym1UBhcHjsQ03g5u0/CjnA=; b=g7paCFmI+cIkdjL8SqxI/cfh7UPmVX7T+6sBBHn/e4NxrOM/yEHtpUpj 0VPcRyPQBwhYxD8xLGDms0gxiG2NgeqQqkoui0aDOda6wx3dFXGdEx6wE pc8AVe/iDtdYVhrT1u+dGgx+BGk/Pmf4R1/+u6CgRaysGnUfx9D/a00rJ xEuKYPM4tCV6TKZ4ISet6THiy0GlyW5uutZzkuh7Db4FMXG0iexsb9J15 VrZuDZX68QRik3S/FDX05uIsU/XIYOWOVNyFfqYennLobqvpjBcGMrihe uRaiU8AtDL3PIk9YqAeSEDqNXU8QSWtrJYy2zwOuk+rdkSYwUvw8ADlQo w==; X-CSE-ConnectionGUID: XA9EaCXuQLyv+MdGv52iTg== X-CSE-MsgGUID: 5TvJAlQzRPWc7laPeg3Svw== X-IronPort-AV: E=Sophos;i="6.18,292,1751234400"; d="scan'208";a="381175106" Received: from secmail.uni-muenster.de ([128.176.118.4]) by UDCM-RELAY1.UNI-MUENSTER.DE with ESMTP; 25 Sep 2025 12:45:22 +0200 Received: from [192.168.178.27] (dynamic-080-171-123-193.80.171.pool.telefonica.de [80.171.123.193]) by SECMAIL.UNI-MUENSTER.DE (Postfix) with ESMTPSA id F1E3B20ADF00; Thu, 25 Sep 2025 12:45:20 +0200 (CEST) Message-ID: Date: Thu, 25 Sep 2025 12:45:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Fix bug with accessing to temporary tables of other sessions To: Daniil Davydov <3danissimo@gmail.com>, Stepan Neretin Cc: PostgreSQL Hackers References: Content-Language: de-DE, en-GB From: Jim Jones In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Daniil, On 7/29/25 11:35, Daniil Davydov wrote: > I attach a v7 patch to this letter. No changes yet, just rebased on the newest > commit in master branch. A few days ago I reviewed one patch[1] that has a significant overlap with this one. Perhaps they should be merged? Here my first tests and comments: == session 1 == $ /usr/local/postgres-dev/bin/psql postgres psql (19devel) Type "help" for help. postgres=# CREATE TEMPORARY TABLE tmp AS SELECT 42 AS val; SELECT 1 postgres=# \d tmp Table "pg_temp_75.tmp" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+--------- val | integer | | | == session 2 == $ /usr/local/postgres-dev/bin/psql postgres psql (19devel) Type "help" for help. -- fixed: previously accessed the table but returning 0 rows postgres=# SELECT * FROM pg_temp_75.tmp; ERROR: could not access temporary relations of other sessions LINE 1: SELECT * FROM pg_temp_75.tmp; ^ -- fixed: previously returning DELETE 0 postgres=# DELETE FROM pg_temp_75.tmp; ERROR: could not access temporary relations of other sessions LINE 1: DELETE FROM pg_temp_75.tmp; ^ postgres=# TRUNCATE TABLE pg_temp_75.tmp; ERROR: could not access temporary relations of other sessions -- fixed: previously returning UPDATE 0 postgres=# UPDATE pg_temp_75.tmp SET val = NULL; ERROR: could not access temporary relations of other sessions LINE 1: UPDATE pg_temp_75.tmp SET val = NULL; ^ -- error message changed: previously "ERROR: cannot access temporary tables of other sessions" postgres=# INSERT INTO pg_temp_75.tmp VALUES (73); ERROR: could not access temporary relations of other sessions LINE 1: INSERT INTO pg_temp_75.tmp VALUES (73); ^ -- fixed: previously returning COPY 0 postgres=# COPY pg_temp_75.tmp TO '/tmp/foo'; ERROR: could not access temporary relations of other sessions -- error message changed. previously "ERROR: cannot alter temporary tables of other sessions" postgres=# ALTER TABLE pg_temp_75.tmp ADD COLUMN foo int; ERROR: could not access temporary relations of other sessions -- fixed: previously[2] it was possible to rename the temp table. postgres=# ALTER TABLE pg_temp_75.tmp RENAME TO bar; ERROR: could not access temporary relations of other sessions -- fixed: previously[3] it was possible to LOCK the temp table. postgres=# BEGIN; BEGIN postgres=*# LOCK TABLE pg_temp_75.tmp IN ACCESS EXCLUSIVE MODE; ERROR: could not access temporary relations of other sessions DROP TABLE still works, but I guess it is the main motivation of RVR_OTHER_TEMP_OK :) Thanks for the patch. It's a great improvement! Best regards, Jim [1] https://www.postgresql.org/message-id/flat/2736425.1758475979%40sss.pgh.pa.us [2] ALTER TABLE ... RENAME TO tests in PostgreSQL 14.19: == session 1 == psql (14.19 (Debian 14.19-1.pgdg13+1)) Geben Sie »help« für Hilfe ein. postgres=# CREATE TEMPORARY TABLE tmp AS SELECT 42 AS val; SELECT 1 postgres=# \d tmp Tabelle »pg_temp_4.tmp« Spalte | Typ | Sortierfolge | NULL erlaubt? | Vorgabewert --------+---------+--------------+---------------+------------- val | integer | | | == session 2 == psql (14.19 (Debian 14.19-1.pgdg13+1)) Geben Sie »help« für Hilfe ein. postgres=# ALTER TABLE pg_temp_4.tmp RENAME TO foo; ALTER TABLE == session 1 == postgres=# \d tmp Keine Relation namens »tmp« gefunden postgres=# \d foo Tabelle »pg_temp_4.foo« Spalte | Typ | Sortierfolge | NULL erlaubt? | Vorgabewert --------+---------+--------------+---------------+------------- val | integer | | | [3] LOCK TABLE tests in PostgreSQL 14.19 == session 2 == postgres=# BEGIN; BEGIN postgres=*# LOCK TABLE pg_temp_4.foo IN ACCESS EXCLUSIVE MODE; LOCK TABLE postgres=*# == session 1 == -- * owner of the temp table postgres=# SELECT locktype, relation::regclass, mode, granted, pid FROM pg_locks WHERE relation = 'pg_temp_4.foo'::regclass::oid; locktype | relation | mode | granted | pid ----------+----------+---------------------+---------+-------- relation | foo | AccessExclusiveLock | t | 277699 (1 Zeile)