Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bWLen-0002Cw-8c for pgsql-bugs@arkaria.postgresql.org; Sun, 07 Aug 2016 10:50:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bWLem-0006e0-R3 for pgsql-bugs@arkaria.postgresql.org; Sun, 07 Aug 2016 10:50:12 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bWLel-0006cd-3g for pgsql-bugs@postgresql.org; Sun, 07 Aug 2016 10:50:11 +0000 Received: from mail-lf0-x22b.google.com ([2a00:1450:4010:c07::22b]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bWLed-0005Ah-Jr for pgsql-bugs@postgresql.org; Sun, 07 Aug 2016 10:50:09 +0000 Received: by mail-lf0-x22b.google.com with SMTP id b199so230215302lfe.0 for ; Sun, 07 Aug 2016 03:50:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joh-to.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to; bh=yWnnAFay6P3IEoD2A37UZRh4053DlxawZiN3ulPowsA=; b=Tbur4Pzsm6L+I2AGFACT7VMYUZo/DPU2JzF2AAAUpjGIGl94XDjb0HGaWfFxNNonlN cghxuiG36chRJ66nJG1LMCoOZFQKCcF3spBfHjc3rwZXOweW/AwOzmAfpL32O/InidKE lCKhrkEyUbYV8hPFMwPSknnjT3YRMSEAxiM4VC5Mu6g+KAZFV4FFUl/9u5UWEoXz6JrD fOg8+npDS7Ox1pVHoNoIzL0Hws4aBv9zvTLFUBA7oRNM0MQc0MpDN+Y2D9NiSR8BMn1A IO4sHkySFtzwpQMUFnOF2aCbi0xd4cT6SUTynGjrMPjOBVK28ehqmqdHznH6d5Rpbm02 34mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to; bh=yWnnAFay6P3IEoD2A37UZRh4053DlxawZiN3ulPowsA=; b=EWGUl0w7ro6it9wQ+5yPRkYD1L6g4O8xRMsqWM3Z1zUUK4ZIr2VRVR+ASDoJVDXM9L oUDm/6X4klvNIAmi7ZaQF+uZhD+X2By/aDlTRQysz75+6vuveffEkvblpv/WDeNnf1fF mdNJUEAtglcNERz72N9Nbm6Cruh5UBYxX7wPqp4EbySIanWIoU6Ut8GsS135avSsRbMi dM0dwPK7KdyGNkEF348R0Vh9LupEmaOK/sPgGyb/LbX1vRA9i4XzfbYNqQJn0iQaQazv ZLHkDLZFGR9Tk54oeSoN2QTON/p2gGhMLrzrT9crcFAdHkyYCXnWacD80j+3+JWodT4w bEZA== X-Gm-Message-State: AEkoousFFqDE109U+IzfP1S0K/bMV6PXVKZYtRYxu3YEMqcXz9hZaTanO10019F9skiQnw== X-Received: by 10.46.1.222 with SMTP id f91mr25354620lji.1.1470567000899; Sun, 07 Aug 2016 03:50:00 -0700 (PDT) Received: from [172.20.10.3] (c-5eea23ce-74736162.cust.telenor.se. [94.234.35.206]) by smtp.googlemail.com with ESMTPSA id l129sm4523987lfl.37.2016.08.07.03.49.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Aug 2016 03:49:44 -0700 (PDT) Subject: Re: BUG #14279: Logical decoding misses a transaction completely To: Andrew Gierth References: <20160804191757.1430.39011@wrigleys.postgresql.org> <8760rgfhrr.fsf@news-spur.riddles.org.uk> Cc: pgsql-bugs@postgresql.org From: Marko Tiikkaja Message-ID: Date: Sun, 7 Aug 2016 12:49:44 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <8760rgfhrr.fsf@news-spur.riddles.org.uk> Content-Type: multipart/mixed; boundary="------------E4AD7631DF0E2496CBDB408F" X-Pg-Spam-Score: -2.6 (--) 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 This is a multi-part message in MIME format. --------------E4AD7631DF0E2496CBDB408F Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Ping. This is a very serious issue and it would be really good to include it in the minor releases. I've attached a patch for 9.5 with a test case and verified that it fixes the problem with our application. .m --------------E4AD7631DF0E2496CBDB408F Content-Type: text/x-patch; name="bug_14279.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="bug_14279.patch" *** a/contrib/test_decoding/expected/xact.out --- b/contrib/test_decoding/expected/xact.out *************** *** 6,14 **** SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_d init (1 row) - -- bug #13844, xids in non-decoded records need to be inspected CREATE TABLE xact_test(data text); INSERT INTO xact_test VALUES ('before-test'); BEGIN; -- perform operation in xact that creates and logs xid, but isn't decoded SELECT * FROM xact_test FOR UPDATE; --- 6,14 ---- init (1 row) CREATE TABLE xact_test(data text); INSERT INTO xact_test VALUES ('before-test'); + -- bug #13844, xids in non-decoded records need to be inspected BEGIN; -- perform operation in xact that creates and logs xid, but isn't decoded SELECT * FROM xact_test FOR UPDATE; *************** *** 33,38 **** SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'inc --- 33,60 ---- COMMIT (6 rows) + -- bug #14279 + BEGIN; + -- first insert + INSERT INTO xact_test VALUES ('main-txn'); + SAVEPOINT foo; + -- and then perform operation in subxact that creates and logs xid, but isn't decoded + SELECT 1 FROM xact_test FOR UPDATE LIMIT 1; + ?column? + ---------- + 1 + (1 row) + + COMMIT; + -- and now show those changes + SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); + data + ------------------------------------------------------- + BEGIN + table public.xact_test: INSERT: data[text]:'main-txn' + COMMIT + (3 rows) + DROP TABLE xact_test; SELECT pg_drop_replication_slot('regression_slot'); pg_drop_replication_slot *** a/contrib/test_decoding/sql/xact.sql --- b/contrib/test_decoding/sql/xact.sql *************** *** 3,12 **** SET synchronous_commit = on; SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); - -- bug #13844, xids in non-decoded records need to be inspected CREATE TABLE xact_test(data text); INSERT INTO xact_test VALUES ('before-test'); BEGIN; -- perform operation in xact that creates and logs xid, but isn't decoded SELECT * FROM xact_test FOR UPDATE; --- 3,12 ---- SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); CREATE TABLE xact_test(data text); INSERT INTO xact_test VALUES ('before-test'); + -- bug #13844, xids in non-decoded records need to be inspected BEGIN; -- perform operation in xact that creates and logs xid, but isn't decoded SELECT * FROM xact_test FOR UPDATE; *************** *** 17,22 **** COMMIT; --- 17,33 ---- -- and now show those changes SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); + -- bug #14279 + BEGIN; + -- first insert + INSERT INTO xact_test VALUES ('main-txn'); + SAVEPOINT foo; + -- and then perform operation in subxact that creates and logs xid, but isn't decoded + SELECT 1 FROM xact_test FOR UPDATE LIMIT 1; + COMMIT; + -- and now show those changes + SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); + DROP TABLE xact_test; SELECT pg_drop_replication_slot('regression_slot'); *** a/src/backend/replication/logical/reorderbuffer.c --- b/src/backend/replication/logical/reorderbuffer.c *************** *** 744,756 **** ReorderBufferCommitChild(ReorderBuffer *rb, TransactionId xid, elog(ERROR, "subxact logged without previous toplevel record"); /* ! * Pass the our base snapshot to the parent transaction if it doesn't have ! * one, or ours is older. That can happen if there are no changes in the * toplevel transaction but in one of the child transactions. This allows ! * the parent to simply use it's base snapshot initially. */ ! if (txn->base_snapshot == NULL || ! txn->base_snapshot_lsn > subtxn->base_snapshot_lsn) { txn->base_snapshot = subtxn->base_snapshot; txn->base_snapshot_lsn = subtxn->base_snapshot_lsn; --- 744,757 ---- elog(ERROR, "subxact logged without previous toplevel record"); /* ! * Pass our base snapshot to the parent transaction if it doesn't have one, ! * or ours is older. That can happen if there are no changes in the * toplevel transaction but in one of the child transactions. This allows ! * the parent to simply use its base snapshot initially. */ ! if (subtxn->base_snapshot != NULL && ! (txn->base_snapshot == NULL || ! txn->base_snapshot_lsn > subtxn->base_snapshot_lsn)) { txn->base_snapshot = subtxn->base_snapshot; txn->base_snapshot_lsn = subtxn->base_snapshot_lsn; --------------E4AD7631DF0E2496CBDB408F Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --------------E4AD7631DF0E2496CBDB408F--