Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLeCH-0006tx-Vc for pgsql-general@arkaria.postgresql.org; Mon, 04 Dec 2017 00:01:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLeCH-0001V1-JB for pgsql-general@arkaria.postgresql.org; Mon, 04 Dec 2017 00:01:21 +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 1eLeCH-0001Us-8z for pgsql-general@lists.postgresql.org; Mon, 04 Dec 2017 00:01:21 +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.89) (envelope-from ) id 1eLeCE-0003ta-P7 for pgsql-general@lists.postgresql.org; Mon, 04 Dec 2017 00:01:20 +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 vB4019q0014019; Sun, 3 Dec 2017 19:01:09 -0500 From: Tom Lane To: Yuri Budilov cc: John R Pierce , "pgsql-general@lists.postgresql.org" Subject: Re: JSON out of memory error on PostgreSQL 9.6.x In-reply-to: References: <81363279.2185591.1511207314550.ref@mail.yahoo.com> <81363279.2185591.1511207314550@mail.yahoo.com> <6207.1511235609@sss.pgh.pa.us>, Comments: In-reply-to Yuri Budilov message dated "Sun, 03 Dec 2017 23:18:50 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14017.1512345669.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 03 Dec 2017 19:01:09 -0500 Message-ID: <14018.1512345669@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Yuri Budilov writes: > Posted on Stack Overflow, sadly no replies, so trying here.... > CREATE TABLE X AS > SELECT json_array_elements(json_rmq -> 'orders'::text) AS order > FROM table_name > WHERE blah; > I get out of memory error. > The JSON column is about ~5 MB and it has about ~150,000 array row eleme= nts in 'orders' above. I tried to reproduce that, and couldn't, given the available info. I made a JSON value of more or less that size with perl -e 'print "{\"orders\": [0"; for($i=3D1;$i<=3D150000;$i++){print ",$i= "}; print "]}\n";' >jsonval and then did regression=3D# create table table_name(json_rmq json); CREATE TABLE regression=3D# \copy table_name from jsonval COPY 1 regression=3D# insert into table_name select * from table_name; INSERT 0 1 regression=3D# insert into table_name select * from table_name; INSERT 0 2 regression=3D# insert into table_name select * from table_name; INSERT 0 4 regression=3D# insert into table_name select * from table_name; INSERT 0 8 regression=3D# insert into table_name select * from table_name; INSERT 0 16 regression=3D# insert into table_name select * from table_name; INSERT 0 32 regression=3D# insert into table_name select * from table_name; INSERT 0 64 regression=3D# insert into table_name select * from table_name; INSERT 0 128 regression=3D# CREATE TABLE X AS SELECT json_array_elements(json_rmq -> 'orders'::text) AS order FROM table_name; SELECT 38400256 Watching the process with "top", its memory consumption stayed rock-steady. If there's a leak in there, this example doesn't show it. There could be a leak related to some detail you failed to mention, but ... regards, tom lane