pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Marlowe <scott.marlowe@gmail.com>
To: Alex Adriaanse <alex@innovacomputing.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Out of memory
Date: Fri, 28 Mar 2008 14:31:01 -0600
Message-ID: <dcc563d10803281331u2d31d35j3c944d2e98561c64@mail.gmail.com> (raw)
In-Reply-To: <47ED3B41.80305@innovacomputing.com>
References: <47ED3B41.80305@innovacomputing.com>

On Fri, Mar 28, 2008 at 12:38 PM, Alex Adriaanse
<alex@innovacomputing.com> wrote:
> I have a client that experienced several Out Of Memory errors a few
>  weeks ago (March 10 & 11), and I'd like to figure out the cause.  In the
>  logs it's showing that they were getting out of memory errors for about
>  0.5-1 hour, after which one of the processes would crash and take the
>  whole database down.  After they restarted the server it would
>  eventually start giving out of memory messages and crash again.  This
>  happened a total of five times over a 24 hour period.  After that we did
>  not see these errors again.  They did upgrade to 8.1.11 on the 14th, and
>  have also moved some of the databases to different servers afterwards.
>
>  First some background information:
>
>  Software (at the time of the memory errors): CentOS 4.5 (x86_64) running
>  its 2.6.9-55.ELsmp Linux kernel, PostgreSQL 8.1.9 (from RPMs provided on
>  the PostgreSQL web site: postgresql-8.1.9-1PGDG.x86_64).
>
>  Hardware: 4 dual-core Opterons.  16GB physical RAM, 2GB swap.
>
>  Database: they use persistent connections, and usually have around 1000
>  open database connections.  The vast majority of those are usually
>  idle.  They do run a lot of queries though.  The total size of the
>  databases in this cluster is 36GB, with the largest database being 21GB,
>  and the largest table being 2.5GB (having 20 million tuples).
>
>  Highlights of postgresql.conf settings:
>  max_connections = 2000
>  shared_buffers = 120000
>  work_mem = 4096

SNIP

Just because you can set max_connections to 2000 doesn't mean it's a
good idea.  If your client needs 1000 persistent connections, then put
a connection pooler between your app (I'm guessing php since it
operates this way) and the database.

Running 1000 connections is a LOT, and you need 1000 active
connections, then you're likely gonna need a bigger machine than one
with 8 cores and 16 gig of rams.  OTOH, if you are actively servicing
less than 10% of those connections at a time, then you're wasting
memory on the number of backends that are started up and doing
nothing.  each one consumes some amount of memory on its own, usually
in the 5 to 10 meg range, just to sit there and do nothing.

Plus you've got issues with thundering herd type situations that can
show up as you increase connections.

Pooling is the answer here.



view thread (58+ messages)  latest in thread

Message-ID: <dcc563d10803281331u2d31d35j3c944d2e98561c64@mail.gmail.com>
Permalink:  ../dcc563d10803281331u2d31d35j3c944d2e98561c64@mail.gmail.com/
Also on:    postgresql.org/message-id/dcc563d10803281331u2d31d35j3c944d2e98561c64@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: scott.marlowe@gmail.com, alex@innovacomputing.com
  Subject: Re: Out of memory
  In-Reply-To: <dcc563d10803281331u2d31d35j3c944d2e98561c64@mail.gmail.com>
  References: <47ED3B41.80305@innovacomputing.com> <dcc563d10803281331u2d31d35j3c944d2e98561c64@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox