Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TdurO-0007O9-6U for pgsql-performance@arkaria.postgresql.org; Thu, 29 Nov 2012 03:32:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TdurM-0007wF-AA for pgsql-performance@arkaria.postgresql.org; Thu, 29 Nov 2012 03:32:20 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TdurL-0007wA-89 for pgsql-performance@postgresql.org; Thu, 29 Nov 2012 03:32:19 +0000 Received: from mail-la0-f46.google.com ([209.85.215.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TdurI-0007KW-Ol for pgsql-performance@postgresql.org; Thu, 29 Nov 2012 03:32:18 +0000 Received: by mail-la0-f46.google.com with SMTP id p5so8317899lag.19 for ; Wed, 28 Nov 2012 19:32:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer :x-gm-message-state; bh=CmNV0ZdqjA5AKAv0yHCyZm4YyhjsVl9+0bFsksmZBig=; b=PW3Dg/gioVEMAQ1nRudK4nKe6KcEgwtx4wXPbLY6ukf8aI5J9DOtf7ycwdMY+DDQpv cFnUHwE1w4N+g9ASknC8DU2VTsntUXclVrReXbhlvoxyvf9EaAcysOZl2l6T9NO26HgM /byI+zq4cEJm91+j/nmRRXYQDKYahGm2UWi30l06jgSstyQq83N4OgrI/8B0HxgNXz5p hoFo8JppFUrJ1L9MJHuXA4MGYxFLvjzVkAU9LRstMRWxidzsxV1eJ2BZJd1CS79B4DIV tUK7pRCV8jirxqk1HIZyB/RTScVhPCnE9MS+htyT3WHX2zAcd5cO/N9d/nqwwFkVf93b Nluw== Received: by 10.152.108.197 with SMTP id hm5mr20298724lab.45.1354159934697; Wed, 28 Nov 2012 19:32:14 -0800 (PST) Received: from [192.168.0.14] (x1-6-84-1b-5e-20-07-92.k404.webspeed.dk. [80.167.117.15]) by mx.google.com with ESMTPS id bf3sm212395lbb.16.2012.11.28.19.32.12 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 28 Nov 2012 19:32:13 -0800 (PST) Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Subject: Re: Optimize update query From: =?iso-8859-1?Q?Niels_Kristian_Schj=F8dt?= In-Reply-To: <50B641AD.3020204@optionshouse.com> Date: Thu, 29 Nov 2012 04:32:11 +0100 Cc: Willem Leenen , Content-Transfer-Encoding: quoted-printable Message-Id: References: <1C199C0D-13DF-47B3-944A-B0560C6D2E5A@autouncle.com> <50B61ABF.4070000@optionshouse.com>, <50B6223B.6000100@mejor.pl> <50B641AD.3020204@optionshouse.com> To: X-Mailer: Apple Mail (2.1499) X-Gm-Message-State: ALoCoQl9frNac850u6OgmBbaXEK2mo2AMRTlxdpBTRuvjf5eBgNgNWWQEkiIkNw2WLqyr4wfK7jC X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Hi, I have started to implement your suggestions . I have a small error so = far though. The "vm.dirty_writeback_ratio =3D 1" command rerurns:=20 error: "vm.dirty_writeback_ratio" is an unknown key I'm on ubuntu 12.04 Den 28/11/2012 kl. 17.54 skrev Shaun Thomas : > On 11/28/2012 10:19 AM, Niels Kristian Schj=F8dt wrote: >=20 >> https://rpm.newrelic.com/public/charts/h2dtedghfsv >=20 > Doesn't this answer your question? >=20 > That iowait is crushing your server into the ground. It's no surprise upd= ates are taking several seconds. That update you sent us *should* execute o= n the order of only a few milliseconds. >=20 > So I'll reiterate that you *must* move your pg_xlog location elsewhere. Y= ou've got row lookup bandwidth conflicting with writes. There are a couple = other changes you should probably make to your config: >=20 >> checkpoint_segments =3D 16 >=20 > This is not enough for the workload you describe. Every time the database= checkpoints, all of those changes in pg_xlog are applied to the backend da= ta files. You should set these values: >=20 > checkpoint_segments =3D 100 > checkpoint_timeout =3D 10m > checkpoint_completion_target =3D 0.9 >=20 > This will reduce your overall write workload, and make it less active. To= o many checkpoints massively reduce write throughput. With the settings you= have, it's probably checkpointing constantly while your load runs. Start w= ith this, but experiment with increasing checkpoint_segments further. >=20 > If you check your logs now, you probably see a ton of "checkpoint startin= g: xlog" in there. That's very bad. It should say "checkpoint starting: tim= e" meaning it's keeping up with your writes naturally. >=20 >> work_mem =3D 160MB >=20 > This is probably way too high. work_mem is used every sort operation in a= query. So each connection could have several of these allocated, thus star= ting your system of memory which will reduce that available for page cache.= Change it to 8mb, and increase it in small increments if necessary. >=20 >> So correct me if I'm wrong here: my theory is, that I have too many >> too slow update queries, that then often end up in a situation, where >> they "wait" for each other to finish, hence the sometimes VERY long >> execution times. >=20 > Sometimes this is the case, but for you, you're running into IO contentio= n, not lock contention. Your 3TB RAID-1 is simply insufficient for this wor= kload. >=20 > If you check your logs after making the changes I've suggested, take a lo= ok at your checkpoint sync times. That will tell you how long it took the k= ernel to physically commit those blocks to disk and get a confirmation back= from the controller. If those take longer than a second or two, you're pro= bably running into controller buffer overflows. You have a large amount of = RAM, so you should also make these two kernel changes to sysctl.conf: >=20 > vm.dirty_ratio =3D 10 > vm.dirty_writeback_ratio =3D 1 >=20 > Then run this: >=20 > sysctl -p >=20 > This will help prevent large IO write spikes caused when the kernel decid= es to write out dirty memory. That can make checkpoints take minutes to com= mit in some cases, which basically stops all write traffic to your database= entirely. >=20 > That should get you going, anyway. You still need more/better disks so yo= u can move your pg_xlog directory. With your write load, that will make a h= uge difference. >=20 > --=20 > Shaun Thomas > OptionsHouse | 141 W. Jackson Blvd. | Suite 500 | Chicago IL, 60604 > 312-444-8534 > sthomas@optionshouse.com >=20 > ______________________________________________ >=20 > See http://www.peak6.com/email_disclaimer/ for terms and conditions relat= ed to this email --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance