From: Tim Cross <theophilusx@gmail.com>
To: Anto Aravinth <anto.aravinth.cse@gmail.com>
Cc: Adrien Nayrat <adrien.nayrat@anayrat.info>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Using COPY to import large xml file
Date: Mon, 25 Jun 2018 08:14:28 +1000
Message-ID: <874lhrsugr.fsf@gmail.com> (raw)
In-Reply-To: <CANtp6R+VFj2=qD6+DR7Hpzg1c_cQRHG-W5kENsre3yQesJHHxw@mail.gmail.com>
References: <CANtp6R+Xu_LmGEA9-5OvX=h+7UqEppJfTgB8P9EcbkLOOO0Xtw@mail.gmail.com>
<95bb81dd-a80a-a493-2c3b-c03848acefc8@anayrat.info>
<CANtp6R+VFj2=qD6+DR7Hpzg1c_cQRHG-W5kENsre3yQesJHHxw@mail.gmail.com>
Anto Aravinth <anto.aravinth.cse@gmail.com> writes:
> Thanks for the response. I'm not sure, how long does this tool takes for
> the 70GB data.
>
> I used node to stream the xml files into inserts.. which was very slow..
> Actually the xml contains 40 million records, out of which 10Million took
> around 2 hrs using nodejs. Hence, I thought will use COPY command, as
> suggested on the internet.
>
> Definitely, will try the code and let you know.. But looks like it uses the
> same INSERT, not copy.. interesting if it runs quick on my machine.
>
> On Sun, Jun 24, 2018 at 9:23 PM, Adrien Nayrat <adrien.nayrat@anayrat.info>
> wrote:
>
>> On 06/24/2018 05:25 PM, Anto Aravinth wrote:
>> > Hello Everyone,
>> >
>> > I have downloaded the Stackoverflow posts xml (contains all SO questions
>> till
>> > date).. the file is around 70GB.. I wanna import the data in those xml
>> to my
>> > table.. is there a way to do so in postgres?
>> >
>> >
>> > Thanks,
>> > Anto.
>>
>> Hello Anto,
>>
>> I used this tool :
>> https://github.com/Networks-Learning/stackexchange-dump-to-postgres
>>
If you are using nodejs, then you can easily use the pg-copy-streams
module to insert the records into your database. I've been using this
for inserting large numbers of records from NetCDF files. Takes between
40 to 50 minutes to insert 60 Million+ records and we are doing
additional calculations on the values, not just inserting them,
plus we are inserting into a database over the network and into a database which is
also performing other processing.
We found a significant speed improvement with COPY over blocks of insert
transactions, which was faster than just individual inserts. The only
downside with using COPY is that it either completely works or
completely fails and when it fails, it can be tricky to work out which
record is causing the failure. A benefit of using blocks of transactions
is that you have more fine grained control, allowing you to recover from
some errors or providing more specific detail regarding the cause of the
error.
Be wary of what indexes your defining on your table. Depending on the
type and number, these can have significant impact on insert times as
well.
--
Tim Cross
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: theophilusx@gmail.com, anto.aravinth.cse@gmail.com, adrien.nayrat@anayrat.info
Subject: Re: Using COPY to import large xml file
In-Reply-To: <874lhrsugr.fsf@gmail.com>
References: <CANtp6R+Xu_LmGEA9-5OvX=h+7UqEppJfTgB8P9EcbkLOOO0Xtw@mail.gmail.com> <95bb81dd-a80a-a493-2c3b-c03848acefc8@anayrat.info> <CANtp6R+VFj2=qD6+DR7Hpzg1c_cQRHG-W5kENsre3yQesJHHxw@mail.gmail.com> <874lhrsugr.fsf@gmail.com>
* 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