Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fIIpe-0002qm-Bf for pgsql-general@arkaria.postgresql.org; Mon, 14 May 2018 19:08:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fIIpc-0008Hs-5t for pgsql-general@arkaria.postgresql.org; Mon, 14 May 2018 19:08:24 +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 1fIIpb-0008Hj-UJ for pgsql-general@lists.postgresql.org; Mon, 14 May 2018 19:08:23 +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 1fIIpY-0002nk-Rk for pgsql-general@lists.postgresql.org; Mon, 14 May 2018 19:08:23 +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 w4EJ8F2w031808; Mon, 14 May 2018 15:08:15 -0400 From: Tom Lane To: Jonathan Marks cc: pgsql-general@lists.postgresql.org Subject: Re: Rapid disk usage spikes when updating large tables with GIN indexes In-reply-to: References: <26217.1526318186@sss.pgh.pa.us> Comments: In-reply-to Jonathan Marks message dated "Mon, 14 May 2018 13:31:52 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <31806.1526324895.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 14 May 2018 15:08:15 -0400 Message-ID: <31807.1526324895@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk [ please keep the list cc'd ] Jonathan Marks writes: > Thanks for your quick reply. Here=E2=80=99s a bit more information: > 1) to measure the =E2=80=9Csize of the database=E2=80=9D we run somethin= g like `select datname, pg_size_pretty(pg_database_size(datname)) from pg_= database;` I=E2=80=99m not sure if this includes WAL size. > 2) I=E2=80=99ve tried measuring WAL size with `select sum(size) from pg_= ls_waldir();` =E2=80=94 this also doesn=E2=80=99t budge. > 3) Our current checkpoint_timeout is 600s with a checkpoint_completion_t= arget of 0.9 =E2=80=94 what does that suggest? Hmph. Your WAL-size query seems on point, and that pretty much destroys my idea about a WAL emission spike. pg_database_size() should include all regular and temporary tables/indexes in the named DB. It doesn't include WAL (but we've eliminated that), nor cluster-wide tables such as pg_database (but those seem pretty unlikely to be at issue), nor non-relation temporary files such as sort/hash temp space. At this point I think we have to focus our attention on what might be creating large temp files. I do not see anything in the GIN index code that could do that, especially not if you have fastupdate off. I wonder whether there is something about the particular bulk-insertion queries you're using that could result in large temp files --- which'd make the apparent correlation with GIN index use a mirage, but we're running out of other ideas. You could try enabling log_temp_files to see if there's anything to that. In the grasping-at-straws department: are you quite sure that the extra disk space consumption is PG's to begin with, rather than something outside the database entirely? regards, tom lane