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 1vlU9D-00CuX4-30 for pgsql-general@arkaria.postgresql.org; Thu, 29 Jan 2026 15:41:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vlU9D-00A8Le-0C for pgsql-general@arkaria.postgresql.org; Thu, 29 Jan 2026 15:41:31 +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 1vlU9C-00A8LU-2L for pgsql-general@lists.postgresql.org; Thu, 29 Jan 2026 15:41:31 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vlU9A-002wXo-1O for pgsql-general@lists.postgresql.org; Thu, 29 Jan 2026 15:41:30 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 60TFfRCo1223181; Thu, 29 Jan 2026 10:41:27 -0500 From: Tom Lane To: Geoff Winkless cc: "pgsql-generallists.postgresql.org" Subject: Re: UNLOGGED table CREATEd on one connection not immediately visible to another connection In-reply-to: References: Comments: In-reply-to Geoff Winkless message dated "Thu, 29 Jan 2026 15:04:43 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1223179.1769701287.1@sss.pgh.pa.us> Date: Thu, 29 Jan 2026 10:41:27 -0500 Message-ID: <1223180.1769701287@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Geoff Winkless writes: > In our application we have a situation where once a day one process > CREATEs an UNLOGGED table and INSERTs several hundred records using > individual queries (no explicit transactions) all of which return > successfully. We then send the ID of the table that we have created > over a TCP socket to a second process, which runs a query that JOINs > against that new table. > Unfortunately quite often the second process is getting a > PGRES_FATAL_ERROR with > Primary: relation "qreftmp750" does not exist > Now (and this is very important) this appears to be a race condition, > because when that process immediately retries the same query (which we > do when we get FATAL_ERROR) it sometimes works on the second or third > (or even 11th) attempt. Perhaps the second process is querying a standby server rather than the primary? Replication lag could explain this. I don't really believe that it's possible within a single PG server, though. We take very substantial pains to avoid the race condition you're positing. If there is anything in your client software stack capable of issuing implicit begin/commit, that'd deserve a second/third/fourth look... regards, tom lane