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 1fKufL-0000Xz-2Q for pgsql-general@arkaria.postgresql.org; Mon, 21 May 2018 23:56:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fKufJ-0005zX-55 for pgsql-general@arkaria.postgresql.org; Mon, 21 May 2018 23:56:33 +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 1fKufI-0005zO-OK for pgsql-general@lists.postgresql.org; Mon, 21 May 2018 23:56:32 +0000 Received: from mail-qt0-x244.google.com ([2607:f8b0:400d:c0d::244]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fKufA-0005qo-TY for pgsql-general@lists.postgresql.org; Mon, 21 May 2018 23:56:31 +0000 Received: by mail-qt0-x244.google.com with SMTP id e8-v6so21227979qth.0 for ; Mon, 21 May 2018 16:56:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=hQzTazbEnznhyYTgkSnhz0I/7uaq6vvguaE8R6bs6Is=; b=UXu9Jgdp6pZB5+hYdd26rg9RZTRXgwqwgOTH8I10VuR6QRc001w/xjqC+iaFwITDWb cVxYPfW32lsTyO82QaVFSWzgOhbGGXA38TVTO2DpkhXyJB7wSkMaPlxKvaEZ0KpdnV+t O5oGx/tB3D1pt3R1432kbkofBdMEA3g1O0y0+rAaaW7ALfuPKas8r1HFBIdP28QfgSbS KZCj9LoKoaZkn5kxE6Yms7+iUzXdRMfgztfTtiFwpBxPBL5MBvRaZHN0kIfvDMkGVteO 3I7MZHQ0bZgKVCeggwoCl58jD+VelPA2p4HzH3TuEYDukLCHv/j2mALOVkz5UOYqYK13 ERLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=hQzTazbEnznhyYTgkSnhz0I/7uaq6vvguaE8R6bs6Is=; b=p31qlOdD9enq+wGe5jYDJ1ZWj6LAcwoMLAM854vSlCay2bPFI8NqqpUxLBR+6ERgvq mm3oNARZa5nOkKNw+yzl6FU08C97sV99aqgjYCXEQjYZZhoAyhop8kLyZWy/qKWzi1SR vkMvjDTsLCcNN+IrbM6W1qydozbrJr5SwRyRcXEGqhO5Zmm1faAXSIY02D4Ds0GKEFAN vhHXUrZhSCWvG7nyllv8LFO+JneiBM1PyDDUTZz2c5PIuTwTM418FEW0A80TG9WXxAdm XOfgm3jJ7fzm31BOEp4bJRkh3gt0OWBfTLoAmQUQf8ndU8OaNAp3dJ9cGbhpJZ8rA31K s2dw== X-Gm-Message-State: ALKqPwdVfmH7oqgop21ASLvMl9Fgl6KyEF5Y1k+yTHM8cSyvrCKRPsl0 CjK5BeSa/ezXefgfa0/6F14= X-Google-Smtp-Source: AB8JxZquDeTBkMRUCEIojhF5cXtLMgO8ziD8g1amzGBiSFdQoHh0bGFqWDbS20p4i0FQhPmgamzuzg== X-Received: by 2002:ac8:2e04:: with SMTP id r4-v6mr20249223qta.266.1526946982889; Mon, 21 May 2018 16:56:22 -0700 (PDT) Received: from [10.35.196.74] (mr-118181ab.lnh.md.smb.rcn.net. [66.44.95.66]) by smtp.gmail.com with ESMTPSA id o84-v6sm12181200qkh.15.2018.05.21.16.56.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 May 2018 16:56:22 -0700 (PDT) From: Jonathan Marks Message-Id: <086267F7-EDBC-4B1A-9C73-2CDC07C27691@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_FD20CC1E-6A6F-49B6-A445-8F619FCF7C7F" 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 Date: Mon, 21 May 2018 19:41:33 -0400 In-Reply-To: Cc: Tom Lane , pgsql-general@lists.postgresql.org To: Nikolay Samokhvalov References: <26217.1526318186@sss.pgh.pa.us> <31807.1526324895@sss.pgh.pa.us> <3F92DA72-F04E-4154-AB04-B2792DD904F1@gmail.com> <6D9599DA-B74E-46DF-BA66-55A408A82E68@gmail.com> X-Mailer: Apple Mail (2.3445.5.20) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_FD20CC1E-6A6F-49B6-A445-8F619FCF7C7F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 I believe that we have figured it out. It indeed was a WAL issue =E2=80=94= the WAL wasn=E2=80=99t getting measured because it had been moved into = an archived folder. We resolved this in a two main ways: 1. By dramatically increasing max_wal_size to decrease the frequency of = commits 2. By turning on wal_compression We=E2=80=99re going to continue looking into whether we can reduce wal = generation / write volume further by turning back on fast_update on our = GIN indexes. > On May 16, 2018, at 4:31 PM, Nikolay Samokhvalov = wrote: >=20 > Why not set up a spot EC2 instance with Postgres 10.1, load database = from a dump (yes you=E2=80=99ll need to create one from RDS because they = don=E2=80=99t provide direct access to dumps/backups; probably you need = to get only specific tables) and repeat your actions, closely looking at = filesystem. >=20 > =D1=81=D1=80, 16 =D0=BC=D0=B0=D1=8F 2018 =D0=B3. =D0=B2 13:10, = Jonathan Marks >: > Hi Tom =E2=80=94 >=20 > 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). >=20 > So, as far as we know: >=20 > 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 >=20 > 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. >=20 > Any other system-monitoring queries that we can run that might further = illuminate the issue? >=20 > Thank you! >=20 > > 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 >=20 >=20 --Apple-Mail=_FD20CC1E-6A6F-49B6-A445-8F619FCF7C7F Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 I = believe that we have figured it out. It indeed was a WAL issue =E2=80=94 = the WAL wasn=E2=80=99t getting measured because it had been moved into = an archived folder.

We= resolved this in a two main ways:

1. By dramatically increasing = max_wal_size to decrease the frequency of commits
2. = By turning on wal_compression

We=E2=80=99re going to continue looking = into whether we can reduce wal generation / write volume further by = turning back on fast_update on our GIN indexes.

On May 16, 2018, at 4:31 PM, Nikolay Samokhvalov <samokhvalov@gmail.com> wrote:

Why not set up a spot EC2 instance with Postgres = 10.1, load database from a dump (yes you=E2=80=99ll need to create one = from RDS because they don=E2=80=99t provide direct access to = dumps/backups; probably you need to get only specific tables) and repeat = your actions, closely looking at filesystem.

=D1=81=D1=80, 16 =D0=BC=D0=B0=D1=8F = 2018 =D0=B3. =D0=B2 13:10, Jonathan Marks <jonathanaverymarks@gmail.com>:
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 <jonathanaverymarks@gmail.com> wrote:
>
> 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.
>
> 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.
>
> 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?
>
> 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.
>
>> On May 14, 2018, at 3:08 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>
>> [ please keep the list cc'd ]
>>
>> Jonathan Marks <jonathanaverymarks@gmail.com> 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?
>>
>> 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
>



= --Apple-Mail=_FD20CC1E-6A6F-49B6-A445-8F619FCF7C7F--