Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 6789E9FCB6C for ; Thu, 8 Nov 2007 07:12:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 21229-04 for ; Thu, 8 Nov 2007 07:12:14 -0400 (AST) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.172]) by postgresql.org (Postfix) with ESMTP id 784809FCB66 for ; Thu, 8 Nov 2007 07:12:14 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id j3so338717ugf for ; Thu, 08 Nov 2007 03:12:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; bh=C4BLPA0ujPpLlrEx1QpUVhU95qmnCPDwYlF55euAkGA=; b=YxlT78xuq0LSEzGP50iPQiQIOzyMaOrfQT1z1WLE9CngfvhrjPO4Gd8k+jcP0VIERJUAyVjXdxuoqfBibN6pkvh+8wnZqQ9WDITsz9oImysRGtgLTFZCnYr8Vj2USSOREDA221NmUsWnhhzmf5jOkTlln96xXJeG8C6UAd/bR98= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=M6mU2j5RqHPLhLSNxg9NMS2Zu3MqYD288OP7bwdg9FDu1oXH9f/17gOr/Y9o6KdL6Ku0wDRkRPbiTJLfsLSKLHi21BxshYwCe8MtiscxL90R4FAQZt84TDOXH+2LV6lDzKQ/pBlawlO+fbPyiCX5LkN+JE+WYvgg4wags9pdBzI= Received: by 10.66.216.8 with SMTP id o8mr2088964ugg.1194520331685; Thu, 08 Nov 2007 03:12:11 -0800 (PST) Received: from ?192.168.1.33? ( [82.13.25.139]) by mx.google.com with ESMTPS id 27sm1225634ugp.2007.11.08.03.12.09 (version=SSLv3 cipher=RC4-MD5); Thu, 08 Nov 2007 03:12:10 -0800 (PST) Message-ID: <4732EF07.3060807@enterprisedb.com> Date: Thu, 08 Nov 2007 11:12:07 +0000 From: Heikki Linnakangas User-Agent: Icedove 1.5.0.12 (X11/20070730) MIME-Version: 1.0 To: Rafael Martinez CC: pgsql-performance@postgresql.org Subject: Re: Need to run CLUSTER to keep performance References: <4732E6B4.1030907@usit.uio.no> In-Reply-To: <4732E6B4.1030907@usit.uio.no> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/94 X-Sequence-Number: 27509 Rafael Martinez wrote: > This is a question about something we have seen sometimes in the last > months. It happens with tables with a large amount of updates/selects > compared with the amount of inserts/deletes. The sizes of these tables > are small and the amount of rows too. > > The 'problem' is that performance decrease during the day and the only > thing that helps is to run CLUSTER on the table with problems. VACUUM > ANALYZE does not help. > > Some information that can help to find out why this happens: > > - PostgreSQL version: 8.1.9 > > ------------------------------------------------------------------------------ > scanorama=# SELECT pg_size_pretty(pg_relation_size('hosts')); > > pg_size_pretty > ---------------- > 12 MB > ------------------------------------------------------------------------------ > scanorama=# SELECT count(*) FROM hosts ; > > count > ------- > 16402 > ------------------------------------------------------------------------------ > scanorama=# EXPLAIN ANALYZE SELECT * FROM hosts; > > Seq Scan on hosts (cost=0.00..2771.56 rows=66756 width=314) (actual > time=0.008..2013.415 rows=16402 loops=1) > Total runtime: 2048.486 ms > ------------------------------------------------------------------------------ > scanorama=# VACUUM ANALYZE ; > VACUUM > ------------------------------------------------------------------------------ > scanorama=# EXPLAIN ANALYZE SELECT * FROM hosts; > > Seq Scan on hosts (cost=0.00..2718.57 rows=61357 width=314) (actual > time=0.008..1676.283 rows=16402 loops=1) > Total runtime: 1700.826 ms > ------------------------------------------------------------------------------ > scanorama=# CLUSTER hosts_pkey ON hosts ; > CLUSTER > ------------------------------------------------------------------------------ > scanorama=# EXPLAIN ANALYZE SELECT * FROM hosts; > > Seq Scan on hosts (cost=0.00..680.02 rows=16402 width=314) (actual > time=0.008..31.205 rows=16402 loops=1) > Total runtime: 53.635 ms > ------------------------------------------------------------------------------ > scanorama=# SELECT * from pg_stat_all_tables WHERE relname LIKE 'hosts'; > relid | schemaname | relname | seq_scan | seq_tup_read | idx_scan | > idx_tup_fetch | n_tup_ins | n_tup_upd | n_tup_del > --------+------------+---------+----------+--------------+----------+---------------+-----------+-----------+----------- > 105805 | public | hosts | 1996430 | 32360280252 | 2736391 | > 3301856 | 948 | 1403325 | 737 > > The information from pg_stat_all_tables is from the last 20 days. > ------------------------------------------------------------------------------ > INFO: analyzing "public.hosts" > INFO: "hosts": scanned 2536 of 2536 pages, containing 16410 live rows > and 57042 dead rows; 16410 rows in sample, 16410 estimated total rows > INFO: free space map contains 191299 pages in 786 relations > DETAIL: A total of 174560 page slots are in use (including overhead). > 174560 page slots are required to track all free space. > Current limits are: 2000000 page slots, 4000 relations, using 12131 KB. > ------------------------------------------------------------------------------ > > The tables with this 'problem' are not big, so CLUSTER finnish very fast > and it does not have an impact in the access because of locking. But we > wonder why this happens. 2 seconds for seq scanning 12 MB worth of data sounds like a lot. Have you increased shared_buffers from the default? Which operating system are you using? Shared memory access is known to be slower on Windows. On a small table like that you could run VACUUM every few minutes without much impact on performance. That should keep the table size in check. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com