pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedCOPY FROM - to avoid WAL generation
4+ messages / 3 participants
[nested] [flat]
* COPY FROM - to avoid WAL generation
@ 2018-08-21 15:00 Ravi Krishna <sravikrishna@aol.com>
0 siblings, 2 replies; 4+ messages in thread
From: Ravi Krishna @ 2018-08-21 15:00 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
In a recent thread of mine I learned something very interesting. If a table 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 file later on.
I tested it as follows for a table with 50 milllion rows. No indexes.
Case 1 - create the table first. - in a separate transaction load the 50 million rows.
Took 3 min 22 seconds
Case 2 - start transaction - create table - load 50 million rows - commit transaction
Took: 3 min 16 seconds.
Am I missing anything?
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: COPY FROM - to avoid WAL generation
@ 2018-08-21 15:26 Jeff Ross <jross@openvistas.net>
parent: Ravi Krishna <sravikrishna@aol.com>
1 sibling, 0 replies; 4+ messages in thread
From: Jeff Ross @ 2018-08-21 15:26 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 8/21/18 9:00 AM, Ravi Krishna wrote:
> In a recent thread of mine I learned something very interesting. If a
> table 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 file later on.
>
> I tested it as follows for a table with 50 milllion rows. No indexes.
>
> Case 1
> - create the table first.
> - in a separate transaction load the 50 million rows.
>
> Took 3 min 22 seconds
>
> Case 2
> - start transaction
> - create table
> - load 50 million rows
> - commit transaction
>
> Took: 3 min 16 seconds.
>
> Am I missing anything?
>
Have you looked into pg_bulkload?
https://github.com/ossc-db/pg_bulkload
Docs are here:
http://ossc-db.github.io/pg_bulkload/index.html
Jeff
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: COPY FROM - to avoid WAL generation
@ 2018-08-21 15:31 Andres Freund <andres@anarazel.de>
parent: Ravi Krishna <sravikrishna@aol.com>
1 sibling, 0 replies; 4+ messages in thread
From: Andres Freund @ 2018-08-21 15:31 UTC (permalink / raw)
To: Ravi Krishna <sravikrishna@aol.com>; +Cc: pgsql-general@lists.postgresql.org
Hi,
On 2018-08-21 15:00:03 +0000, Ravi Krishna wrote:
> In a recent thread of mine I learned something very interesting. If a table 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 file later on.
> I tested it as follows for a table with 50 milllion rows. No indexes.
Please note this is only the case if wal_level = minimal. If replication
(or PITR) is supported, that mode can't be used, because the data has to
go into the WAL.
Were you using wal_level = minimal?
(FWIW, it's not VACUUM that'd unlink the data in cause of failure, but
that doesn't really matter much).
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: COPY FROM - to avoid WAL generation
@ 2018-08-21 15:42 Ravi Krishna <sravikrishna@aol.com>
0 siblings, 0 replies; 4+ messages in thread
From: Ravi Krishna @ 2018-08-21 15:42 UTC (permalink / raw)
To: ; +Cc: pgsql-general@lists.postgresql.org
>Please note this is only the case if wal_level = minimal. If replication
>(or PITR) is supported, that mode can't be used, because the data has to
>go into the WAL.
>Were you using wal_level = minimal?
Aha. No it was not minimal. For a second I thought PG is super smart. Oh well. Thanks.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2018-08-21 15:42 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-08-21 15:00 COPY FROM - to avoid WAL generation Ravi Krishna <sravikrishna@aol.com>
2018-08-21 15:26 ` Jeff Ross <jross@openvistas.net>
2018-08-21 15:31 ` Andres Freund <andres@anarazel.de>
2018-08-21 15:42 Re: COPY FROM - to avoid WAL generation Ravi Krishna <sravikrishna@aol.com>
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