pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Tim Cross <theophilusx@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Improve COPY performance into table with indexes.
Date: Fri, 03 Apr 2020 10:47:40 +0200
Message-ID: <215532307a982c0e9cc1ec72993ec6435dea69a9.camel@cybertec.at> (raw)
In-Reply-To: <87eet5do6o.fsf@gmail.com>
References: <CAFCW2QMNCxO8=8FE5r05KqSDJAun-E0-gx174YhkTfVRMhTz1w@mail.gmail.com>
	<87eet5do6o.fsf@gmail.com>

On Fri, 2020-04-03 at 18:27 +1100, Tim Cross wrote:
> > I am using the COPY command to insert 10 million rows from a CSV file
> > into a database table and I am finding the performance is
> > unacceptable. When the COPY command is executed the disk I/O is
> > extremely high which leads to degraded query performance for other
> > queries being executed on the database.
> > 
> > What are my options in this scenario?
> 
> I don't think there is any way you can disable/drop indexes just for one
> transaction and not impact on other activities, such as queries. What
> options you have depends on a number of factors. Some
> questions/suggestions.

These are all good suggestions.

Let me add that there is a trade-off between fast queries and fast data
modifications.  You may drop those indexes that are not absolutely required
and accept that some queries become slower.

Another way to save one index is to partition on one column and drop the
index on that column.  Then queries can use a sequential scan on one
partition rather than an index scan, which might still be acceptable.

Speaking of partitioning: perhaps it is an option to use a partitioned
table and load the new data in a new partition. Then you can add the index
after loading and only then you turn the new table into a table partition.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com






view thread (5+ messages)  latest in thread

Message-ID: <215532307a982c0e9cc1ec72993ec6435dea69a9.camel@cybertec.at>
Permalink:  ../215532307a982c0e9cc1ec72993ec6435dea69a9.camel@cybertec.at/
Also on:    postgresql.org/message-id/215532307a982c0e9cc1ec72993ec6435dea69a9.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, theophilusx@gmail.com
  Subject: Re: Improve COPY performance into table with indexes.
  In-Reply-To: <215532307a982c0e9cc1ec72993ec6435dea69a9.camel@cybertec.at>
  References: <CAFCW2QMNCxO8=8FE5r05KqSDJAun-E0-gx174YhkTfVRMhTz1w@mail.gmail.com> <87eet5do6o.fsf@gmail.com> <215532307a982c0e9cc1ec72993ec6435dea69a9.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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