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 1fs88t-0006Ft-Bi for pgsql-general@arkaria.postgresql.org; Tue, 21 Aug 2018 15:00:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fs88q-0006DQ-Bw for pgsql-general@arkaria.postgresql.org; Tue, 21 Aug 2018 15:00:20 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1fs88p-0006Ct-QZ for pgsql-general@lists.postgresql.org; Tue, 21 Aug 2018 15:00:20 +0000 Received: from sonic302-3.consmr.mail.bf2.yahoo.com ([74.6.135.42]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fs88d-0000VZ-9v for pgsql-general@lists.postgresql.org; Tue, 21 Aug 2018 15:00:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1534863604; bh=Vwb4Y3bZXBnQBxy3APkVEOHGZl4K5v1S24Axz7heylw=; h=Date:From:To:Subject:References:From:Subject; b=OcAdkzk7ZvO2/UQApc96HxYafATtsMC7GKe6rqj/CZSEVy1Iv82fRZWWUFNHZTn8UV/UvzDwS+26ZUHe5UjE4V008E6A8lYsqP+7i4XRG2WdoCfwvZnIGHcRzDCTJU+HDuLoUoXBJon9vqekYVq3sototbUZIM2sM2zPCLPgiyw/bSD96QRPMXeDADWqx+ie4ZHqvSJkzQTWKU5cDses+DRs7mSNtUY/48S51iWaZDZF/BTGxfafJPUSovxUQNlYo5MeCv89LYSfHInhp1fc58NnEHjDZ8te3TpsnQ9WvlO4sAC0C7elLwhJ4Kqm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ug 2018 15:00:04 +0000 Date: Tue, 21 Aug 2018 15:00:03 +0000 (UTC) From: Ravi Krishna To: pgsql-general@lists.postgresql.org Message-ID: <89305671.347835.1534863603311@mail.yahoo.com> Subject: COPY FROM - to avoid WAL generation MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_347834_698671087.1534863603310" References: <89305671.347835.1534863603311.ref@mail.yahoo.com> X-Mailer: WebService/1.1.12262 aolwebmail Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 Content-Length: 2310 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_347834_698671087.1534863603310 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable In a recent thread of mine I learned something very interesting.=C2=A0 If a= table is created and data is loaded via COPY FROM within the same transact= ion, then PG will be smart enough to not generate WAL logs because all it n= eeds to do is to track the status of the transaction and let the data load = go to the new data file created for the table.=C2=A0 If committed, the tabl= e is released for other sessions, if rolledback, vaccum will delete the dat= a file later on. I tested it as follows for a table with 50 milllion rows.=C2=A0 No indexes. Case 1=C2=A0 - create the table first.=C2=A0 - in a separate transaction lo= ad the 50 million rows. Took 3 min 22 seconds Case 2=C2=A0 - start transaction=C2=A0 - create table=C2=A0 - load 50 milli= on rows=C2=A0 - commit transaction Took: 3 min 16 seconds. Am I missing anything? ------=_Part_347834_698671087.1534863603310 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
In a = recent thread of mine I learned something very interesting.  If a tabl= e is created and data is loaded via COPY FROM within the same transaction, = then PG will be smart enough to not generate WAL logs because all it needs = to do is to track the status of the transaction and let the data load go to= the new data file created for the table.  If committed, the table is = released for other sessions, if rolledback, vaccum will delete the data fil= e later on.

I tested it as follows for a table with 50 m= illlion rows.  No indexes.

Case 1
&= nbsp; - create the table first.
  - in a separate transactio= n load the 50 million rows.

Took 3 min 22 seconds<= /div>

Case 2
  - start transaction
<= div>  - create table
  - load 50 million rows
  - commit transaction

Took: 3 mi= n 16 seconds.

Am I missing anything?
------=_Part_347834_698671087.1534863603310--