Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jKHzQ-0006P4-Ak for pgsql-general@arkaria.postgresql.org; Fri, 03 Apr 2020 08:47:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jKHzP-0000OV-8U for pgsql-general@arkaria.postgresql.org; Fri, 03 Apr 2020 08:47:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jKHzO-0000ON-S8 for pgsql-general@lists.postgresql.org; Fri, 03 Apr 2020 08:47:46 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jKHzL-0000tU-75 for pgsql-general@lists.postgresql.org; Fri, 03 Apr 2020 08:47:45 +0000 Received: by mail-wr1-x442.google.com with SMTP id c7so7500586wrx.5 for ; Fri, 03 Apr 2020 01:47:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=h3rCOWdG+3SxQA9q2BQZjceSu3PIKH7yWewcDXVIo8U=; b=El4Yneg3I+HivH2/dfoagoUxyfo0GVVzSBFhxrTAFkBA8nYpnrOW/ap760CHS4WVZ/ Gwktxi/yJl5Ayh4iA+HEQ4rbqiac/iwku2RbsZ+zoVOVeNtNMoO+NOtyD/kDAwa70xIG 8L82Bgkqn75CUEm5DGw6IWDohd77xvwzdrNDkgmpver9VjB1cRy//AoJW6TvtyrF8sUh bAtGaa8kITHgWpYT7hlDEjzcjNST8+whCLbKqTC2UiOROjrxmiMbXCkd6BWVc4zISz0i SRI9CccIeawr/AZuF8+kqjB4xoJkBUvautC41iKEVHu5evZWGok2iKBfx3lsrWmMV784 wYRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=h3rCOWdG+3SxQA9q2BQZjceSu3PIKH7yWewcDXVIo8U=; b=KNYGYxUPRXOmfacEaEPp1B4XevlSqwjGLzsoCRc5ZtPs6v5+gzkAH0WczUEP0f3oE+ Q2AbBX2ZpCEWF3b2fa5SuZf4+W0IrTBFIDJL3yNX+6fmLJ1b5qgHrvQNU1CPeWQ4ZvWr xG18g2ruRpjrpZYhOVYwjBP4Y2xkn2W9TG4hcdwnoVudGJrHjX3O3b1VvVAXn4QfZSBw aT9dL2WXcs9Y8MELLqTn4463Pe8gdOSl65eeIyUWrXKH0sBXTW4wvf31hWoYVrPsiNyl 7fPzicXBFt3CI/2JkGzUSbPEurP8ol0RfWSM1I8w1dDwqNCw+fMn0UGlzrd6o3wmdiqr uaMg== X-Gm-Message-State: AGi0PuavcwFXhHmcxlYj1//IlhwhbD9v/c2i9jPP15yQIBoJZw9TWyHq s1nsQIhqFYGCmh32SrBCbrv/WA== X-Google-Smtp-Source: APiQypIrKIg7b9kAfNavhEH5fcUjOT/tLSZ40fTShPzXeUkvfqbNSdHOz2Y3aVGhfyAkldOptrZMmA== X-Received: by 2002:a5d:4306:: with SMTP id h6mr2305113wrq.234.1585903661529; Fri, 03 Apr 2020 01:47:41 -0700 (PDT) Received: from dynamic-epxb5nex9f0d44bw6-pd01.res.v6.highway.a1.net (dynamic-epxb5nex9f0d44bw6-pd01.res.v6.highway.a1.net. [2001:871:60:e80a:4e0b:3bfa:c8d6:ad36]) by smtp.gmail.com with ESMTPSA id 195sm10829164wmb.8.2020.04.03.01.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 01:47:40 -0700 (PDT) Message-ID: <215532307a982c0e9cc1ec72993ec6435dea69a9.camel@cybertec.at> Subject: Re: Improve COPY performance into table with indexes. From: Laurenz Albe To: Tim Cross , pgsql-general@lists.postgresql.org Date: Fri, 03 Apr 2020 10:47:40 +0200 In-Reply-To: <87eet5do6o.fsf@gmail.com> References: <87eet5do6o.fsf@gmail.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.5 (3.32.5-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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