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.89) (envelope-from ) id 1iyg0w-0007IV-7t for pgsql-general@arkaria.postgresql.org; Mon, 03 Feb 2020 18:00:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iyfzv-0003lB-7F for pgsql-general@arkaria.postgresql.org; Mon, 03 Feb 2020 17:58:59 +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 1iyfzu-0003l4-Tg for pgsql-general@lists.postgresql.org; Mon, 03 Feb 2020 17:58:58 +0000 Received: from ms-10.1blu.de ([178.254.4.101]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iyfzr-0002X2-Uo for pgsql-general@lists.postgresql.org; Mon, 03 Feb 2020 17:58:58 +0000 Received: from [188.174.87.171] (helo=localhost.unixarea.de) by ms-10.1blu.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.86_2) (envelope-from ) id 1iyfzo-0000pZ-P1; Mon, 03 Feb 2020 18:58:52 +0100 Received: from localhost.my.domain (localhost [127.0.0.1]) by localhost.unixarea.de (8.15.2/8.14.9) with ESMTPS id 013Hwp55003082 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 3 Feb 2020 18:58:51 +0100 (CET) (envelope-from guru@unixarea.de) Received: (from guru@localhost) by localhost.my.domain (8.15.2/8.14.9/Submit) id 013Hwplk003081; Mon, 3 Feb 2020 18:58:51 +0100 (CET) (envelope-from guru@unixarea.de) X-Authentication-Warning: localhost.my.domain: guru set sender to guru@unixarea.de using -f Date: Mon, 3 Feb 2020 18:58:51 +0100 From: Matthias Apitz To: Steven Lembark Cc: pgsql-general@lists.postgresql.org Subject: Re: performance of loading CSV data with COPY is 50 times faster than Perl::DBI Message-ID: <20200203175851.GA3037@c720-r342378> Reply-To: Matthias Apitz References: <20200131182441.GA8181@c720-r342378> <20200203100104.2a9d3fcd.lembark@wrkhors.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20200203100104.2a9d3fcd.lembark@wrkhors.com> X-Operating-System: FreeBSD 13.0-CURRENT r342378 (amd64) X-message-flag: Mails containing HTML will not be read! Please send only plain text. User-Agent: Mutt/1.11.1 (2018-12-01) X-Con-Id: 51246 X-Con-U: 0-guru X-Originating-IP: 188.174.87.171 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk El d=C3=ADa lunes, febrero 03, 2020 a las 10:01:04a. m. -0600, Steven Lemba= rk escribi=C3=B3: > On Fri, 31 Jan 2020 19:24:41 +0100 > Matthias Apitz wrote: >=20 > > Hello, > >=20 > > Since ages, we transfer data between different DBS (Informix, Sybase, > > Oracle, and now PostgreSQL) with our own written tool, based on > > Perl::DBI which produces a CSV like export in a common way, i.e. an > > export of Oracle can be loaded into Sybase and vice versa. Export and > > Import is done row by row, for some tables millions of rows. > >=20 > > We produced a special version of the tool to export the rows into a > > format which understands the PostgreSQL's COPY command and got to know > > that the import into PostgreSQL of the same data with COPY is 50 times > > faster than with Perl::DBI, 2.5 minutes ./. 140 minutes for around 6 > > million rows into an empty table without indexes. > >=20 > > How can COPY do this so fast? >=20 > DBI is a wonderful tool, but not intended for bulk transfer. It > is useful for post-processing queries that extract specific > data in ways that SQL cannot readily handle.=20 >=20 > One big slowdown is the cycle of pull-a-row, push-a-row involves=20 > signiicant latency due to database connections. That limits the=20 > throughput. I should have mentioned this: the export is done on Linux to file and the import with that tool is read from such files. matthias --=20 Matthias Apitz, =E2=9C=89 guru@unixarea.de, http://www.unixarea.de/ +49-176= -38902045 Public GnuPG key: http://www.unixarea.de/key.pub