Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Z9xbD-0007LH-I6 for pgsql-performance@arkaria.postgresql.org; Tue, 30 Jun 2015 15:37:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Z9xbC-0001jO-HX for pgsql-performance@arkaria.postgresql.org; Tue, 30 Jun 2015 15:37:26 +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) (envelope-from ) id 1Z9xbB-0001jH-9d for pgsql-performance@postgresql.org; Tue, 30 Jun 2015 15:37:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Z9xb9-0002kS-0M for pgsql-performance@postgresql.org; Tue, 30 Jun 2015 15:37:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t5UFbKCe028250; Tue, 30 Jun 2015 11:37:20 -0400 From: Tom Lane To: eudald_v cc: pgsql-performance@postgresql.org Subject: Re: Sudden connection and load average spikes with postgresql 9.3 In-reply-to: <1435675936590-5855895.post@n5.nabble.com> References: <1435675936590-5855895.post@n5.nabble.com> Comments: In-reply-to eudald_v message dated "Tue, 30 Jun 2015 07:52:16 -0700" Date: Tue, 30 Jun 2015 11:37:20 -0400 Message-ID: <28249.1435678640@sss.pgh.pa.us> X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org eudald_v writes: > This is my very first message to the Postgresql community, and I really hope > you can help me solve the trouble I'm facing. > I've an 80 core server (multithread) with close to 500GB RAM. > My configuration is: > MaxConn: 1500 (was 850) > Shared buffers: 188Gb > work_mem: 110Mb (was 220Mb) > maintenance_work_mem: 256Mb > effective_cache_size: 340Gb > The database is running under postgresql 9.3.9 on an Ubuntu Server 14.04 LTS > (build 3.13.0-55-generic) > Two days from now, I've been experiencing that, randomly, the connections > rise up till they reach max connections, and the load average of the server > goes arround 300~400, making every command issued on the server take > forever. When this happens, ram is relatively low (70Gb used), cores > activity is lower than usual and sometimes swap happens (I've swappiness > configured to 10%) You haven't described why you would suddenly be getting more connections, but if that's just an expected byproduct of transactions taking too long to finish, then a plausible theory is that something is acquiring a strong lock on some heavily-used table, causing other transactions to back up behind it. The pg_stat_activity and pg_locks views may help identify the culprit. In any case, a good mitigation plan would be to back off your max_connections setting, and instead use a connection pooler to manage large numbers of clients. The usual rule of thumb is that you don't want number of backends much more than the number of cores. 1500 active sessions is WAY more than your hardware can support, and even approaching that will exacerbate whatever the root performance problem is. I'm also a bit worried by your focus on CPU capacity without any mention of the disk subsystem. It may well be that the actual bottleneck is disk throughput, and that you can't even sustain 80 sessions unless they're read-mostly. It would be a good idea to watch the i/o stats the next time you see one of these high-load episodes. It might also be a good idea to decrease the shared_buffers setting and rely more on OS-level disk caching. Some have found that very large shared buffer pools tend to increase contention without much payback. regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance