From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: Loading 500m json files to database
Date: Tue, 24 Mar 2020 10:27:34 +0100
Message-ID: <20200324092734.GA14300@hjp.at> (raw)
In-Reply-To: <1585009125214-0.post@n3.nabble.com>
References: <1584959088557-0.post@n3.nabble.com>
<CAFNqd5UWCrnh6o4R1-sQ=Kr-HLoK0M5d16HJ=y-9vM+Je-7oqQ@mail.gmail.com>
<1585009125214-0.post@n3.nabble.com>
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.
> >
> > 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.
>
> 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.
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
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
Attachments:
signature.asc (application/pgp-signature, 832B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: hjp-pgsql@hjp.at
Subject: Re: Loading 500m json files to database
In-Reply-To: <20200324092734.GA14300@hjp.at>
References: <1584959088557-0.post@n3.nabble.com> <CAFNqd5UWCrnh6o4R1-sQ=Kr-HLoK0M5d16HJ=y-9vM+Je-7oqQ@mail.gmail.com> <1585009125214-0.post@n3.nabble.com> <20200324092734.GA14300@hjp.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox