Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bCRov-0000IJ-T5 for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Jun 2016 13:22:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bCRov-0004ky-Aw for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Jun 2016 13:22:25 +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_2) (envelope-from ) id 1bCRou-0004kj-Mw for pgsql-bugs@postgresql.org; Mon, 13 Jun 2016 13:22:24 +0000 Received: from andy.depesz.com ([88.198.47.100] helo=depesz.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bCRoq-0006HU-6x for pgsql-bugs@postgresql.org; Mon, 13 Jun 2016 13:22:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20140207; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:Cc:To:Sender:From:Date:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=6FsULGYvbXaCmHhzDSUnzfKFOqhhboc/HsK3BbrFXvA=; b=n+G+h8E40h66draDVcedKlNePI wP9TprEcwDlyzzU3IZtIKqSu5vXjHwpo6syCW4FfFUqTC9WIqgcbyxreli88lQ3TmFa5Gg+vjJdKQ w0IkP2UB9UCn13uckooli9ZyP; Received: from andy.depesz.com ([88.198.47.100] helo=depesz.com) by depesz.com with esmtpa (Exim 4.87) (envelope-from ) id 1bCRon-0002Yq-8U; Mon, 13 Jun 2016 15:22:17 +0200 Date: Mon, 13 Jun 2016 15:22:17 +0200 From: hubert depesz lubaczewski To: Peter Eisentraut Cc: pgsql-bugs@postgresql.org Subject: Re: PostgreSQL (9.3 and 9.6) eats all memory when using many tables Message-ID: <20160613132216.GA31472@depesz.com> Reply-To: depesz@depesz.com References: <20160609154610.GA20600@depesz.com> <41f45186-64f6-8f9a-c72a-a3e9555d57b1@2ndquadrant.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <41f45186-64f6-8f9a-c72a-a3e9555d57b1@2ndquadrant.com> User-Agent: Mutt/1.6.0 (2016-04-01) X-Pg-Spam-Score: -3.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 On Mon, Jun 13, 2016 at 08:56:56AM -0400, Peter Eisentraut wrote: > On 6/9/16 11:46 AM, hubert depesz lubaczewski wrote: > > Basically it looks that postgresql "caches" query plans? parsed elements? for > > queries, but doesn't put any kind of limit to size of this cache. Which means > > that if our app is using LOTS of different queries, the memory usage will grow > > in time. > > If you compile with -DSHOW_MEMORY_STATS, it will print out memory allocation > after every command, so you might be able to see where the memory is going. Compiled, am running it now, but it is much slower now. And the output is huge. After ~5k queries, it looks like: TopMemoryContext: 5892000 total in 701 blocks; 18344 free (68 chunks); 5873656 used TableSpace cache: 8192 total in 1 blocks; 3216 free (0 chunks); 4976 used Operator lookup cache: 24576 total in 2 blocks; 11888 free (5 chunks); 12688 used MessageContext: 32768 total in 3 blocks; 6216 free (5 chunks); 26552 used Operator class cache: 8192 total in 1 blocks; 1680 free (0 chunks); 6512 used smgr relation table: 4186112 total in 9 blocks; 1374144 free (31 chunks); 2811968 used TransactionAbortContext: 32768 total in 1 blocks; 32736 free (0 chunks); 32 used Portal hash: 8192 total in 1 blocks; 1680 free (0 chunks); 6512 used PortalMemory: 8192 total in 1 blocks; 8160 free (1 chunks); 32 used Relcache by OID: 2088960 total in 8 blocks; 1008496 free (16 chunks); 1080464 used CacheMemoryContext: 182443144 total in 422 blocks; 2623776 free (1 chunks); 179819368 used MdSmgr: 1040384 total in 7 blocks; 192512 free (0 chunks); 847872 used ident parser context: 3072 total in 2 blocks; 1416 free (1 chunks); 1656 used hba parser context: 130048 total in 7 blocks; 42496 free (2 chunks); 87552 used LOCALLOCK hash: 24576 total in 2 blocks; 13920 free (4 chunks); 10656 used Timezones: 83472 total in 2 blocks; 3744 free (0 chunks); 79728 used ErrorContext: 8192 total in 1 blocks; 8160 free (6 chunks); 32 used I'll try to get to the end of the test (~70k tables), and then show the same info, plus some statistics about "CacheMemoryContext" if it helps (I'd rather not show *all* of it, though :) depesz -- The best thing about modern society is how easy it is to avoid contact with it. http://depesz.com/ -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs