Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fXDHP-00037o-As for pgsql-general@arkaria.postgresql.org; Sun, 24 Jun 2018 22:14:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fXDHL-00084p-PK for pgsql-general@arkaria.postgresql.org; Sun, 24 Jun 2018 22:14:39 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fXDHL-00084i-By for pgsql-general@lists.postgresql.org; Sun, 24 Jun 2018 22:14:39 +0000 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fXDHG-0004ad-Vd for pgsql-general@lists.postgresql.org; Sun, 24 Jun 2018 22:14:38 +0000 Received: by mail-pg0-x242.google.com with SMTP id c10-v6so5184942pgu.9 for ; Sun, 24 Jun 2018 15:14:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=VK2HWTxLub83yNGnM/p4Awh/nT6X7QuYfr7ydg3jZCU=; b=Sc5UQTa0pzk78WyYmjIfB6UhJhZdORdJStean0oClhyVlGXJqQvADMa7QnhxqHUsi6 a61gNhQU/P5fVY5mjgXwxOoHS+45h+U3OnW5n3xnrJJ34L6CtMGb9tr8IsqKfoMaNmJ7 O1q5kA+8QhmwbazQDbniqvuwyJCpA+Y57hnQqbxapNyMEZ6Z4cjABikVgnDLvkK3czVM sP+6vVvMcUFUKrZWIM7izYXWDs6gSlsdhM1FvdCbZ7grHVdTsssyhSjPpvLaydLchRX/ YRSdmBEurn3N4uqUEzkXzG7u45OhFYuFVYf4BgcpqGa8X4MStPXiV9dZadvu3rK9tzpb qjKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=VK2HWTxLub83yNGnM/p4Awh/nT6X7QuYfr7ydg3jZCU=; b=QvEO4GdtU9ZtZqRJ4mGWRp3hkt6bt8I6MqKZjN48UT1orNv7rMDgUrQdBH8kuLWJ8J FvFri8D+lqk/3VEp5Xu+LBbL0jR6lrhdv6qcVDJ5jtNoxqaK1Z/ZKXm89xvaMYJeggP6 JgmjL3HGBmJw327fiwTF6m6YgjjAciVVadE2o9+dfxMqyjcVqzKJRI0PDkwdmGkA9Ox0 m/eH3M3I/6kEKWg/tOXeVuzGF1r6eLS9uyiqSfkfVR/QziRNhrO30YtJ09ZNn40+ESGL T7PXKqBD2Rvm72G7Cp4jDeWJYMFH5AVoGKtJepAIc58p70L3DSEUp0llGFq9hRt+BEvO /IBg== X-Gm-Message-State: APt69E3D3TP6/hWg6cfsGyFebdcUrGCuAgR+dpn/IB1DyfLyc+d9AHt+ AqIJvWxhhpGwV2VgUSgqjrIhAVLr X-Google-Smtp-Source: ADUXVKJop9fw7ifQQ8F5Ednr1bukUMvUxYppi4FSYNiWhpXh3PEq8vm+jqjH+PakPfimXfll88VZOg== X-Received: by 2002:a62:7db:: with SMTP id 88-v6mr10416862pfh.178.1529878473370; Sun, 24 Jun 2018 15:14:33 -0700 (PDT) Received: from tim-desktop (2001-44b8-31f2-bb00-8dd8-0999-73c5-db06.static.ipv6.internode.on.net. [2001:44b8:31f2:bb00:8dd8:999:73c5:db06]) by smtp.gmail.com with ESMTPSA id e17-v6sm12122942pgo.70.2018.06.24.15.14.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Jun 2018 15:14:32 -0700 (PDT) References: <95bb81dd-a80a-a493-2c3b-c03848acefc8@anayrat.info> User-agent: mu4e 0.9.18; emacs 26.1 From: Tim Cross To: Anto Aravinth Cc: Adrien Nayrat , pgsql-general@lists.postgresql.org Subject: Re: Using COPY to import large xml file In-reply-to: Date: Mon, 25 Jun 2018 08:14:28 +1000 Message-ID: <874lhrsugr.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Anto Aravinth 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 > 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