pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: PostgreSQL processes use large amount of private memory on Windows
Date: Thu, 17 Sep 2020 19:26:59 +0200
Message-ID: <20200917172659.GA417@hjp.at> (raw)
In-Reply-To: <CAH_oh=wk5i36whfUKhPvnTfR6KsU_CzRTXecNaAtY86HWb57YQ@mail.gmail.com>
References: <CAH_oh=wk5i36whfUKhPvnTfR6KsU_CzRTXecNaAtY86HWb57YQ@mail.gmail.com>

On 2020-09-17 11:19:07 +0200, Øystein Kolsrud wrote:
> I have a product that uses PostgreSQL (v9.6) as database on Windows, and we
> often observe that the "shared working set" memory reported for the individual
> connection processes is quite high (around 200MB), but the "private working
> set" is relatively low (around 5 MB). I assume this is due to the processes
> utilizing the shared buffers of Postgres, and in these cases everything works
> fine as the total memory consumption on the system is quite low. But for some
> deployments we have observed that the "private working set" is around 200 MB as
> well, and in these cases the server quickly runs out of memory when the number
> of connections rises. I have never been able to reproduce this behavior myself.
[...]
> All settings typically referred to (like "work_mem" and "temp_buffers") are at
> default settings, and I have a very hard time seeing how those settings could
> add up to memory in the magnitude of 200MB.

The work_mem setting is per operation (e.g. sort, hash join, etc.), so a
complex query may use a multiple of it. However, the default is just 4 MB,
so a query would have to be very complex to use 50 times as much. Also,
that memory is freed after the query (however "freed" does not
necessarily mean "returned to the OS", it can just mean "marked as
availiable for reuse" - that depends on the C library and the OS).

What I would do:

* Set log_statement to all (warning: that can be a lot of log messages.
  It can also be a privacy/security hazard, depending on who has access
  to the server and how sensitive queries are).
* Frequently (at least once per minute) record the size of all postgres
  processes. Send an alert if one of them is "too large".

This should give you a good idea what the processes were doing at the
time they allocated that memory, so that you can reproduce the problem.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (7+ messages)  latest in thread

Message-ID: <20200917172659.GA417@hjp.at>
Permalink:  ../20200917172659.GA417@hjp.at/
Also on:    postgresql.org/message-id/20200917172659.GA417@hjp.at

 · 

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: hjp-pgsql@hjp.at
  Subject: Re: PostgreSQL processes use large amount of private memory on Windows
  In-Reply-To: <20200917172659.GA417@hjp.at>
  References: <CAH_oh=wk5i36whfUKhPvnTfR6KsU_CzRTXecNaAtY86HWb57YQ@mail.gmail.com> <20200917172659.GA417@hjp.at>

* 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