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 1lACO6-0004F7-5F for pgsql-general@arkaria.postgresql.org; Thu, 11 Feb 2021 13:52:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lACO3-0005p6-MH for pgsql-general@arkaria.postgresql.org; Thu, 11 Feb 2021 13:52:03 +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 1lACO3-0005oy-Es for pgsql-general@lists.postgresql.org; Thu, 11 Feb 2021 13:52:03 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lACNw-0003hI-WD for pgsql-general@lists.postgresql.org; Thu, 11 Feb 2021 13:52:01 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 3CD78446D; Thu, 11 Feb 2021 14:51:54 +0100 (CET) Date: Thu, 11 Feb 2021 14:51:54 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: SV: Insertion time is very high for inserting data in postgres Message-ID: <20210211135154.GA1603@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <280e6bd026024e389657ae15ba169e90@dst.dk> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="6c2NcOVqGQ03X4Wi" Content-Disposition: inline In-Reply-To: <280e6bd026024e389657ae15ba169e90@dst.dk> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --6c2NcOVqGQ03X4Wi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2021-02-10 11:10:41 +0000, Niels Jespersen wrote: > >Fra: prachi surangalikar > >We are using Postgres 12.2.1 for fetching per minute data for about 25 > machines but running parallely via a single thread in python. > >But suddenly the insertion time has increased to a very high level, abou= t 30 >> second for one machine. >=20 > >We are in so much problem as the data fetching is becoming slow. >=20 > >if anyone could help us to solve this problem it would be of great help = to us. >=20 > Get your data into a Text.IO memory structure and then use copy https:// > www.psycopg.org/docs/usage.html#using-copy-to-and-copy-from >=20 > =20 >=20 > This is THE way of high-performant inserts using Postgres. True, but Prachi wrote that the insert times "suddenly ... increased to a very high level". It's better to investigate what went wrong than to blindly make some changes to the code. As a first measure I would at least turn on statement logging and/or pg_stat_statements to see which statements are slow, and then investigate the slow statements further. auto_explain might also be useful. hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --6c2NcOVqGQ03X4Wi Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmAlNnUACgkQ8g5IURL+ KF21LRAAomo3oD37BtNjo1NQ9WsLQqzbMGHIzHs/Ah6wQ6rBGaaBHtWxKBq8r1qY RLsL7+qT5s0WrqGA/nb7gD7GnskSc+MzIvzs0xcd/3NUFm9s39Q7wY3xVnm/TWJu nSH5hBZcXRsEO0nx+LVz3rk8EGgo3L/kve5azIK4S3OK04gkuMzW9FfmpjKoWyKa 2IU8EDoyxxNqe1X+xhkegRpBkzmSsNolvS7/mjbc83bdtO4uIHh2sbyU+H3370x8 +MF7WbWNbj2PzzKCTMLokg8E/1rygyWXLlVYDotSKL2J4gXCbbK4SwAekHYQCpCU OqQJggq+Jyn3OmDStUMblxoN/k9p5CLhQoW8knzm0rl8ya2h7LTK7G75rILjmYMa M3jlpyOMo9lCG0Jyek+nLPp+DuS9RQ/A6b+qVDSIv0ftDQ35NvfHE6Uy9rVx4a8J m+SqP1k6Zwy5Ud0iWco4xeNYQutjLLIYX4i/i14AmZ0iYMimx/oZhKXdBPfzu2De NJ4s6XRPNwG8LmjEqM9lGc20oJ3gCTJfQOU0n7yhV3LvwJNI3G6HzHoIMcJ4oARu 8mxauAue/xqTcy+wuWKEnJXGb5axaz1VqmsyzwkSP+bwqhWuEksjeGSTBag6NuDn pYISZdwcx2abmi++IMOgYWxiiLlWRstFp4sk8nW7pQGPMou90T0= =uSUl -----END PGP SIGNATURE----- --6c2NcOVqGQ03X4Wi--