Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f48fQ-0006M1-NE for pgsql-general@arkaria.postgresql.org; Thu, 05 Apr 2018 17:27:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f48fO-0004jf-Pz for pgsql-general@arkaria.postgresql.org; Thu, 05 Apr 2018 17:27:18 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1f48fO-0004in-Ha for pgsql-general@lists.postgresql.org; Thu, 05 Apr 2018 17:27:18 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f48fH-00041C-59 for pgsql-general@postgresql.org; Thu, 05 Apr 2018 17:27:17 +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 w35HR7L3014879; Thu, 5 Apr 2018 13:27:07 -0400 From: Tom Lane To: Jorge Daniel cc: "pgsql-general@postgresql.org" Subject: Re: Docker + postgreSQL : OOM killing in a large Group by operation In-reply-to: References: Comments: In-reply-to Jorge Daniel message dated "Thu, 05 Apr 2018 17:02:18 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14877.1522949227.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 05 Apr 2018 13:27:07 -0400 Message-ID: <14878.1522949227@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jorge Daniel writes: > I have a problem with a query that grabs a bunch of rows and then does a= n aggreate operation, at that moment it gots killed by OOM-killer, I don't= know why, the engine starts using tmpfiles as expected , and then tries = to work in memory and gots killed. > SELECT count(*) > FROM "changelog_change_transaction" > INNER JOIN "changelog_change_stats" ON ( changelog_change_stats.cha= ngelog_change_transactionid =3D changelog_change_transaction.changelog_cha= nge_transactionid ) > LEFT OUTER JOIN "changelog_change_group" ON ( changelog_change_tran= saction.changelog_change_groupid =3D changelog_change_group.changelog_chan= ge_groupid ) > WHERE ( changelog_change_group.companyid =3D 40 OR changelog_change_= group.companyid =3D 1 OR changelog_change_group.companyid =3D 53 OR change= log_change_group.companyid IS NULL ) > AND changelog_change_transaction.started_at > '2017-04-21' > GROUP BY "changelog_change_transaction"."changelog_change_transactionid= ", "changelog_change_transaction"."epoch", "changelog_change_transaction" > ."changelog_change_groupid", "changelog_change_transaction"."started_at"= , "changelog_change_transaction"."duration_microseconds", "changelog_chang= e_transaction"."changed_items", "changelog_change_transaction"."xmin" > ; Why are you grouping on xmin? > For sure if the GROUP BY the one that causes this OOM (when I removed it= , the query finish ok ) , so I've change the query-plan to avoid the HashA= ggregate: > But the explain still shows: That's because type XID doesn't have sort support, only hash support, so hash aggregation is the only way to do the query at all. regards, tom lane