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 1tsgjY-004eJ3-Ir for pgsql-performance@arkaria.postgresql.org; Thu, 13 Mar 2025 11:28:16 +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 1tsgjW-00BBoH-Vz for pgsql-performance@arkaria.postgresql.org; Thu, 13 Mar 2025 11:28:15 +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 1tsgjW-00BBnf-KN for pgsql-performance@lists.postgresql.org; Thu, 13 Mar 2025 11:28:14 +0000 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tsgjS-002dgy-37 for pgsql-performance@postgresql.org; Thu, 13 Mar 2025 11:28:14 +0000 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5e5491eb379so1197985a12.3 for ; Thu, 13 Mar 2025 04:28:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1741865291; x=1742470091; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=EtHjB8VaIeP6k17+4xifyU5aDehVSWjyCke4Nm8LrCo=; b=cxxS9llSJfWwJuz/R98+vZkpwe6ggaj+aBFCVSqzDDl+zNAEcYBiMXXn857wlocoKP MzNJaC70Ov1ctBdKDdbsZ78UsPCnNYQ4DWKGgkT5Pd0NHG/tKsrRAUMXOOyl3+pVIO8u ajaf7T6eDtRZEy5UXWjOcZqLPWeTf3S1yUaJgrYdOPiJGdblImSaM0gOI+L8cnwVTvNL WItmyj88/VRZfnkFBIPgjdnYHR6R5qpId8ZK/xOc5/7NqjjYQu7MgOQk98oSFlHtsT05 NsfPre9F56/+QUbBPpTUCgLxStuHFgmc5Sw81pFKsghZpA7Vy381O6DmSnq9ezhzQa81 lZqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741865291; x=1742470091; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=EtHjB8VaIeP6k17+4xifyU5aDehVSWjyCke4Nm8LrCo=; b=RTmTbdMwseRDBcJ+AOD502b3ZQ5kU+1U+jiLScLR/SDQDCdhJ+eFzdloQ8EfNFS0+L stmd/NpQEXiYO2hXbdXfTBe+ymUZ7mnu6S/VIFf7gmCP30De/erBS4jSpeQJHkb9Q8oX 8LIGR3fLdPnmt5K+525cmCOpIgnvXFsgQ6tHX5xti7CzDaOY5JkX2oYF+1m4p4+d1WJy XMd7vfkAcJKMXKHkVtM5KAWABvf02Xgvd+WsGAW4Y+KSq48dMrDmt9TdN4OXAGLVoHNA r1DASjiKO+3JNtXIWitKihVUFRjIgwOalKtv9Kgv9F4I5jBY8ZSlyE4LRkHbRtL7HpPu WvgA== X-Forwarded-Encrypted: i=1; AJvYcCUzvVQD5vxk3wuLNEincNplKPLkdNODj2PwD78uWMTUGjwqJjx0CoXYIx3brDZ40SIRYPm50Rrm1hTR6+1rQy8csA==@postgresql.org X-Gm-Message-State: AOJu0Yw5Y3WmfRmpMsBs/NGaExoxuJpQtvqVkKg6e75PDpOJ+V9ryNgt hsVQhIPXaFsREnHL5d8EhZhr/zt5KPBSJhcoiNGsTlLTiMss4Ub93DLyrTYGU1s= X-Gm-Gg: ASbGncshPzvQ+G++5GdNea/hAKHMmMVDWt/zuXKlitwbauuVt5XVIEEMNVQkdfQq9t8 0RwB4tTEwyWsKP5lpd78Hh9uPEkS5PHHrN/WW0TO0mDzT111wTixR/+kn+uvzPMNzJ5xFK9UNeD tUElVA9xN9+tHF+5YdPGlhzFaSCL0jOT6BQIoornxMKNTPXP+1c7Y83rkz9evcs+fFcymTOUCHe y0QX27CebNPI//rCNQU3j6t1nc2aCJKjS3X3MpA3/qEW0k6GpFB8y3KHkPOrCW3YeiqFolBr761 7xfVCjXKO9m610Bd/8V9JODA+mSFIj9jQwZWPAcAcRqvyzPsTDaQKqMw6DyDieFr X-Google-Smtp-Source: AGHT+IGjUVUzFmgyGOkrkDKDHBMOE4G6YTsRWPT2xXIpkhp0UwYR49zOoQMxGRsQTRgZQNmcBlwJgA== X-Received: by 2002:a50:858a:0:b0:5e6:23c:a242 with SMTP id 4fb4d7f45d1cf-5e6023ca3camr24636743a12.18.1741865290970; Thu, 13 Mar 2025 04:28:10 -0700 (PDT) Received: from localhost.localdomain ([88.116.133.170]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e816ad2894sm640023a12.51.2025.03.13.04.28.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Mar 2025 04:28:09 -0700 (PDT) Message-ID: Subject: Re: Bulk DML performance From: Laurenz Albe To: bill.poole@ymail.com, pgsql-performance@postgresql.org Date: Thu, 13 Mar 2025 12:28:09 +0100 In-Reply-To: <00a401db9400$86c240f0$9446c2d0$@ymail.com> References: <008701db93cd$2eb404d0$8c1c0e70$.ref@ymail.com> <008701db93cd$2eb404d0$8c1c0e70$@ymail.com> <0942a47d7a89f1b181f7e306f8389d9717eb5fe0.camel@cybertec.at> <00a401db9400$86c240f0$9446c2d0$@ymail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.54.3 (3.54.3-1.fc41) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2025-03-13 at 18:13 +0800, bill.poole@ymail.com wrote: >=20 > it is noteworthy that inserting 27 MB of data into a newly created table = creates > 191 MB of data including the index and 127 MB of data excluding the index= . PostgreSQL has a lot of overhead per row. >=20 > Can you help me understand why performing 3 million lookups on a b-tree i= ndex > with all pages cached in memory takes so long? It is probably not the lookup, but the *modification* of the index that is = slow. >=20 > It seems like deleting 3 million rows identified by 3 million IDs should = be > faster than updating 3 million rows (also identified by 3 million IDs). It should be, yes. To find out where the time is spent, use EXPLAIN (ANALYZE, BUFFERS) on the statement. > > To get better performance, the best I can think of is to parallelize lo= ading > > the data until you saturate CPU, disk or hit internal contention in the= database. >=20 > Sadly, I cannot do that because I need all rows to be inserted in a singl= e > database transaction, which I cannot do over multiple database connection= s. Then the best you can do is to use COPY rather than INSERT. It will perform better (but now vastly better). Yours, Laurenz Albe