Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fi311-0000KV-1X for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Jul 2018 19:30:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fi30z-0005hE-KM for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Jul 2018 19:30:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fi30z-0005h7-EA for pgsql-bugs@lists.postgresql.org; Tue, 24 Jul 2018 19:30:33 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fi30w-0003vh-Q6 for pgsql-bugs@lists.postgresql.org; Tue, 24 Jul 2018 19:30:32 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 58E2821BE2; Tue, 24 Jul 2018 15:30:29 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 24 Jul 2018 15:30:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=mVyd1KMk1HCNmbds7lMoKpN5xukP7f535ynCLbqLugs=; b=GMfzadIh iioVPUoTVjnYpPUjEvrjSPWCie8FTNPbje/Ot2JHL48Ew5XUIk/xG6WnTE59mkOY iI0i90E4DFw5+gAT9IL061rUyaMPf7QYFtdqcRlYX1aB06vGT36fmfyql6bQtrGQ bv7W8DQ0MfJar2v2rD2jli20bzqJdNkypdrqRvhf09C1P/LHfTBdtbcvDL5eDdoz X4BCCaG6K7Vx7oWvISMFv7SAhk1bS7oBuCL0nMGnFuv4z0IlTWZt3qfqlc6PU9sW K6lVOrZZF9QpxfFpHMfd+8xbIXF6q0O16ghNKtCLMy0ftjRG6ekTQpdM4rD1tjBw HCspByyeBknQzg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=mVyd1KMk1HCNmbds7lMoKpN5xukP7 f535ynCLbqLugs=; b=A20PPDe0LGZ1wgtg0RrVnfxV3bMNor9yVzYXOjMztsW95 VCSJN0VlAuTrAO+gkJj4jP+ya5VRKgfTLQ459XZLGwh2jYIbFTeVr1Q7x1/lQjkO gzb3Uqm/+INdOo39h+7cqw3AgdNTy0BUqzztUhoX+yqAI369nN/vjJQqP3O3imbr fNynE6c25h43oD091FnWC7GqUyFxqgVJv9CxbOhalYjyQ2oKWW0lWytVWbStKFCD pTZCIsAGHD8YpeNgRptr3CKIMCIOUDyGwgl1DXYFZzhG8RPiDKye9QYtbsUZoOvV JKgQga8wpflclXhdN3qM58ZK8xhvhky6Q4UydoJSg== X-ME-Proxy: X-ME-Sender: Received: from intern.anarazel.de (c-98-210-140-171.hsd1.ca.comcast.net [98.210.140.171]) by mail.messagingengine.com (Postfix) with ESMTPA id B8278E4636; Tue, 24 Jul 2018 15:30:28 -0400 (EDT) Date: Tue, 24 Jul 2018 12:30:27 -0700 From: Andres Freund To: olav@backupbay.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15294: Phantom read in serializable transaction when you rename schema. Message-ID: <20180724193027.ienedticl5crlebx@alap3.anarazel.de> References: <153245969228.1404.11293353392171366243@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <153245969228.1404.11293353392171366243@wrigleys.postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2018-07-24 19:14:52 +0000, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 15294 > Logged by: Olav Gjerde > Email address: olav@backupbay.com > PostgreSQL version: 10.4 > Operating system: Linux olav-system 4.15.0-29-generic #31-Ubuntu SMP > Description: > > We are developing a process where we want to rename schema when deploying a > data model to "prod". > > When using serializable you will not get any phantom reads if you use UPDATE > statements. But if you rename the schema name you will. > > You can do the following to reproduce this error > > CREATE SCHEMA prod; > CREATE SCHEMA staging; > CREATE SCHEMA history; > > CREATE TABLE prod.link(id serial, text text); > CREATE TABLE staging.link(id serial, text text); > > INSERT INTO prod.link (text) VALUES ('prod link text'); > INSERT INTO staging.link (text) VALUES ('staging link text'); > > Now start the first read transaction: > BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; > select * from prod.link; > id | text > ----+---------------- > 1 | prod link text > (1 row) > > > Then open another session and start new transaction where you rename schema > names and commit > BEGIN TRANSACTION; > > DROP SCHEMA history CASCADE; > ALTER SCHEMA prod RENAME TO history; > ALTER SCHEMA staging RENAME TO prod; > COMMIT; > > Now go back to the first session and continue within the same transaction: > select * from prod.link; > id | text > ----+------------------- > 1 | staging link text > (1 row) > > Is this an error? Or have I misunderstood something? Are transactions not > supported for schema renames? Transactions are supported, but DDL basically is processed as READ COMMITTED. There's not really a good way around that - you have to use the newer table definition etc, otherwise you might e.g. insert rows that violate newly added constraints and such. Btw, although that's unrelated in this case, you really can only rely on serializable if all the participating transactions use serializable. Greetings, Andres Freund