Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yf7sv-0000uW-2v for pgsql-bugs@arkaria.postgresql.org; Mon, 06 Apr 2015 14:20:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Yf7su-0003ch-Gx for pgsql-bugs@arkaria.postgresql.org; Mon, 06 Apr 2015 14:20:16 +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 1Yf6FU-0004Fb-4x for pgsql-bugs@postgresql.org; Mon, 06 Apr 2015 12:35:28 +0000 Received: from mail-wg0-x236.google.com ([2a00:1450:400c:c00::236]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Yf6FP-0001VD-PQ for pgsql-bugs@postgresql.org; Mon, 06 Apr 2015 12:35:26 +0000 Received: by wgsk9 with SMTP id k9so3107571wgs.3 for ; Mon, 06 Apr 2015 05:35:22 -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=fOQ3/bi/umGhV31cyWMn9ISzTM2zBrF6KPrTqO/Ntn8=; b=GDBj7eV+1UXmnVz1Jw0Uze4WyzfzhaQ0ekxX0GSrKzmK3ao4JPGuO7NbME9OvqKWru catnudk0iKPcROYdGuClbS5a+DjqMtjnayliB0qKGjeH85qomDJunsE79vMUfc4pGOdG s3IP5xAKPEHOVdRigrRcLTmKq6QPSOvIyzh+RVG5D5hO7bX83X496qYtxLyyniyEayf8 CCHQzq0W4sMfAK2SdMKgIkoMT+XRHIXuqx1aFQoQ9NXe+FRHWVu6fEbq9cZwmGTYmLuN 1aB9OChWxWr5ajTzO04MZP/68iCqxqUUxD+vJFOOE2LncsgUZaXxUAvRbi5Pm3Ni7bbA eI8Q== X-Received: by 10.181.25.225 with SMTP id it1mr57730436wid.8.1428323722353; Mon, 06 Apr 2015 05:35:22 -0700 (PDT) Received: from [192.168.1.7] ([92.247.26.34]) by mx.google.com with ESMTPSA id vq9sm6329777wjc.6.2015.04.06.05.35.20 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Apr 2015 05:35:21 -0700 (PDT) Message-ID: <55227D87.9080007@gmail.com> Date: Mon, 06 Apr 2015 15:35:19 +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> In-Reply-To: <20150331144048.GL4878@alap3.anarazel.de> Content-Type: multipart/alternative; boundary="------------090005040207010609050007" 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. --------------090005040207010609050007 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Andres, I am writing again because I did some more testing to see what was the used resources. Now I am more sure that this is more a memory leak then anything else. I extended the swap and the disk space on the server that I was doing the testing. 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. After I start ti get the transactions changes one by one with select * from pg_logical_slot_get_changes('', null, 1), on one of this statements the process eats all the ram and some space on the disk and fails again. This is the eaten resources: - 18 GB RAM + swap - 0 free - 12 GB in base/pgsql_tmp in the data directory Again this is comparing with the 7.2 GB in the pg_xlog directory ... Maybe I am not understanding something, but is this normal? To my knowledge the data in pg_xlog is not compressed, so the size cannot just increase like this ? Best Regards, Peter Slavov/ / На 31.03.2015 в 17:40, Andres Freund написа: > Hi, > > On 2015-03-27 09:47:57 +0000, pet.slavov@gmail.com wrote: >> I am trying to use logical decoding to replay the data modifying queries on >> a different server, to synchronize some of the tables. The primary server >> has some load, but not so much. I am getting the changes with >> pg_logical_slot_get_changes limiting the changes to 50 at a time. > That's generally not a very good idea. It's much better to use the > streaming interface. Repeatedly starting/stopping a logical slot (as the > SQL interface has to do every time) isn't all that efficient. > >> At some point pg_logical_slot_get_changes queries become slow and starts to >> eat all the ram and swap, which eventually kills the primary database with >> this error: >> FATAL: the database system is in recovery mode. > That indicates a crash. Please check the server log for any details? If > it crashes, could you perhaps get a backtrace? > > What output plugin are you using? > >> The nature of changes on the primary can have a lot of data in one >> transaction. Which I guess is the reason of the slow >> pg_logical_slot_get_changes. > In that case changes should just be spooled to disk. > > Greetings, > > Andres Freund --------------090005040207010609050007 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Hi Andres,

I am writing again because I did some more testing to see what was the used resources.
Now I am more sure that this is more a memory leak then anything else.
I extended the swap and the disk space on the server that I was doing  the testing.
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.
After I start ti get the transactions changes one by one with select * from pg_logical_slot_get_changes('<slot name>', null, 1),
on one of this statements the process eats all the ram and some space on the disk and fails again.
This is the eaten resources:
 - 18 GB RAM + swap - 0 free
 - 12 GB in base/pgsql_tmp in the data directory
Again this is comparing with the 7.2 GB in the pg_xlog directory ...

Maybe I am not understanding something, but is this normal? To my knowledge the data in pg_xlog is not compressed,
so the size cannot just  increase like this ?

Best Regards,
Peter Slavov

На 31.03.2015 в 17:40, Andres Freund написа:
Hi,

On 2015-03-27 09:47:57 +0000, pet.slavov@gmail.com wrote:
I am trying to use logical decoding to replay the data modifying queries on
a different server, to synchronize some of the tables. The primary server
has some load, but not so much. I am getting the changes with
pg_logical_slot_get_changes limiting the changes to 50 at a time.
That's generally not a very good idea. It's much better to use the
streaming interface. Repeatedly starting/stopping a logical slot (as the
SQL interface has to do every time) isn't all that efficient.

At some point pg_logical_slot_get_changes queries become slow and starts to
eat all the ram and swap, which eventually kills the primary database with
this error:
 FATAL:  the database system is in recovery mode.
That indicates a crash. Please check the server log for any details?  If
it crashes, could you perhaps get a backtrace?

What output plugin are you using?

The nature of changes on the primary can have a lot of data in one
transaction. Which I guess is the reason of the slow
pg_logical_slot_get_changes. 
In that case changes should just be spooled to disk.

Greetings,

Andres Freund

--------------090005040207010609050007--