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.92) (envelope-from ) id 1jGfqY-0001au-Iv for pgsql-general@arkaria.postgresql.org; Tue, 24 Mar 2020 09:27:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jGfqX-0002CO-4U for pgsql-general@arkaria.postgresql.org; Tue, 24 Mar 2020 09:27:41 +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 1jGfqW-0002CH-RC for pgsql-general@lists.postgresql.org; Tue, 24 Mar 2020 09:27:40 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jGfqS-00027N-5q for pgsql-general@lists.postgresql.org; Tue, 24 Mar 2020 09:27:39 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 8DF4E29D6; Tue, 24 Mar 2020 10:27:34 +0100 (CET) Date: Tue, 24 Mar 2020 10:27:34 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Loading 500m json files to database Message-ID: <20200324092734.GA14300@hjp.at> References: <1584959088557-0.post@n3.nabble.com> <1585009125214-0.post@n3.nabble.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="9jxsPFA5p3P2qPhR" Content-Disposition: inline In-Reply-To: <1585009125214-0.post@n3.nabble.com> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2020-03-23 17:18:45 -0700, pinker wrote: > Christopher Browne-3 wrote > > Well, you're paying for a lot of overhead in that, as you're > > establishing a psql command, connecting to a database, spawning a > > backend process, starting a transactions, committing a transaction, > > closing the backend process, disconnecting from the database, and > > cleaning up after the launching of the psql command. And you're > > doing that 500 million times. > >=20 > > The one thing I left off that was the loading of a single tuple into > > json_parts. [...] > > Reducing that overhead is the single most important thing you can do. >=20 > Yes, I was thinking about that but no idea now how to do it right now. Do you know any programming language (Python, Perl, ...)? You'll probably get a huge gain from writing a script that just opens the connection once and then inserts each file.=20 Copy usually is even faster by a fair amount, but since you have to read the data for each row from a different file (and - if I understood you correctly, a remote one at that), the additional speedup is probably not that great in this case. Splitting the work int batches and executing several batches in parallel probably helps. hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --9jxsPFA5p3P2qPhR Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAl550oIACgkQ8g5IURL+ KF0P6w/+PTJjMWoR1H68QmowYRyUOmPKzmNSCx6QxqcNhEEfwiOJfQiiP6Jzw1We 0WRMJKZ7iIVS48xvx/IqSCdtQ0HrRQ4Vallc3xJBLSvGsFgBJQFihlzJUb5sleVk wVFfsPGhVepr/KQktBTihWk/jqRLG9hXbH9GZva3A0Cy4Frdrq7dOtAsaga66vKU XMGMdllICliRwxwzHc5XVMXG+uLiyCGtRno446XXYtJrx9IKz+B9ZhZZc6NySVka 7odW+s6wFMyrOyg6FeCQdRNUWqce+clEQLnccXX7hxY5Uc5zG6qHMYhophk6R/hw keUJUMHAJR19Hb7HLb12eRva4qSWpvIjwP+uAjORBmcUsaMVdiWsBi85w6VMqR7T k81C9rZHJGu6Q9Mjnku5/39k52qUGkJdY3PxfIxVw/n99mDY2iJl8TGbksvblDTF 4cVT6fPqhRuG3KEgAC6UahYcFngUq3ljAf/8f5VWefVmJZU/CxN75v7yf/8r8r2p BLRMlZYuhMlbwIc2zANnPukW7OUpzuUWWefYlqJ/lAATMp8sPxJJKuuk78vcGHe4 NecMiNkpXofbwZ3hRpKx9N8FqVaM4xN8z1uLcsVPWUJqE0l2LzmaVuqEmAd3qdzF S0RV+530wVmIx931NvoN0BZMTtgmdjPLxHl77S9E7fJyC4VnlSU= =d+zU -----END PGP SIGNATURE----- --9jxsPFA5p3P2qPhR--