Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gWRDp-000258-BE for pgsql-general@arkaria.postgresql.org; Mon, 10 Dec 2018 19:28:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gWRDo-00010x-1T for pgsql-general@arkaria.postgresql.org; Mon, 10 Dec 2018 19:28:04 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1gWRDn-00010p-Gr for pgsql-general@lists.postgresql.org; Mon, 10 Dec 2018 19:28:03 +0000 Received: from sonic317-27.consmr.mail.bf2.yahoo.com ([74.6.129.82]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gWRDk-00029D-Vn for pgsql-general@postgresql.org; Mon, 10 Dec 2018 19:28:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1544470078; bh=BAtxzKkG7Gabr5yNNzQhs4Rd/AT5J3+b/C/nx2VZ16w=; h=Date:From:To:Subject:References:From:Subject; b=lccpFii2wZg69WJsGPseahyd42+gVNUJ3GhpCWApZKuaxwgSAARxZNo5MYnVk6nCSKZLu4ECmOoWKR/Y+AiM7PGv6UcC9cIE04I4wRyHGGUHgQEuvvNhJfxUkCOGPC5GVStwzD+EY6uqFbtSWE+Vlt/otIo3/9AO4yId3Zs6b/20IaNoVcCPoT1siEUz01yucvIBii1w4SB6UElnqaV7iaTvV3a56v2VcKv8WDNynFb5IABq3xrdczzUNVO4yLh299nUPn0FU4Fb6TY2rM1DeYT1ov2DXyhFtO3vPzdaP5AV76VHXjqkUJ5iTOK48ExUiUCm+CM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RRyds- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.bf2.yahoo.com with HTTP; Mon, 10 Dec 2018 19:27:58 +0000 Date: Mon, 10 Dec 2018 19:26:36 +0000 (UTC) From: Thomas Carroll To: "pgsql-general@postgresql.org" Message-ID: <2114009259.1866365.1544469996900@mail.yahoo.com> Subject: Memory exhaustion due to temporary tables? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1866364_1681614854.1544469996899" References: <2114009259.1866365.1544469996900.ref@mail.yahoo.com> X-Mailer: WebService/1.1.12857 YMailNorrin Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0 Content-Length: 4782 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_1866364_1681614854.1544469996899 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable We have a situation where a long-persistent Postgres connection consumes mo= re and more memory.=C2=A0 If ignored, we eventually get =E2=80=9CCannot all= ocate memory=E2=80=9D errors in the Postgres log.=C2=A0 If still ignored, t= he box will eventually crash.=C2=A0 This takes about 3 weeks to happen.=C2= =A0 It issues a call to a single function about once every 15 seconds.=C2= =A0 What can I do to prevent this outcome? What the function does: The purpose of the function is to refresh a cache i= n an application, not make meaningful updates. It does write to the databas= e, but only a temporary table.=C2=A0 If I remove the temporary table (just = as an experiment, it makes the function useless) the memory consumption doe= s not occur. There are no transactions left hanging open, no locks holding resources fo= r long periods of time.=C2=A0 The temporary table is about half a meg in si= ze, about 5500 rows. The memory usage is identified by examining and totaling the lines beginnin= g with =E2=80=9CPrivate=E2=80=9D in the /proc/1234/smaps file, where 1234 i= s the process ID for the connection.=C2=A0 The memory consumption starts ou= t at under 20 meg, but swells to hundreds of megabytes over the three weeks= .=C2=A0 I have been able to reproduce the issue on my own Linux workstation= with an accelerated schedule. Other loads: None, this is a dedicated Postgres server Postgres version: 10.5.=C2=A0 work_mem setting: 4MB, shared_buffers setting= : 800 MB, connections typically around 30-40. Linux kernel version: 3.10 and CentOS 7.=C2=A0 Also kernel 4.19 and OpenSUS= E Tumbleweed when I recreate the issue on my workstation. Server: An AWS EC2 instance: t2.medium.=C2=A0 In other words, 2 CPUs, 4 GB = of memory.=C2=A0 Not big, but we do have a bunch of them. Workaround: We monitor the process and bounce it periodically.=C2=A0 I don'= t love this approach.=C2=A0 We could rewrite the function to avoid the temp= orary table.=C2=A0 It would be my shame as a DBA to ask a developer to do t= hat :). Thanks for any insight! Tom ------=_Part_1866364_1681614854.1544469996899 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
We have a situation where a long-persistent Postgres connection co= nsumes more and more memory.  If ignored, we eventually get =E2=80=9CC= annot allocate memory=E2=80=9D errors in the Postgres log.  If still i= gnored, the box will eventually crash.  This takes about 3 weeks to ha= ppen.  It issues a call to a single function about once every 15 secon= ds.  What can I do to prevent this outcome?

What the function d= oes: The purpose of the function is to refresh a cache in an application, n= ot make meaningful updates. It does write to the database, but only a tempo= rary table.  If I remove the temporary table (just as an experiment, i= t makes the function useless) the memory consumption does not occur.

There are no transactions= left hanging open, no locks holding=20 resources for long periods of time.  The temporary table is about half= a meg in size, about 5500 rows.

= The memory usage is identified by examining and totaling the lines beginnin= g with =E2=80=9CPrivate=E2=80=9D in the /proc/1234/smaps file, where 1234 i= s the process ID for the connection.  The memory consumption starts ou= t at under 20 meg, but swells to hundreds of megabytes over the three weeks= .  I have been able to reproduce the issue on my own Linux workstation= with an accelerated schedule.

Other loads: None, this is a dedicate= d Postgres server

Postgres version: 10.5.  work_mem setting: 4M= B, shared_buffers setting: 800 MB, connections typically around 30-40.
<= br>Linux kernel version: 3.10 and CentOS 7.  Also kernel 4.19 and Open= SUSE Tumbleweed when I recreate the issue on my workstation.

Server:= An AWS EC2 instance: t2.medium.  In other words, 2 CPUs, 4 GB of memo= ry.  Not big, but we do have a bunch of them.

Workaround: We mo= nitor the process and bounce it periodically.  I don't love this appro= ach.  We could rewrite the function to avoid the temporary table. = ; It would be my shame as a DBA to ask a developer to do that :).

Th= anks for any insight!

Tom
------=_Part_1866364_1681614854.1544469996899--