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 1jKOrg-0005cP-0x for pgsql-general@arkaria.postgresql.org; Fri, 03 Apr 2020 16:08:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jKOre-0007JJ-Up for pgsql-general@arkaria.postgresql.org; Fri, 03 Apr 2020 16:08:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jKOre-0007JC-NL for pgsql-general@lists.postgresql.org; Fri, 03 Apr 2020 16:08:14 +0000 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jKOrc-0000zy-Pb for pgsql-general@lists.postgresql.org; Fri, 03 Apr 2020 16:08:14 +0000 Received: by mail-io1-xd44.google.com with SMTP id o3so8103385ioh.2 for ; Fri, 03 Apr 2020 09:08:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=uHRzarWk9Ei5WePieKaTDdmeOiPmIm08P7YlyEDg+PQ=; b=uKUzFMb4rNxBzydpYMXf7XDUSp+E5sLx/57aUodpNxY971fh0HQAfa1/KJJIqULR6e OTgz2bgIjLx1LfK3HYiDS5L8jXmYo7sXxkSFj6UgnvT8+bUU7ToJvTW0E8IINMwjwzi1 XRJmnbSbvmBCRdQWfpkaGQ0bGc0naG7sCQb4Fp7+n1mqsi162F/qGi0vpVD4+FIvYm6w 8kM1z2wljG2qHUMOWH2Qy09tQ+Bot6MRFuuZUsl1/WQDgKRQT4ELwJkYWttubOMzy8yr gwkA7AQnWiuWH4Yph5dJT9w4uOLJxXx2D11LhsDzJLxI0oZ6BzGnNXlQixSesHGOmW2L Ypqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=uHRzarWk9Ei5WePieKaTDdmeOiPmIm08P7YlyEDg+PQ=; b=ua8S4xJE44r/qjKuZTugd3rn6wg5ye35v0dblwvwNjSNa1AvZUf3nDeUgwy/BdqaaD pgc5BMQ3nuWzSkeJftG80nCz9ayjY+BDe2WjywBfKJc16BKN8z/5wcr4CmmKrU4/+xfM dv2AiVkWtORZqt3xWViIxdgEhuRmzNthbzYL47GGH7hyEcvccBlsjlOTboFUhFtcxjOT RdCW0ZHiLUmtDxpWl5qs1QgaHX2kK5eq7kHo7NZxD5cbwrcP8Tjbg3cbs7FvLgvENQ0P CBhomZXa+hahjJI9E/EDNKDZkF6jmKWkq1LximIPbBobIwkWaIIG4gAKKuLIVGtEGFrl vrNw== X-Gm-Message-State: AGi0PuZ/xnII+/0nOBKKQ3QL+hK1vmBk2ggpgm/5D151gfOugHhP1TBU M/dTU/wIH4WdKvveSVWGU8eCZ2Uv0Lo= X-Google-Smtp-Source: APiQypKqGP8GRiVwWfvOelcRS24DaxtgyflAr54DBybcQFSXeanlZGiIbVoLVTLH0MTCXcb6jNrGpg== X-Received: by 2002:a6b:378a:: with SMTP id e132mr8289776ioa.206.1585930086709; Fri, 03 Apr 2020 09:08:06 -0700 (PDT) Received: from [172.16.12.101] (c-73-63-59-118.hsd1.ut.comcast.net. [73.63.59.118]) by smtp.gmail.com with ESMTPSA id l12sm2912199ils.55.2020.04.03.09.08.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Apr 2020 09:08:05 -0700 (PDT) Subject: Re: Improve COPY performance into table with indexes. To: pgsql-general@lists.postgresql.org References: From: Rob Sargent Message-ID: <87083802-1fb6-52c9-b651-fdfdbe1232a2@gmail.com> Date: Fri, 3 Apr 2020 10:08:04 -0600 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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 4/3/20 9:52 AM, Adrian Klaver wrote: > On 4/2/20 9:42 PM, James Brauman 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. >> >> I have tried removing the indexes from the database table and this >> dramatically improved performance (both reducing the execution time >> and reducing disk I/O). > I've had excellent results dealing similar data quantity with the earlier suggestion of writing to a staging table.  Simply splitting the insert statements to cover 1/16[1] of the data turned untenable into real-time. [1] I split on an id column which is of UUID type.  Any arbitrary splitting that reduces the footprint sufficiently will do.