Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTE9Q-0002PA-6g for pgsql-general@arkaria.postgresql.org; Tue, 21 May 2019 23:26:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hTE9M-0000Q3-Q1 for pgsql-general@arkaria.postgresql.org; Tue, 21 May 2019 23:26:28 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTE9M-0000Pw-EY for pgsql-general@lists.postgresql.org; Tue, 21 May 2019 23:26:28 +0000 Received: from mail-qt1-x844.google.com ([2607:f8b0:4864:20::844]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTE9J-0006hc-UW for pgsql-general@lists.postgresql.org; Tue, 21 May 2019 23:26:28 +0000 Received: by mail-qt1-x844.google.com with SMTP id f24so182227qtk.11 for ; Tue, 21 May 2019 16:26:25 -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=w+ZiNc6p9LKHos8Z3WZlJftj1MAoy27nPnaBcVC3izc=; b=Gl9KK6QGCCI6KddzRiU0OtLylqLuX4xqtkKRqjpFLp968HppvzqMOdbs5/zP9vB6Yh XB9DgokAmaabMK88NWaB1WFeeq4pAH6a1jS7R4AAKqZ8I1Npd2WZjWRqotK4Ljk8zpRr U3oYxUzpIZpvGUjBoAvX67AtJpJvz1upVTHyUXEI2AO1DNphU6qpwzC6MxGkb6T/aniY Ycrv6PmcRlKpYD0gryOd3O+6H8y7QU6yTdubOZioDdGhlmm4VTxC/Ol9EAt/t9ZuKgKj gvXvZ4ViZZjEuRZI4WrYRw/woG2r2F/Hhgr0Z36FmApzLzL5P+uiuFvs0N7aamvBohyO GhfA== 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=w+ZiNc6p9LKHos8Z3WZlJftj1MAoy27nPnaBcVC3izc=; b=pDtmFewTDh4SDcDknQqau/JOoVtIBDfb/qLtOM89pV6I9J7ysStqp6MoVXOta/jP5g 5PNDDIIakc4g1DhZ/dp584FaiklYJajx9m3HjxvyZJ2gR1lz5nEz+2f6ml1f//Xv4P1W xfL7iY4oSYPMbzOoxialLC+DQQXA70LOo1aoFlK4j97wGh019Quna/KbE3anu1Av7Jm4 AyZ4KheBjracuv2aBPfs4pWd5Luo2JmYF8D14yoZpbCo/K1sa6pL785nWaSel98f7wre ToEzjGAeqNmPxqAcxgMBe41laNE5iA3hXcOWoZs6mQYGdTPeLURDcsII0ZyVVD2+qlqT ysXg== X-Gm-Message-State: APjAAAVB/BPucYCpOhvBGymwK7zbxF8jCY5Il+rmW2H8tegjBMIoC0S1 x10oMSL5drWxVYXn+p++sG8= X-Google-Smtp-Source: APXvYqy7Ns96qpZbbb2xVvIqmWHls1depXKauVaCZpTLE/vtbX02pTeQTR6LX2p+OM41FALqv/J8xw== X-Received: by 2002:a0c:f40c:: with SMTP id h12mr24990218qvl.95.1558481183818; Tue, 21 May 2019 16:26:23 -0700 (PDT) Received: from [10.35.60.64] ([64.164.57.170]) by smtp.gmail.com with ESMTPSA id b123sm10248016qkd.45.2019.05.21.16.26.22 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 May 2019 16:26:22 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: Loading table with indexed jsonb field is stalling From: Will Hartung In-Reply-To: <22234.1558398707@sss.pgh.pa.us> Date: Tue, 21 May 2019 16:26:20 -0700 Cc: Will Hartung , Adrian Klaver , Ron , pgsql-general@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <999C358F-D7BD-4DED-9ED6-AC4E42157427@gmail.com> References: <20505.1558202555@sss.pgh.pa.us> <90835D2B-1FBA-4F26-8157-7C831C24B266@gmail.com> <3A35A039-D8F5-4B40-9B41-42E70BEF2C2E@gmail.com> <806d4915-f05d-8e75-0a42-e11b48596ab5@gmail.com> <12E9FEDD-37E9-4D51-9BA7-94FF5039BB1B@gmail.com> <563e995f-d7b1-7e2f-c1f1-b00db7a18589@gmail.com> <3EF519CA-17FE-4B68-8B7A-78200E0A408F@gmail.com> <7c0a001e-d3d5-c521-1a27-77d05f547fef@aklaver.com> <375E86FF-5B4D-4896-B4ED-FCA8C1D3A60B@gmail.com> <703a6c76-854d-3d1c-8be6-30864c873d05@aklaver.com> <52ACFC7C-47B8-4BF1-BDF1-8810F02BD297@gmail.com> <22234.1558398707@sss.pgh.pa.us> To: Tom Lane X-Mailer: Apple Mail (2.3124) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On May 20, 2019, at 5:31 PM, Tom Lane wrote: >=20 > Well, you're the only one who's seen this problem, and none of the > rest of us have any idea how to reproduce it. So if you want = something > to get done in a timely fashion, it's up to you to show us a test = case. So, we had success. We looked in to maintenance_work_mem. By default, this value is 64MB. Our test on AWS was against a small machine, 2 CPU, 16G. My VM is however many cores it gets (not that it matters) and 4G of RAM. My VM used the 64MB value for maintenance_work_mem. The AWS small VM = used 247M. We killed the rebuild on the small machine, it was pushing 67 hours. I was running a load on my machine, and it was still making progress = over night, but was at, like 17 hours. But it was moving, but had only = loaded 2.2M rows in that time. We grabbed one of the huge AWS instances. 64 CPU, 488G of ram. Just, = silly. But, that=E2=80=99s fine =E2=80=94 I=E2=80=99m good with silly. It=E2=80=99s mainteance_work_mem was ~8G. And we loaded all of my files on that instance in about 5.5 hours, about = 9M rows per hour. So, obviously, maintenance_work_mem was the smoking gun. Since I don=E2=80= =99t know the details of GIN indexing, its not clear to me how the = maintenance_work_mem is utilized with GIN index builds, but, obviously = 64M is =E2=80=9Cnot enough=E2=80=9D, nor is 247M. And 8G is certainly = enough. We=E2=80=99re cautious just setting these values =E2=80=9Cto 11=E2=80=9D = because of the fact that multiple connections can utilize them, so it = seems to me that it=E2=80=99s important that they be =E2=80=9Cgenerous = enough=E2=80=9D, but not overly generous. So this is good news, no bug, and, perhaps, left to its own devices, the = DB would have eventually built this index. Whether it would have done so = before universal heat death, is a different question. Can anyone discuss how the maintenance_work_mem is utilized during GIN = index creation? On our production systems, this value is set to 1G. And = we don=E2=80=99t seem to have any problems for day to day work. This is = a very busy table, and we have thousands of inserts/updates daily which = seem to proceed well enough. I have not tried to rebuild this index on = this system, so I can=E2=80=99t say if 1G is enough to rebuild this = index efficiently or not. But its efficient enough for our transaction = load. Now, that said, should I ever be in that situation of having to recover = this table like this, I=E2=80=99d have no problem cranking that value up = high since it would be the only real connection on the system anyway. But I=E2=80=99m still curious how the memory is utilized during index = builds just to have a better understanding of the nuances of the system. Thanks all for your help.