Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 47DF81E94F73 for ; Wed, 25 Jul 2012 22:32:29 -0300 (ADT) Received: from mahout.postgresql.org ([98.129.198.123]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SuCwF-00019L-54 for pgsql-bugs@postgresql.org; Thu, 26 Jul 2012 01:32:27 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SuCw0-0007bD-Ne for pgsql-bugs@postgresql.org; Thu, 26 Jul 2012 01:32:14 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1SuCw0-0007s2-5D for pgsql-bugs@postgresql.org; Thu, 26 Jul 2012 01:32:12 +0000 Date: Thu, 26 Jul 2012 01:32:12 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6763: Severe memory leak with arrays and hstore To: pgsql-bugs@postgresql.org From: karavelov@mail.bg X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/203 X-Sequence-Number: 33679 The following bug has been logged on the website: Bug reference: 6763 Logged by: Luben Karavelov Email address: karavelov@mail.bg PostgreSQL version: 9.1.4 Operating system: Debian Linux Description: = I was trying to migrate a big ER table (user preferences) into a new table. Old able: old_prefs ( user_id integer NOT NULL, name varchar NOT NULL, value varchar NOT NULL ); New table: preferences ( user_id integer PRIMARY KEY, prefs hstore; ); The query I have tried to use is: INSERT INTO preferences = SELECT user_id,hstore(array_agg(name), array_agg(value)) = FROM old_prefs = GROUP BY user_id; But the postgres backend consumed all the available memory (6G free + 4G swap) and finally was killed by the kernel. Its 8G RAM machine and here are the memory options from the config: shared_buffers =3D 1800MB temp_buffers =3D 16MB work_mem =3D 64MB maintenance_work_mem =3D 256MB max_stack_depth =3D 2MB Finally I have managed to migrate it in batches of 100-200k user ids and disconnecting after each query in order to free the backend and leaked memory. Best regards Luben