Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sokhC-00DZ4N-C0 for pgsql-general@arkaria.postgresql.org; Thu, 12 Sep 2024 14:21:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sokhB-009c55-Pj for pgsql-general@arkaria.postgresql.org; Thu, 12 Sep 2024 14:21:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sokhB-009c1L-Bc for pgsql-general@lists.postgresql.org; Thu, 12 Sep 2024 14:21:17 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sokh7-000pZO-FU for pgsql-general@lists.postgresql.org; Thu, 12 Sep 2024 14:21:16 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a8a897bd4f1so136738766b.3 for ; Thu, 12 Sep 2024 07:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726150874; x=1726755674; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=xoYbR4w5YokFewQkSw6F4+u92MghkiJMIVEpBR7y40A=; b=HCS+QdY3ljnDNieY3msd680S3Y6EgZkAEvzK0GOkJVFAQKkziwv9+ZmBAS2MDkbfIO PHByx5v26LLjmO/eub7Hu/tlnjAlskzQ1aNf0rejfHwaCLdkablQbZLSR8nckFoJxXCG 5XrLBAggA1tvov+SzXtG2JFMfo3Y+SmhlzzsaOlF0YdgBSNgVWhrTjwr1mHjuNn1K14x 8njTLNGp3mmklnB4NkcMBKDd3WZMcbSjj3icNFPFeaOMWoGstGzAlLN6JCS9H4m8Q6LM 3fG4ygOamkZ9bSClwQR3QvcSyDOoAlY1tGk+/mGl42xMKTXT7ZTMbuugufnocuXpILum +U0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726150874; x=1726755674; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xoYbR4w5YokFewQkSw6F4+u92MghkiJMIVEpBR7y40A=; b=Q71UlrPCtkc0+oxBNihbHJVh+sTckrJdZoQrhU+QsTWU29WX4sewWQM4/pFe/Wy1Yu cZPyQ95uMwdDols+Ysovpe9Kiom4BQ7cKaWRY+iBzPJIBmn0c68epJgh19ZUMU6s26JU dtFijocgrp7f/arSbF36Dmpyx7B/TWrd/YsIg/sSpBbBGFkYP3wKaJxQPXg+ijzhh7jr uOa1ZG4LzW9i4mBf6MWKP3W5pGUgA4E+x9+kKAhC6AvOyg6n0BW+DfiRKcdudMiSHlxE hf42Omk6c7dDrp/sVvtt5cADHkvrTGNWkN5/q9smabHZ+hfN+RFev/sMpOjHOK2bY9iB nYQg== X-Gm-Message-State: AOJu0YxJGSiUHzy71enPZ4aHvB1GAxpofLUX0Kv3IsocFTxzggr4t/Ys 7/JV4J3rVWd/XphT21FdsRXvKnoo/1OYm8rX2SK1z9Ej0Jrq7HxraQK/7Xz88ieWowXHf5kun/L SNPtPjEi0JvTvlP+dpcj4MbgJCPM= X-Google-Smtp-Source: AGHT+IHTrzwVv+xwbHh1IKVYoTjScgyNH6P6hC+EZgtx1ydb3i3Di8Oi6RRJvusf53+9KOBJEo0pfrhvPygfjYJuss8= X-Received: by 2002:a17:907:e20b:b0:a6f:593f:d336 with SMTP id a640c23a62f3a-a90294a909emr289853366b.11.1726150873786; Thu, 12 Sep 2024 07:21:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Durgamahesh Manne Date: Thu, 12 Sep 2024 19:53:45 +0530 Message-ID: Subject: Re: Performance degrade on insert on conflict do nothing To: Greg Sabino Mullane Cc: pgsql-general@lists.postgresql.org, pgsql-in-general@postgresql.org, Christoph Berg , laurenz.albe@cybertec.at, semab tariq , PostgreSQL mailing lists Content-Type: multipart/alternative; boundary="000000000000a933ce0621ecd1dc" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000a933ce0621ecd1dc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Greg Great response from you this worked Regards Durga Mahesh On Wed, Sep 11, 2024 at 7:12=E2=80=AFPM Greg Sabino Mullane wrote: > On Wed, Sep 11, 2024 at 1:02=E2=80=AFAM Durgamahesh Manne < > maheshpostgres9@gmail.com> wrote: > >> Hi >> createdat | timestamp with time zone | | not null | now(= ) >> | plain | | | >> modified | timestamp with time zone | | not null | now(= ) >> | plain | | | >> Triggers: >> i_dictionary_createdat BEFORE INSERT ON dictionary FOR EACH ROW >> EXECUTE FUNCTION update_createdat_col() >> i_dictionary_modified BEFORE INSERT OR UPDATE ON dictionary FOR EACH >> ROW EXECUTE FUNCTION update_modified_col() >> > > >> How do we improve this query performance without taking more cpu? >> > > 1. Lose the first trigger. I don't know exactly what those functions do, > but if they are only for updating those columns, just remove the first on= e > and let postgres handle it via NOT NULL DEFAULT. > > 2. Change the second trigger to just ON UPDATE > > 3. Remove that second trigger as well, and have the app populate that > column (assuming that is all it does), e.g. UPDATE dictionary SET lang = =3D > 'foo', modified =3D DEFAULT, modified_by =3D 'foo' where tid =3D 12345; > > 4. Remove any indexes you do not absolutely need > > Cheers, > Greg > > --000000000000a933ce0621ecd1dc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi=C2=A0Greg

Great response from you th= is worked=C2=A0

Regards
Durga Mahesh=C2= =A0

On Wed, Sep 11, 2024 at 7:12=E2=80=AFPM Greg Sabino Mullane <htamfids@gmail.com> wrote:
On Wed, Sep 11, 2024 at 1:02=E2=80=AFAM Durgamahesh Manne <= maheshpostgr= es9@gmail.com> wrote:
Hi=C2=A0
=C2= =A0createdat =C2=A0 =C2=A0 =C2=A0| timestamp with time zone | =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 | not null | now() =C2=A0 =C2=A0| plain =C2=A0 =C2=A0= | =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0|
=C2=A0modified =C2=A0 =C2=A0 =C2=A0 | t= imestamp with time zone | =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | not null | n= ow() =C2=A0 =C2=A0| plain =C2=A0 =C2=A0| =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 | =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|
Triggers:=C2=A0 =C2=A0 i_dictionary_createdat BEFORE INSERT ON dictionary FOR EACH = ROW EXECUTE FUNCTION update_createdat_col()
=C2=A0 =C2=A0 i_dictionary_m= odified BEFORE INSERT OR UPDATE ON dictionary FOR EACH ROW EXECUTE FUNCTION= update_modified_col()
=C2=A0
How do we = improve this query performance without taking more cpu?

1. Lose the first trigger. I don't know exactl= y what those functions do, but if they are only for updating those columns,= just remove the first one and let postgres handle it via NOT NULL DEFAULT.=

2. Change the second trigger to just ON UPDATE

3. Remove that second trigger as well, and have the = app populate that column (assuming that is all it does), e.g. UPDATE dictio= nary SET lang =3D 'foo', modified =3D DEFAULT, modified_by =3D '= ;foo' where tid =3D 12345;

4. Remove any index= es you do not absolutely need

Cheers,
Gr= eg

--000000000000a933ce0621ecd1dc--