Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o92Vg-0002jB-C0 for pgsql-general@arkaria.postgresql.org; Wed, 06 Jul 2022 10:43:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o92Vf-0001bi-5d for pgsql-general@arkaria.postgresql.org; Wed, 06 Jul 2022 10:43:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o92Ve-0001bE-IW for pgsql-general@lists.postgresql.org; Wed, 06 Jul 2022 10:43:54 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1o92Vb-0000Il-Rh for pgsql-general@lists.postgresql.org; Wed, 06 Jul 2022 10:43:53 +0000 Received: by mail-ej1-x631.google.com with SMTP id sb34so26316589ejc.11 for ; Wed, 06 Jul 2022 03:43:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=KITUGHqFwrchTtYn65/WQ1YTJ9k0iN1Gk0urQbZbwbE=; b=lM3u+bPtbWDJ7N/EG3CjmhE8oiQmq6d6HGchIkbY2wY6e0UhSN8ggVGTEh2tE8e3xq NQkhKiniHxIaiIjj+B6S/7xZFr+o0QqOk5/OONzBolZHcWJRGEWT1dNTWUMORJJFnHNg HDfqGm29MGQ4qVZXLYj65HLZiUSFhOp8ugAs3WIi+sa22/6LAojNxUKNTHCPGD06BptU XveNrB9JEWPzfrouTA7ZcKSkDV/zk8cAmZNE4/kw9odSUDiQ6UaIEHLq2WMakCLGvYJz Xz4KDrjOhCc/Ra3PkupG42pg+Zxeyv1NUlpDKk7aehnQhF3830m848rXa/+ExXSoQifm /LcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=KITUGHqFwrchTtYn65/WQ1YTJ9k0iN1Gk0urQbZbwbE=; b=Jj1nRiCHm5amns2t1ezR0v0DE2s85iF8DzAtWfkdz3cEE0wNJ9zH5XTU8Wd7Ke4eme 9AiJVHI7cjInCwladIMxCkIa6wO3yzYBw6Quwcu9jE5iwC4gtQodom9/oFyCmgVGiV3k XE2k51dCp+4+PblIX9J2TZOcerGHnXH1E8w1xxtYysqqUi4+82nqtcjBdst5g2cdj/mt UvL+n9ViiYyzRdHbEo0cm45NYlTsN2sR6pb3ka/4hnFxjBeFQonR8aultGAAhxwJkKtH KZdxynXCS4jZ7GD3a+QK7Mu/7mA9OIWMSH2w/wGC0BSMjxutCV/HFiP0S3kdYlUYSAG/ /9VQ== X-Gm-Message-State: AJIora9kZHU3szYVJw1Z/T5wfv4yQLd+DFpdy74CuENlEMXLTKApedxo WF9uSL+K5DZL+UnFZI70WZw= X-Google-Smtp-Source: AGRyM1uyolrySB7kF56Irn6pN2OVhKA4ebJ/TPMUivo5/alEgyEtvHX/l2Uf7oVSfj2T68DxKYBlzQ== X-Received: by 2002:a17:907:7289:b0:726:bea6:488d with SMTP id dt9-20020a170907728900b00726bea6488dmr38784198ejc.283.1657104229587; Wed, 06 Jul 2022 03:43:49 -0700 (PDT) Received: from smtpclient.apple (ppp-94-66-221-5.home.otenet.gr. [94.66.221.5]) by smtp.gmail.com with ESMTPSA id t25-20020a056402241900b0043589eba83bsm15307822eda.58.2022.07.06.03.43.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jul 2022 03:43:49 -0700 (PDT) From: Florents Tselai Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_DD5F10BE-A1BD-42DC-8F15-192ED43F052C" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.100.31\)) Subject: Re: ADD COLUMN ts tsvector GENERATED too slow Date: Wed, 6 Jul 2022 13:43:47 +0300 In-Reply-To: Cc: Francisco Olarte , Peter Eisentraut , pgsql-general To: Florents Tselai References: <03C74523-7947-42CA-8392-B7CB8EFC16D2@gmail.com> <155880bb-f9d7-a34b-664b-61763b6e8719@enterprisedb.com> <4ABCA676-9635-421E-83DC-609E87E967AC@gmail.com> <9E6090C6-74EC-413F-9E3B-E6F2D59E772B@gmail.com> X-Mailer: Apple Mail (2.3696.100.31) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_DD5F10BE-A1BD-42DC-8F15-192ED43F052C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 6 Jul 2022, at 1:35 PM, Florents Tselai = wrote: >=20 >=20 >=20 >> On 6 Jul 2022, at 1:11 PM, Francisco Olarte = wrote: >>=20 >> On Wed, 6 Jul 2022 at 11:55, Florents Tselai = wrote: >>> Also, fwiw looking at top the CPU% and MEM% activity, looks like it = does data crunching work. >> ... >>>>> On 06.07.22 10:42, Florents Tselai wrote: >>>>>> I have a beefy server (40+ worker processes , 40GB+ shared = buffers) and a table holding (key text, text text,) of around 50M rows. >>>>>> These are text fields extracted from 4-5 page pdfs each. >>=20 >> How big is yout table? from your query it seems you expect more than >> 1M-1 ( left... ), but if you have very big text columns it may be >> spending a lot of time fully decompressing / reading them ( I'm not >> sure if it left(..) on toasted values is optimized to stop after >> reading enough ). Also, it has to rewrite a lot of data to insert the >> columns, it it takes some ms per row which I would not discard 50M >> rows * 1 ms / row =3D 50ksecs =3D 500k secs ~=3D13.9 hours per = ms-row, so at >> 2 ms ( which may be right for reading a big row, calculating the >> vector and writing an even bigger row ) it would take more than a day >> to finish, which I would not discard given you are asking for a heavy >> thing. >=20 > 50M+ rows and iirc pg_relation_size was north of 80GB or so. >=20 >>=20 >> If you have stopped it I would try doing a 1000 row sample in a = copied >=20 > Haven=E2=80=99t stopped it as I=E2=80=99m not convinced = there=E2=80=99s an alternative to just waiting > For it to complete :/=20 >=20 >> table to get an speed idea. Otherwise, with this query, I would >> normally monitor disk usage of disk files as an indication of Actually, I monitored my disk usage and it was **definitely** working as=20= It had already eaten up an additional 30% of my disk capacity. Thus, I=E2=80=99ll have to fall back on my initial solution and use GIN = indexes=20 To get ts_vectors on the fly. >> progress, I'm not sure there is another thing you could look at >> without disturbing it. >>=20 >> FWIW, I would consider high mem usage normal in these kind of query, >> hi cpu would depend on what you call it, but it wouldn't surprise me >> if it has at least one cpu running at full detoasting and doing >> vectors, I do not know if alter table can go paralell.. >>=20 >=20 > You=E2=80=99re probably right, a lot of the CPU usage could be = detoasting. >=20 >> Francisco Olarte. Thanks everyone for your comments. You can consider this solved.=20 --Apple-Mail=_DD5F10BE-A1BD-42DC-8F15-192ED43F052C Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On 6 Jul 2022, at 1:35 PM, Florents Tselai <florents.tselai@gmail.com> wrote:



