Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YgFHL-0004RG-C3 for pgsql-bugs@arkaria.postgresql.org; Thu, 09 Apr 2015 16:26:07 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YgFHK-0005mc-Nz for pgsql-bugs@arkaria.postgresql.org; Thu, 09 Apr 2015 16:26:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YgE7E-0005QA-MC for pgsql-bugs@postgresql.org; Thu, 09 Apr 2015 15:11:36 +0000 Received: from mail-wi0-x231.google.com ([2a00:1450:400c:c05::231]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YgE79-0002Py-8X for pgsql-bugs@postgresql.org; Thu, 09 Apr 2015 15:11:35 +0000 Received: by wiun10 with SMTP id n10so102013171wiu.1 for ; Thu, 09 Apr 2015 08:11:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:organization:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type; bh=Y9BE8xA2AaRNTnQZYDx+BLgIRg5IiyCbazobyzVheLs=; b=Ed9iZ4OPpkCoc5HnRa3i1dKGacB7eq2YbZfSgMfBIA7REjdJJGaWn+8SWZwRCq6Ekb U6RNsBcWuQn53tMBwf6zmzWD/TSc6HZcwpIHeNaEEgU4uBQ/NJmXONTtP4zOtHqe7+ky vM0xQwuXYcFGNtJHWlTbSol5RZaU9WL4f7O4gnbLnI+jDa6b8MTjlrJS5V1hZCJq6vJh JblVvhCrdrJhXW1oAfFNegrvETNtdh7YIibOLCBxO+Ci2PzTeXWd7W0kg44iDZU4A/4Q Ac94qpWS+pfsCq/loR587uJkNvZ8QQK42AZS+qD4y3K+HJP5tk79VmXK6Sc8lI9Rt2Jq x5pA== X-Received: by 10.194.222.197 with SMTP id qo5mr60337504wjc.142.1428592289684; Thu, 09 Apr 2015 08:11:29 -0700 (PDT) Received: from [192.168.1.7] ([92.247.26.34]) by mx.google.com with ESMTPSA id pa4sm20519970wjb.11.2015.04.09.08.11.28 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2015 08:11:28 -0700 (PDT) Message-ID: <5526969F.4050704@gmail.com> Date: Thu, 09 Apr 2015 18:11:27 +0300 From: Peter Slavov Organization: sumup User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:36.0) Gecko/20100101 Icedove/36.0 MIME-Version: 1.0 To: Andres Freund CC: pgsql-bugs@postgresql.org Subject: Re: BUG #12910: Memory leak with logical decoding References: <20150327094757.2488.58808@wrigleys.postgresql.org> <20150331144048.GL4878@alap3.anarazel.de> <55227D87.9080007@gmail.com> <20150406135026.GJ17586@awork2.anarazel.de> In-Reply-To: <20150406135026.GJ17586@awork2.anarazel.de> Content-Type: multipart/alternative; boundary="------------030001020208070301090309" X-Pg-Spam-Score: -2.7 (--) 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. --------------030001020208070301090309 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Andres, I prepared a test case, that can reproduce the problem. This is the link to the SQL File . I am just creating few tables and filling then with data then deleting and then filling again; This will produce tables with size ~1.5 GB 2 times and delete them ones. This queries in the logical decoding of course will be one row for each inserted and deleted row. Which will produce ~ 15GB of data for one transactions. I get the data from terminal like thins: psql test_case -c "select * from pg_logical_slot_get_changes('testing', null, 1);" 1>//tmp/replay.sql You can see that when the big transaction is red from the WAL files all this 15GB is going to the RAM and swap space. Eventually if you get enough RAM and swap the data will be compiled and after that written to the file. I know that this setup is not optimal, but it can reproduce the big memory usage. Greetings, Peter Slavov На 6.04.2015 в 16:50, Andres Freund написа: > Hi, > > I'm on holidays right now, so my answers will be delayed. > > On 2015-04-06 15:35:19 +0300, Peter Slavov wrote: >> Before I start I can see that the pg_xlog directory is 7.2 GB size. >> This give me some idea that the size of the changes cannot be much bigger >> than that. > There's no such easy correlation. That said, there pretty much never > should be a case where so much memory is needed. > >> After I start ti get the transactions changes one by one with select * from >> pg_logical_slot_get_changes('', null, 1), > As I said before, it's *not* a good idea to consume transactions > one-by-one. The startup of the decoding machinery is quite expensive. If > you want more control about how much data you get you should use the > streaming interface. > >> Maybe I am not understanding something, but is this normal? > It's definitely not normal. It's unfortunately also hard to diagnose > based on the information so far. Any chance you can build a reproducible > test case? > > Greetings, > > Andres Freund --------------030001020208070301090309 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Hi Andres,

I prepared a test case, that can reproduce the problem.
This is the link to the SQL File .
I am just creating few tables and filling then with data then deleting and then filling again;
This will produce tables with size ~1.5 GB 2 times and delete them ones. This queries in the logical decoding
of course will be one row for each inserted and deleted row. Which will produce ~ 15GB of data for one transactions.
I get the data from terminal like thins:
 
       psql test_case -c "select * from pg_logical_slot_get_changes('testing', null, 1);" 1>//tmp/replay.sql

You can see that when the big transaction is red from the WAL files all this 15GB is going to the RAM and swap space.
Eventually if you get enough RAM and swap the data will be compiled and after that written to the file.

I know that this setup is not optimal, but it can reproduce the big memory usage.

Greetings,
Peter Slavov

На 6.04.2015 в 16:50, Andres Freund написа:
Hi,

I'm on holidays right now, so my answers will be delayed.

On 2015-04-06 15:35:19 +0300, Peter Slavov wrote:
Before I start I can see that the pg_xlog directory is 7.2 GB size.
This give me some idea that  the size of the changes cannot be much bigger
than that.
There's no such easy correlation. That said, there pretty much never
should be a case where so much memory is needed.

After I start ti get the transactions changes one by one with select * from
pg_logical_slot_get_changes('<slot name>', null, 1),
As I said before, it's *not* a good idea to consume transactions
one-by-one. The startup of the decoding machinery is quite expensive. If
you want more control about how much data you get you should use the
streaming interface.

Maybe I am not understanding something, but is this normal?
It's definitely not normal. It's unfortunately also hard to diagnose
based on the information so far. Any chance you can build a reproducible
test case?

Greetings,

Andres Freund

--------------030001020208070301090309--