Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id A51E055C5A4 for ; Mon, 16 Jul 2012 11:06:29 -0300 (ADT) Received: from mail-ey0-f174.google.com ([209.85.215.174]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SqlwP-0007V4-Qi for pgsql-performance@postgresql.org; Mon, 16 Jul 2012 14:06:28 +0000 Received: by eaak11 with SMTP id k11so1674702eaa.19 for ; Mon, 16 Jul 2012 07:06:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=Zo3IT1BcSV/lC/we6Q2lNyCuimRm0l1hSPgQCcYslL8=; b=RUbgGAlP7z4hF7slXi85WOhu4e7ZWOGi31KmrUoJydcQ5ekEJzhPBKF+Ffz+M7qjTo FEwDx4MYnB+2aY64hukyVU74/jq10Yw1fB21bVS9pl0IjiYqzKeG63gZJbJziWmprnn+ Tw5g5ylJQoiDvPxNNwTDrBsKLXqN3PGjgmTvg2m2vlK5fjF7seyHXs2sxRNlSrqcTf3W SxozxMmZQPwL1LtbNGFy96/q5VQBWumQVuRDYcZLwose7PEaPk3TJWhVUKILLNriFxM3 izy8ZfFpzRE4JdJYZku8nl3fy0yva85dfQrf6bI4ZEaEmyi5QYfMaUFVPSyZLoUOeKVC wdAA== Received: by 10.14.178.129 with SMTP id f1mr9272448eem.5.1342447572660; Mon, 16 Jul 2012 07:06:12 -0700 (PDT) Received: from [192.168.41.201] (host81-142-153-89.in-addr.btopenworld.com. [81.142.153.89]) by mx.google.com with ESMTPS id k48sm19112469een.10.2012.07.16.07.06.10 (version=SSLv3 cipher=OTHER); Mon, 16 Jul 2012 07:06:11 -0700 (PDT) Message-ID: <50041FD1.5070002@optrak.com> Date: Mon, 16 Jul 2012 15:06:09 +0100 From: Mark Thornton User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: pgsql-performance@postgresql.org, jnelson+pgsql@jamponi.net Subject: Re: very very slow inserts into very large table References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQnTUU8W37La9E6yVw3eHGL+RNYWgMuEBWAVMmcy0KKJbNRTcMCOlpces6EIrAolrhuxEa5Z X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201207/193 X-Sequence-Number: 47374 On 16/07/12 14:37, Jon Nelson wrote: > I have a single *table* that is some 560GB in size, 6 columns, average > row width 63. > There are approximately 6.1 billion rows. > It has 4 indices, 131, 313, 131 and 190 GB in size, respectively. All > are btree indices. > > I tried inserting new data into the table, and it's taking a *very* long time. > I pre-built the data to be inserted into a temporary table with the > exact same structure and column ordering, etc, and the temporary table > is about 8.5GB in size with about 93 million rows. > The temporary table was built in about 95 seconds. > The insert has been going for 47 hours and 21 minutes, give or take. > I'm not doing any correlation or filtering, etc -- straight up > insert, literally "insert into big_table select * from > the_temp_table;". > > vmstat output doesn't seem that useful, with disk wait being 10-15% > and I/O speeds highly variable, from 5-20MB/s reads couple with > 0-16MB/s writes, generally on the lower end of these. > strace of the inserting process shows that it's basically hammering > the disk in terms of random reads and infrequent writes. > postgresql. It's not verifying, rebuilding, etc. While this process is > active, streaming write I/O is terrible - 36MB/s. WIth it "paused" > (via strace) I get 72MB/s. (reads are 350MB/s). > > The OS is Scientific Linux 6.2, and the version of postgresql is 9.1.4 > - x86_64. There is nothing else of note happening on the box. The box > is a quad CPU, dual-core each Xeon E5430 @ 2.66GHz with 32GB of RAM > and a 3ware 9690 RAID 4TB RAID10 for the storage for > > What might be going on here? > > Every insert updates four indexes, so at least 3 of those will be in random order. The indexes don't fit in memory, so all those updates will involve reading most of the relevant b-tree pages from disk (or at least the leaf level). A total of 10ms of random read from disk (per inserted row) wouldn't surprise me ... which adds up to more than 10 days for your 93 million rows. Mark Thornton