On 6 Jul 2022, at 1:11 PM, Francisco = Olarte <folarte@peoplecall.com> wrote:

On Wed, 6 Jul 2022 at 11:55, Florents Tselai <florents.tselai@gmail.com> wrote:
Also, fwiw looking at = top the CPU% and MEM% activity, looks like it does data crunching = work.
...
On 06.07.22 10:42, Florents Tselai wrote:
I have a beefy server = (40+ worker processes , 40GB+ shared buffers) and a table holding (key = text, text text,) of around 50M rows.
These are text = fields extracted from 4-5 page pdfs each.

How big is yout table? from your query it seems you expect = more than
1M-1 ( left... ), but if you have very big text = columns it may be
spending a lot of time fully = decompressing / reading them ( I'm not
sure if it left(..) = on toasted values is optimized to stop after
reading = enough ). Also, it has to rewrite a lot of data to insert the
columns, it it takes some ms per row which I would not = discard 50M
rows * 1 ms / row =3D 50ksecs =3D 500k secs = ~=3D13.9 hours per ms-row, so at
2 ms ( which may be right = for reading a big row, calculating the
vector and writing = an even bigger row ) it would take more than a day
to = finish, which I would not discard given you are asking for a heavy
thing.

50M+ rows and iirc pg_relation_size was north of 80GB or = so.


If you have stopped it I would try doing a 1000 row sample in = a copied

Haven=E2=80=99t stopped it as I=E2=80=99m not = convinced there=E2=80=99s an alternative to just waiting
For it to complete :/ 

table = to get an speed idea. Otherwise, with this query, I would
normally monitor disk usage of disk files as an indication = of

Actually, I monitored my disk usage and it was = **definitely** working as 
It had already eaten up an = additional 30% of my disk capacity.

Thus, I=E2=80=99ll have to fall back on my initial = solution and use GIN indexes 
To get ts_vectors on the = fly.

progress, I'm not sure there is another thing you could look = at
without disturbing it.

FWIW,= I would consider high mem usage normal in these kind of query,
hi cpu would depend on what you call it, but it wouldn't = surprise me
if it has at least one cpu running at full = detoasting and doing
vectors, I do not know if alter table = can go paralell..


You=E2=80=99re probably right, a = lot of the CPU usage could be detoasting.

Francisco = Olarte.


Thanks everyone for your comments.
You = can consider this solved. 

= --Apple-Mail=_DD5F10BE-A1BD-42DC-8F15-192ED43F052C--