Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 220D09FBB4D for ; Mon, 18 Jun 2007 16:49:01 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 26097-04 for ; Mon, 18 Jun 2007 16:48:56 -0300 (ADT) X-Greylist: delayed 00:17:58.933191 by SQLgrey-1.7.5 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id ED3ED9FBB45 for ; Mon, 18 Jun 2007 16:48:56 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from silene.metacarta.com (silene.metacarta.com [65.77.47.18]) by svr4.postgresql.org (Postfix) with ESMTP id 684D45AFCFB for ; Mon, 18 Jun 2007 19:30:47 +0000 (GMT) Received: from localhost (silene.metacarta.com [65.77.47.18]) by silene.metacarta.com (Postfix) with ESMTP id 29D4F14C8F14 for ; Mon, 18 Jun 2007 15:30:34 -0400 (EDT) Received: from silene.metacarta.com ([65.77.47.18]) by localhost (silene.metacarta.com [65.77.47.18]) (amavisd-new, port 10024) with ESMTP id 20673-07 for ; Mon, 18 Jun 2007 15:30:32 -0400 (EDT) X-Auth-Received: from [65.77.47.195] (dhcp-65-77-47-195.metacarta.com [65.77.47.195]) (using SSLv3 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by silene.metacarta.com (Postfix) with ESMTP id 745B114C8F11 for ; Mon, 18 Jun 2007 15:30:32 -0400 (EDT) Message-ID: <4676DD57.7070304@metacarta.com> Date: Mon, 18 Jun 2007 15:30:31 -0400 From: Karl Wright User-Agent: Thunderbird 2.0.0.0 (Windows/20070326) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Performance query about large tables, lots of concurrent access Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at metacarta.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200706/314 X-Sequence-Number: 25346 Hi, I have an application which really exercises the performance of postgresql in a major way, and I am running into a performance bottleneck with Postgresql 8.1 that I do not yet understand. Here are the details: - There is a primary table, with some secondary tables - The principle transaction consists of a "SELECT...FOR UPDATE", followed by either an INSERT or an UPDATE on the primary table - INSERTs, DELETEs, and UPDATEs may occur on the secondary table depending on what happens with the primary table, for any given transaction. The secondary table has about 10x the number of rows as the primary. - All operations are carefully chosen so that highly discriminatory indexes are used to locate the record(s) in question. The execution plans show INDEX SCAN operations being done in all cases. - At any given time, there are up to 100 of these operations going on at once against the same database. What I am seeing: - In postgresql 7.4, the table activity seems to be gated by locks, and runs rather slowly except when the sizes of the tables are small. - In postgresql 8.1, locks do not seem to be an issue, and the activity runs about 10x faster than for postgresql 7.4. - For EITHER database version, the scaling behavior is not the log(n) behavior I'd expect (where n is the number of rows in the table), but much more like linear performance. That is, as the tables grow, performance drops off precipitously. For a primary table size up to 100,000 rows or so, I get somewhere around 700 transactions per minute, on average. Between 100,000 and 1,000,000 rows I got some 150 transactions per minute. At about 1,500,000 rows I get about 40 transactions per minute. - Access to a row in the secondary table (which right now has 13,000,000 rows in it) via an index that has extremely good discriminatory ability on a busy machine takes about 90 seconds elapsed time at the moment - which I feel is pretty high. I tried increasing the shared_buffers parameter to see if it had any impact on overall throughput. It was moderately helpful going from the small default value up to 8192, but less helpful when I increased it beyond that. Currently I have it set to 131072. Question: Does anyone have any idea what bottleneck I am hitting? An index's performance should in theory scale as the log of the number of rows - what am I missing here? Thanks very much! Karl