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 1fJ2kt-00056B-Sc for pgsql-general@arkaria.postgresql.org; Wed, 16 May 2018 20:10:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fJ2ks-0007om-95 for pgsql-general@arkaria.postgresql.org; Wed, 16 May 2018 20:10:34 +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 1fJ2kr-0007od-V9 for pgsql-general@lists.postgresql.org; Wed, 16 May 2018 20:10:34 +0000 Received: from mail-qk0-x22f.google.com ([2607:f8b0:400d:c09::22f]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fJ2kp-0001uW-1e for pgsql-general@lists.postgresql.org; Wed, 16 May 2018 20:10:33 +0000 Received: by mail-qk0-x22f.google.com with SMTP id c137-v6so1768111qkg.2 for ; Wed, 16 May 2018 13:10:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=nFs75aIfUSP7hPKQ//rHun0BXBBAiGGK+2gaft0sS8o=; b=tMme6arwh9Erj/Le9hKpCm88hAsGqfgeQUVL7iwtyf7J3hoiyZgO3QhJfTw11uItdc xJZboI9RmMfMxoVGdQT5WOuFiqrbB23dSnILFz7lhUusIbZ0zwyaBVsie4T4BfhlwomO 6acW1fvq44qp9bddaycED/HX70+/e6yK0ZLKMevN5xKCfXZl+VTiNeSF86VQGzKCUKrP IMXx92tFZJo2nsAGalpXVzsFFX23Kvxj7Nsou5EgCCyxjt6LSgHOwoqoVzdrxvx42VVT +rsTRqVcRPlpLVqrf/a9dbs/XDBpJPe4skMcIVMoWXGL9cD/0gpe+D5DIYgyMKZPuaot IhbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=nFs75aIfUSP7hPKQ//rHun0BXBBAiGGK+2gaft0sS8o=; b=GkXbiEB5HzcP1HSXM7W/+QXzM8vb5ZVUXQfcz1+ga+iwwdEr4Z0/6a5JIUbSiBRgpX ibsXpuJSctM1QjXFuS228L6IKSCT5u9Xz9AmE71M/1adHrXxhRwusuXEEOLBB0gwY15O GpmYus+Ycc0Vk5E9QFYxqzYwxPtCRdH+nXi14Opfo0L2vaVEf8tPf5FgNyeC43AG7nOx vZBsVptpsoZCLoBnl9BTQs118chhZlt+FyXeMvbXLAVy5CaBnJ/abOwXk664Hr2bCOKK uoDPm5Q/Zsi0NGxnOduX9ePjfslw9NBYruYi7ilCOTiXxjxu7eoo1bv/jCfz+K6vXnVv r//g== X-Gm-Message-State: ALKqPwe3jQyebWoYDFtVH4bZLTryv8fHIO2agpmTS9S+XOUU74TVo4GM eO9a4EwREGTBc30++7glz7E9oSqd X-Google-Smtp-Source: AB8JxZr6KfTrJOMWIYbMEYJARoqSu6Ssu3XeSJcw6e8JxYERxuEPtgPKn9ns1PvKt8RWGEvBye1B6w== X-Received: by 2002:a37:4b03:: with SMTP id y3-v6mr2327298qka.98.1526501428825; Wed, 16 May 2018 13:10:28 -0700 (PDT) Received: from [192.168.212.192] (50-249-28-57-static.hfc.comcastbusiness.net. [50.249.28.57]) by smtp.gmail.com with ESMTPSA id u188-v6sm2449870qkd.45.2018.05.16.13.10.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 May 2018 13:10:28 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Re: Rapid disk usage spikes when updating large tables with GIN indexes From: Jonathan Marks In-Reply-To: <3F92DA72-F04E-4154-AB04-B2792DD904F1@gmail.com> Date: Wed, 16 May 2018 16:10:26 -0400 Cc: pgsql-general@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <6D9599DA-B74E-46DF-BA66-55A408A82E68@gmail.com> References: <26217.1526318186@sss.pgh.pa.us> <31807.1526324895@sss.pgh.pa.us> <3F92DA72-F04E-4154-AB04-B2792DD904F1@gmail.com> To: Tom Lane X-Mailer: Apple Mail (2.3445.5.20) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Tom =E2=80=94 We turned on log_temp_files and since the last stats reset (about a week = ago) we=E2=80=99re seeing 0 temp files altogether (grabbing that info = from pg_stat_database). So, as far as we know: 1) It=E2=80=99s not WAL 2) It=E2=80=99s not tempfiles 3) It=E2=80=99s not the size of the error logs 4) It=E2=80=99s not the size of the actual rows in the database or the = indexes Another thread we found suggested pg_subtrans =E2=80=94 this seems less = likely because we=E2=80=99ve been able to replicate this across many = different types of connections etc. but thought it might be a potential = source. Any other system-monitoring queries that we can run that might further = illuminate the issue? Thank you! > On May 14, 2018, at 3:31 PM, Jonathan Marks = wrote: >=20 > We=E2=80=99ll turn on log_temp_files and get back to you to see if = that=E2=80=99s the cause. Re: the exact queries =E2=80=94 these are just = normal INSERTs and UPDATEs. This occurs as part of normal database = operations =E2=80=94 i.e., we are processing 10% of a table and marking = changes to a particular row, or happen to be inserting 5-10% of the = table volume with new rows. Whenever we bulk load we have to drop the = indexes because the disk space loss just isn=E2=80=99t tenable. >=20 > Re: extra disk space consumption not within PG =E2=80=94 the AWS folks = can=E2=80=99t tell me what the problem is because it=E2=80=99s all = internal to the PG part of the instance they can=E2=80=99t access. = Doesn=E2=80=99t mean your last suggestion can=E2=80=99t be the case but = makes it slightly less likely. >=20 > Any chance that GIN indexes are double-logging? I.e. with fastupdate = off they are still trying to keep track of the changes in the pending = list or something? >=20 > Our thought has been temp files for a while, but we=E2=80=99re not = sure what we should do if that turns out to be the case. >=20 >> On May 14, 2018, at 3:08 PM, Tom Lane wrote: >>=20 >> [ please keep the list cc'd ] >>=20 >> 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 = something 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_target of 0.9 =E2=80=94 what does that suggest? >>=20 >> Hmph. Your WAL-size query seems on point, and that pretty much = destroys >> my idea about a WAL emission spike. >>=20 >> 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. >>=20 >> 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? >>=20 >> regards, tom lane >=20