Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XjTbT-00067A-M5 for pgsql-performance@arkaria.postgresql.org; Wed, 29 Oct 2014 13:47:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XjTbT-00083V-4E for pgsql-performance@arkaria.postgresql.org; Wed, 29 Oct 2014 13:47:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XjTbR-000815-9h for pgsql-performance@postgresql.org; Wed, 29 Oct 2014 13:47:57 +0000 Received: from nm27-vm5.bullet.mail.ne1.yahoo.com ([98.138.91.249]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XjTbN-0006b9-8k for pgsql-performance@postgresql.org; Wed, 29 Oct 2014 13:47:56 +0000 Received: from [98.138.226.177] by nm27.bullet.mail.ne1.yahoo.com with NNFMP; 29 Oct 2014 13:47:50 -0000 Received: from [98.138.87.2] by tm12.bullet.mail.ne1.yahoo.com with NNFMP; 29 Oct 2014 13:47:50 -0000 Received: from [127.0.0.1] by omp1002.mail.ne1.yahoo.com with NNFMP; 29 Oct 2014 13:47:50 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 124310.9726.bm@omp1002.mail.ne1.yahoo.com Received: (qmail 35101 invoked by uid 60001); 29 Oct 2014 13:47:49 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1414590469; bh=thhbr/uhvlaTg8/m+rpv/GZGa68w+/jl5KMU13wyrAU=; h=References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=bBg2vcisYyVCVv2Ma6iPMn3zt6uxVrOsB52UnGxrQ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G90b3MgdGFrZXMgMzggc2Vjb25kcyB0byBydW4gKHdpdGggYW4gYWdncmVnYXRlL25lc3RlZCBsb29wCj4gdGFraW5nIGVmZmVjdGl2ZWx5IGFsbCBvZiB0aGF0IHRpbWUpLAoKV2l0aCB0aGUgc2VlayB0aW1lIG9mIGNvbW1vZGl0eSBkaXNrIGRyaXZlcyB0eXBpY2FsbHkgYmVpbmcgOW1zLCBhCm5haXZlIGFwcHIBMAEBAQE- X-Mailer: YahooMailWebService/0.8.203.733 References: Message-ID: <1414590469.72962.YahooMailNeo@web122304.mail.ne1.yahoo.com> Date: Wed, 29 Oct 2014 06:47:49 -0700 From: Kevin Grittner Reply-To: Kevin Grittner Subject: Re: Sanity checking big select performance To: Jeff Chen , "pgsql-performance@postgresql.org" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Pg-Spam-Score: -0.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 Jeff Chen wrote: > One of these queries that should be targeting something like 300K > photos takes 38 seconds to run (with an aggregate/nested loop > taking effectively all of that time), With the seek time of commodity disk drives typically being 9ms, a naive approach using random access to join to 300k rows on a single thread with no caching would take 45 minutes; so the fact that you are seeing much better than that implies some benefit from cache, some sequential scanning, faster drives, or concurrent access to multiple spindles. > and then upon second execution with a warm cache, 4 seconds. This shows that it is faster to access data in RAM than on disk, and that your data wasn't already all in cache (most likely because it doesn't all fit in RAM). > Also worryingly, it spikes read IOPS to almost 1500/sec during > the time and write IOPS 200/sec. When not running the query, > steady level read iops basically nil, write hovers around 50-100. The reads are just another symptom of not having the data fully cached. The writes are more interesting. The two obvious possibilities are that the query needed to use work files (for sorts or hash tables) or that you were accessing a fair amount of data which had not been vacuumed since it was last modified. To help improve performance for the first, you might want to consider increasing work_mem (although this will reduce RAM available for caching). To improve performance for the second you might want to make autovacuum more aggressive. To get more specific advice, you may want to read this page and follow the advice there: https://wiki.postgresql.org/wiki/SlowQueryQuestions -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance