Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id D298C2E0032 for ; Mon, 28 Apr 2008 15:18:05 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 30335-02 for ; Mon, 28 Apr 2008 15:17:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from 27.mail-out.ovh.net (27.mail-out.ovh.net [91.121.30.210]) by developer.postgresql.org (Postfix) with SMTP id 9AE5C2E0038 for ; Mon, 28 Apr 2008 15:18:00 -0300 (ADT) Received: (qmail 438 invoked by uid 503); 28 Apr 2008 20:07:27 -0000 Received: from gw2.ovh.net (HELO mail170.ha.ovh.net) (213.251.189.202) by 27.mail-out.ovh.net with SMTP; 28 Apr 2008 20:07:27 -0000 Received: from b0.ovh.net (HELO queue-out) (213.186.33.50) by b0.ovh.net with SMTP; 28 Apr 2008 18:17:54 -0000 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO apollo13.peufeu.com) (88.161.102.87) by ns0.ovh.net with SMTP; 28 Apr 2008 18:17:53 -0000 Date: Mon, 28 Apr 2008 20:23:12 +0200 To: "A B" , pgsql-performance@postgresql.org Subject: Re: Where do a novice do to make it run faster? From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: Content-Transfer-Encoding: Quoted-Printable Message-ID: In-Reply-To: User-Agent: Opera Mail/9.24 (Linux) X-Ovh-Tracer-Id: 1499980151616439819 X-Ovh-Remote: 88.161.102.87 (par69-8-88-161-102-87.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|H 0.5/N X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.717 tagged_above=0 required=5 tests=AWL=0.717 X-Spam-Level: X-Archive-Number: 200804/410 X-Sequence-Number: 29903 You got the order slightly wrong I guess. > 1) hardware Would only come first if your RAM is really too small, or you use RAID5= = on write-heavy tables, or what limits you is transaction fsync (hint : = 8.3). Adding RAM is cheap. > 2) rewriting my queries and table structures This should really come first. Log expensive queries. Note that an expensive query can be a slow query= , = or be a rather fast query that you execute lots of times, or a very simp= le = and fast query that you execute really really too often. Now ask yourself : * What is this query supposed to do ? * Do I need this query ? Example : You put your sessions in a database ? =3D> Perhaps put them in the good old filesystem ? Your PHP is loading lots of configuration from the database for every = page. =3D> Cache it, generate some PHP code once and include it, put it in th= e = session if it depends on the user, but don't reload the thing on each pa= ge = ! This feature is useless =3D> Do you really need to display a birthday cake on your forum for th= ose = users who have their birthday today ? UPDATEs... =3D> Do you really need to update the last time a user was online every= = time ? What about updating it every 5 minutes instead ? * Is this query inside a loop ? =3D> Use JOIN. * Do I need all the rows from this query ? Example : You use pagination and perform the same query changing LIMIT/OFFSET ? =3D> Perform the query once, retrieve the first N pages of result, cache= it = in the session or in a table. * You have a website ? =3D> Use lighttpd and fastcgi * Do I need all the columns from this query ? * Do I suffer from locking ? etc. Now you should see some easy targets. For the queries that are slow, use EXPLAIN ANALYZE. Question your schema. etc.