Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aSNja-0005f0-Fq for pgsql-bugs@arkaria.postgresql.org; Sun, 07 Feb 2016 11:42:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aSNjZ-00023o-EJ for pgsql-bugs@arkaria.postgresql.org; Sun, 07 Feb 2016 11:42:29 +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.84) (envelope-from ) id 1aSNjX-000239-Gs for pgsql-bugs@postgresql.org; Sun, 07 Feb 2016 11:42:27 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aSNjP-0004GQ-Pe for pgsql-bugs@postgresql.org; Sun, 07 Feb 2016 11:42:27 +0000 Received: from intern.anarazel.de (tmo-100-108.customers.d1-online.com [80.187.100.108]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id C475A580003; Sun, 7 Feb 2016 12:42:18 +0100 (CET) Date: Sun, 7 Feb 2016 12:42:17 +0100 From: Andres Freund To: jarred@webriots.com Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13844: Logical decoding bug with subxact + row locking Message-ID: <20160207114217.pct2ldvbtdubriy3@alap3.anarazel.de> References: <20160105033249.1087.66040@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160105033249.1087.66040@wrigleys.postgresql.org> X-Pg-Spam-Score: -4.4 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Hi, On 2016-01-05 03:32:49 +0000, jarred@webriots.com wrote: > This is a pretty serious logical decoding bug that bit us pretty hard > in production. > > Run the following code: > > > ---------------------------------------------------------------------------- > CREATE TABLE foo(a SERIAL PRIMARY KEY, b TEXT); > > SELECT pg_create_logical_replication_slot('regression_slot', > 'test_decoding'); > > INSERT INTO foo (b) VALUES ('john'); > > BEGIN; > SELECT * FROM foo WHERE b = 'john' FOR UPDATE; > SAVEPOINT sp1; > INSERT INTO foo (b) VALUES ('jane'); > ROLLBACK TO SAVEPOINT sp1; > INSERT INTO foo (b) VALUES ('doe'); > END; > > SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, > NULL); > > ---------------------------------------------------------------------------- > > The last select above should return the decoded WAL, but instead it > returns: > > > ---------------------------------------------------------------------------- > ERROR: subxact logged without previous toplevel record > > ---------------------------------------------------------------------------- Ugh, that's an annoying bug. Working on producing a fix. The problem is that logical decoding expects to know about toplevel xids before subtransaction/savepoint xids. Which is enforced in the WAL logging code, so that's ok. But the problem is that right now the WAL produced looks like (abbreviated): rmgr: Heap tx: 585, lsn: 0/01A304A8, desc: LOCK off 1: xid 585 LOCK_ONLY EXCL_LOCK KEYS_UPDATED , blkref #0: rel 1663/12385/24607 blk 0 rmgr: Heap tx: 586, lsn: 0/01A30658, desc: INSERT off 2, blkref #0: rel 1663/12385/24607 blk 0 FPW rmgr: Transaction tx: 586, lsn: 0/01A30798, desc: ABORT 2016-02-07 12:21:18.624045 CET rmgr: Standby tx: 0, lsn: 0/01A307C0, desc: RUNNING_XACTS nextXid 587 latestCompletedXid 586 oldestRunningXid 585; 1 xacts: 585 rmgr: Heap tx: 587, lsn: 0/01A307F8, desc: INSERT off 3, blkref #0: rel 1663/12385/24607 blk 0 rmgr: Btree tx: 587, lsn: 0/01A30838, desc: INSERT_LEAF off 3, blkref #0: rel 1663/12385/24614 blk 1 rmgr: Transaction tx: 585, lsn: 0/01A30878, desc: COMMIT 2016-02-07 12:21:28.062978 CET; subxacts: 587 and decode.c doesn't care about LOCK records so far. Which means reorderbuffer.c doesn't know about the relevant xid. Hm. Greetings, Andres Freund -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs