Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eT6ZU-0006IR-8e for pgsql-hackers@arkaria.postgresql.org; Sun, 24 Dec 2017 13:44:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eT6ZR-00006P-Nq for pgsql-hackers@arkaria.postgresql.org; Sun, 24 Dec 2017 13:44:05 +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 1eT6ZR-00006F-6C for pgsql-hackers@lists.postgresql.org; Sun, 24 Dec 2017 13:44:05 +0000 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eT6ZJ-00052b-Bt for pgsql-hackers@postgresql.org; Sun, 24 Dec 2017 13:44:03 +0000 Received: by mail-wm0-x231.google.com with SMTP id t8so28973188wmc.3 for ; Sun, 24 Dec 2017 05:43:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=h3UtHrDcix/uz4BNqRckeizSawPhwHPNZ5e/u8mgUto=; b=2BFk0dteO71qFvvxXJCc1ibgt8p00pU3i0XIQPOyer0NfnrpL6YHTzLRnNKpNenns/ qFlyN4HHCnXZtxFdZnYWMYOrWo6CApmFj5vIiAuLOPUs5V+D33g5kLurMUZnKbmhgwRP FpB9ZFP4FIQ6PoTGW2/FmWGEsWIWqZN39rquzY1agTeCVqDG14vf6gM159z1+NKI7CEb wIcVi3tTSdnPN6BQm6dvkwPfNug9Ojfu171lp3KBTe1/Sa6i/Y1CGgxee0Eef2PrBesk XafDet18AF8GPtvAGVzBKXpjFqfQJmVLkvq3OqmFdKwkYH0ZbxXXqCsmMyOCxAinA2CI IwFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=h3UtHrDcix/uz4BNqRckeizSawPhwHPNZ5e/u8mgUto=; b=oyYrmx0txGoktUKXMrg95e8h4iF6fUYBgJmpOR2FPQa0wzBkihneRnIIixgqE0yzVr c4Ti4ralrSbgNtaVX2mDPMgPSZZKtjuD4WOn7RHywPgr7b0oCnWqOZYHFtOlJmQLFtlw MK+1o/lEKssB2rjskE87kxMTAg8Xq4UuyeSqYW8hfnRMhAvgKCPYtnt2ou6nB2LfaSgv BAMnzJeyz+BMus4Om+H3u18gWoaVLApBSQ18AKLpCYjDFbaRNaEe1KqXHVrl1fvTzvq0 hKxFZP9AsWRPNYmD0rsYKiJjGKDmazJvGTqa/Tso+btkLMBJQ11mxlkWtrsTvN4DBrez u0xA== X-Gm-Message-State: AKGB3mJzOyp3eAWufcQMhp+/rY6BOWTKhovn02xFEHYskHXuicdSFipD hPCkCF7NTsC7eDsTdhoRpXhUJW3T5EohGSWBepshfgVobjyV32cWrTQ7m/W0upzFZMXJrIk6Ut3 hlN0HyDg5Lq35HlIPr8CZx7TbJaRmx1ppMS+J5McQWPSopf0UZsD12yJrE6nE6xRydGwPk37IEe DTEk1UsARH X-Google-Smtp-Source: ACJfBouzOI6VwwxXl+8YxkBWB+pAtHBGtq5hUF3Pl0lq4ByK/3SSqVt1vIUZ8x/OOoXZ6y0oTy5cfA== X-Received: by 10.80.194.145 with SMTP id o17mr23019036edf.59.1514123033519; Sun, 24 Dec 2017 05:43:53 -0800 (PST) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id i6sm22022806eda.6.2017.12.24.05.43.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Dec 2017 05:43:52 -0800 (PST) Subject: Re: PATCH: logical_work_mem and logical streaming of large in-progress transactions To: Craig Ringer Cc: PostgreSQL Hackers References: <688b0b7f-2f6c-d827-c27b-216a8e3ea700@2ndquadrant.com> From: Tomas Vondra Message-ID: Date: Sun, 24 Dec 2017 14:43:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/24/2017 05:51 AM, Craig Ringer wrote: > On 23 December 2017 at 12:57, Tomas Vondra > wrote: > > Hi all, > > Attached is a patch series that implements two features to the logical > replication - ability to define a memory limit for the reorderbuffer > (responsible for building the decoded transactions), and ability to > stream large in-progress transactions (exceeding the memory limit). > > I'm submitting those two changes together, because one builds on the > other, and it's beneficial to discuss them together. > > > PART 1: adding logical_work_mem memory limit (0001) > --------------------------------------------------- > > Currently, limiting the amount of memory consumed by logical decoding is > tricky (or you might say impossible) for several reasons: > > * The value is hard-coded, so it's not quite possible to customize it. > > * The amount of decoded changes to keep in memory is restricted by > number of changes. It's not very unclear how this relates to memory > consumption, as the change size depends on table structure, etc. > > * The number is "per (sub)transaction", so a transaction with many > subtransactions may easily consume significant amount of memory without > actually hitting the limit. > > > Also, even without subtransactions, we assemble a ReorderBufferTXN > per transaction. Since transactions usually occur concurrently, > systems with many concurrent txns can face lots of memory use. > I don't see how that could be a problem, considering the number of toplevel transactions is rather limited (to max_connections or so). > We can't exclude tables that won't actually be replicated at the reorder > buffering phase either. So txns use memory whether or not they do > anything interesting as far as a given logical decoding session is > concerned. Even if we'll throw all the data away we must buffer and > assemble it first so we can make that decision. Yep. > Because logical decoding considers snapshots and cid increments even > from other DBs (at least when the txn makes catalog changes) the memory > use can get BIG too. I was recently working with a system that had > accumulated 2GB of snapshots ... on each slot. With 7 slots, one for > each DB. > > So there's lots of room for difficulty with unpredictable memory use. > Yep. > So the patch does two things. Firstly, it introduces logical_work_mem, a > GUC restricting memory consumed by all transactions currently kept in > the reorder buffer > > > Does this consider the (currently high, IIRC) overhead of tracking > serialized changes? >   Consider in what sense? regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services