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 1ixb5r-0002q6-TH for pgsql-general@arkaria.postgresql.org; Fri, 31 Jan 2020 18:32:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ixb5q-0005PB-I4 for pgsql-general@arkaria.postgresql.org; Fri, 31 Jan 2020 18:32:38 +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 1ixb5o-0005P4-OG for pgsql-general@lists.postgresql.org; Fri, 31 Jan 2020 18:32:38 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ixb5k-0006QP-Be for pgsql-general@postgresql.org; Fri, 31 Jan 2020 18:32:36 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 3F81021F2E; Fri, 31 Jan 2020 13:32:30 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Fri, 31 Jan 2020 13:32:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=L +YJHiTslcq8LoYukQPkqhFx3QFfoefAVs0UWDLfL88=; b=iBnfawJBGvmA1/lAR s14DVj5BBGdNc0vLej8KpWgn5eA3TpDNCJ8/gY+47MYOrJF8rA1chP3KaAtbL4Ks lgoP0NwOa+7LclxDATS91b6pkgNN5Hsw92P38V3gLPap7cvok+N5AVV/wGEy06r2 zsZxn6N4+G5/Ii1yWHj5sD7yvj6SPUnmz+IAlrmiNFiW3aqOIYSSMo6XopscERzL amGOeROZSM/SSSVC0FeVitNXFvaCgeQHeBqB6noEtyuyvsBiuv9gjoSTjtU0K8zU dCx8tiJAawBPv8AqqKH6v8GwO/7i3Ajr48DQ0aShDNMlBuZCuXYwh0OE3TliPCw0 SZkCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=L+YJHiTslcq8LoYukQPkqhFx3QFfoefAVs0UWDLfL 88=; b=Idlv7GHCcaO84Y8H0yGwOSxFlE+hHoAnD78DzJWOVUySZq5qDP5zptn3y SntxuhZDLSwb1joGbLuO+R0oEU2Ki9EQK9kXd0uoTsIuZ+OVho+tvspZxdCOfvZ3 s9NJRHkbC1Q+rhhgjxfiupObAZOFGlQA2SaV+jNtQdt7fyxN4y6QOWWDXLQl7FP2 5x9rSCZP/yPB+Zu3U3QU0ixA+pIr+9gMJCElDF94J+gJVaxQEK6U6WQol8W22arB oD64Jo0+cUlOqaVADFXTxD6+MbJEmEAdrKH5Mx0GWK8HmKRd45+e4ErbOKvQ2fXG XBLQG+tnOFRm+XSYMWHsx3CELExug== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrgedtgddutdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtje ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuffhomhgrihhnpehpohhsthhgrhgvsh hqlhdrohhrghenucfkphepjeegrdelgedrjeefrddvvddvnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrg hklhgrvhgvrhdrtghomh X-ME-Proxy: Received: from ranger.suse (unknown [74.94.73.222]) by mail.messagingengine.com (Postfix) with ESMTPA id D6DBF3060986; Fri, 31 Jan 2020 13:32:28 -0500 (EST) Subject: Re: performance of loading CSV data with COPY is 50 times faster than Perl::DBI To: Matthias Apitz , pgsql-general@postgresql.org References: <20200131182441.GA8181@c720-r342378> From: Adrian Klaver Message-ID: <52a2d5e7-8443-25fb-af28-67f460a5e61e@aklaver.com> Date: Fri, 31 Jan 2020 10:32:27 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200131182441.GA8181@c720-r342378> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/31/20 10:24 AM, Matthias Apitz wrote: > > Hello, > > 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. > > 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. > > How can COPY do this so fast? Well for one thing COPY does everything in a single transaction, which is both good and bad. The good is that it is fast, the bad is that a single error will rollback the entire operation. COPY also uses it's own method for transferring data. For all the details see: https://www.postgresql.org/docs/12/protocol-flow.html#PROTOCOL-COPY > > matthias > -- Adrian Klaver adrian.klaver@aklaver.com