Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bCOKy-0004qO-B0 for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Jun 2016 09:39:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bCOKx-0005dk-4D for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Jun 2016 09:39:15 +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 1bCOKw-0005dQ-B2 for pgsql-bugs@postgresql.org; Mon, 13 Jun 2016 09:39:14 +0000 Received: from andy.depesz.com ([88.198.47.100] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bCOKt-0004yX-2f for pgsql-bugs@postgresql.org; Mon, 13 Jun 2016 09:39:12 +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=Nl31jkQ9jT1MIe8mSYTQmeZ1s5CK5zc7qom5AZTLgFs=; b=SIl9Fd7g5RBblP0HFM1ncCgpI/ O0wqnuUF2jut9q1piL1YUHq0fiUiySb1e5jHDcWjVD6/Gj3Jx427lxlci7x+9z/PMZ1nz7y38K1Gj BLH8OwSJwgL3EYT4kLILhbszg; Received: from andy.depesz.com ([88.198.47.100] helo=depesz.com) by depesz.com with esmtpa (Exim 4.87) (envelope-from ) id 1bCOKp-0003Lu-Rv; Mon, 13 Jun 2016 11:39:07 +0200 Date: Mon, 13 Jun 2016 11:39:07 +0200 From: hubert depesz lubaczewski To: Jeff Janes Cc: Pg Bugs Subject: Re: PostgreSQL (9.3 and 9.6) eats all memory when using many tables Message-ID: <20160613093907.GA10381@depesz.com> Reply-To: depesz@depesz.com References: <20160609154610.GA20600@depesz.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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 Sun, Jun 12, 2016 at 01:50:48PM -0700, Jeff Janes wrote: > You should probably use pgbouncer's server_lifetime to force > connections to be discarded and recreated every now and then. That > parameter seems to exist specifically for dealing with this kind of > problem. While I know I can deal with it with server_lifetime, I still think it's a problem in Pg - the amount of memory used for this cache should be limitable/configurable. > Is all of that necessary? Can't you reproduce the problem just as > well with just "select count(*) from ;" ? No. I'd rather not count(*) as some of these tables are large'ish, but I did: select * from table limit 1 And the results are: 1 | =$ ./bad.pl 2 | 109 24536 0.0 0.0 6821072 6312 ? Ss 09:32 0:00 postgres: depesz-rw dbname 127.0.0.1(45788) idle 3 | 74002 tables; press enter to continue: 4 | 5 | 1000: (87524 kB anon) 109 24536 65.5 0.8 6905176 530844 ? Ss 09:32 0:01 postgres: depesz-rw dbname 127.0.0.1(45788) idle 6 | 2000: (115648 kB anon) 109 24536 90.0 1.0 6937684 667540 ? Ss 09:32 0:01 postgres: depesz-rw dbname 127.0.0.1(45788) idle 7 | 3000: (143460 kB anon) 109 24536 77.3 1.2 6962660 794880 ? Ss 09:32 0:02 postgres: depesz-rw dbname 127.0.0.1(45788) idle 8 | 4000: (170640 kB anon) 109 24536 94.3 1.4 6995196 905052 ? Ss 09:32 0:02 postgres: depesz-rw dbname 127.0.0.1(45788) idle 9 | 5000: (199388 kB anon) 109 24536 58.1 1.6 7020896 1028180 ? Ss 09:32 0:03 postgres: depesz-rw dbname 127.0.0.1(45788) idle 10 | 6000: (226852 kB anon) 109 24536 47.4 1.8 7045140 1159604 ? Ss 09:32 0:04 postgres: depesz-rw dbname 127.0.0.1(45788) idle 11 | 7000: (254836 kB anon) 109 24536 38.9 2.0 7076732 1300960 ? Ss 09:32 0:05 postgres: depesz-rw dbname 127.0.0.1(45788) idle 12 | 8000: (286072 kB anon) 109 24536 37.5 2.2 7103824 1435416 ? Ss 09:32 0:06 postgres: depesz-rw dbname 127.0.0.1(45788) idle 13 | 9000: (312956 kB anon) 109 24536 34.1 2.4 7139348 1545560 ? Ss 09:32 0:06 postgres: depesz-rw dbname 127.0.0.1(45788) idle 14 | 10000: (339100 kB anon) 109 24536 33.0 2.6 7162500 1646176 ? Ss 09:32 0:07 postgres: depesz-rw dbname 127.0.0.1(45788) idle 15 | 11000: (365104 kB anon) 109 24536 32.2 2.7 7185596 1742468 ? Ss 09:32 0:08 postgres: depesz-rw dbname 127.0.0.1(45788) idle 16 | 12000: (391628 kB anon) 109 24536 31.6 2.9 7218820 1838912 ? Ss 09:32 0:09 postgres: depesz-rw dbname 127.0.0.1(45788) idle 17 | 13000: (424096 kB anon) 109 24536 31.4 3.1 7251908 1959756 ? Ss 09:32 0:10 postgres: depesz-rw dbname 127.0.0.1(45788) idle 18 | 14000: (458424 kB anon) 109 24536 30.6 3.3 7277756 2083952 ? Ss 09:32 0:11 postgres: depesz-rw dbname 127.0.0.1(45788) idle Line #2 shows output of ps nh uww -p before start of work. There are, in total, 74002 tables, and then I iterate over list of them, and for each, I do the select I mentioned. Every 1000 tables, I get stats - ps output, and (in parent) sum of "Anonymous:" lines from /proc//smaps. As you can see - we're getting ~ 32kB of cache per table. While I do appreciate caching of metadata, it is causing serious problems, which we will alleviate with server_lifetime, but I would much prefer a setting like: internal_cache_limit = 256MB or something similar. Best regards, depesz -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs