From pgsql-bugs-owner@postgresql.org Sat May 31 22:29:52 2003 X-Original-To: pgsql-bugs@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 7A65692595B for ; Sat, 31 May 2003 22:29:51 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 80324-09 for ; Sat, 31 May 2003 22:29:41 -0400 (EDT) Received: from simmts5-srv.bellnexxia.net (simmts5.bellnexxia.net [206.47.199.163]) by developer.postgresql.org (Postfix) with ESMTP id 67481925942 for ; Sat, 31 May 2003 22:29:40 -0400 (EDT) Received: from [192.168.1.200] ([64.231.215.231]) by simmts5-srv.bellnexxia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20030601022937.UMIA7058.simmts5-srv.bellnexxia.net@[192.168.1.200]>; Sat, 31 May 2003 22:29:37 -0400 Subject: Re: Index speeds up one row table (why)? From: Rod Taylor To: Dave E Martin XXIII Cc: pgsql-bugs@postgresql.org In-Reply-To: <3ED93338.80806@dave.to> References: <3ED93338.80806@dave.to> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-GMB/VZzTWx+23wqx8UuU" Organization: Message-Id: <1054434573.11968.42.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.4 Date: 31 May 2003 22:29:33 -0400 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/131 X-Sequence-Number: 6092 --=-GMB/VZzTWx+23wqx8UuU Content-Type: text/plain Content-Transfer-Encoding: quoted-printable > vacuum verbose bigint_unique_ids; > INFO: --Relation public.bigint_unique_ids-- > INFO: Index bigint_unique_ids__table_name: Pages 29; Tuples 1: Deleted= =20 > 5354. > CPU 0.01s/0.04u sec elapsed 0.05 sec. > INFO: Removed 11348 tuples in 79 pages. > CPU 0.00s/0.02u sec elapsed 0.02 sec. > INFO: Pages 79: Changed 1, Empty 0; Tup 1: Vac 11348, Keep 0, UnUsed 0. > Total CPU 0.03s/0.06u sec elapsed 0.14 sec. Vacuum (regular, not full) frequently enough that the 'Pages' value doesn't increase past 1 and you'll be fine. A sequential scan on a very small table is what you want to have. In this particular case, vacuum removed over 11000 dead versions of the tuple. An 8 k page will hold approx 140 tuples based on your structure. So, for every ~100 updates you'll want to run vacuum (regular, not full) on the table. --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-GMB/VZzTWx+23wqx8UuU Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA+2WUN6DETLow6vwwRAqBYAJ9T/4JelT/VgC/OdzozMkcE7dqu5QCcC9lV gJN0G1B/1iECZKDcyFuPFJc= =lPHq -----END PGP SIGNATURE----- --=-GMB/VZzTWx+23wqx8UuU-- From pgsql-performance-owner@postgresql.org Sat May 31 22:52:34 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 30E809257F9 for ; Sat, 31 May 2003 22:52:33 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 84767-01 for ; Sat, 31 May 2003 22:52:22 -0400 (EDT) Received: from TheWorld.com (pcls1.std.com [199.172.62.103]) by developer.postgresql.org (Postfix) with ESMTP id 51AEF921BF2 for ; Sat, 31 May 2003 22:52:22 -0400 (EDT) Received: from trouble (pool-151-203-197-57.bos.east.verizon.net [151.203.197.57]) by TheWorld.com (8.12.8p1/8.12.8) with SMTP id h512qI1L023377 for ; Sat, 31 May 2003 22:52:19 -0400 From: "Brian Tarbox" To: Subject: are views typically any faster/slower than equivilent joins? Date: Sat, 31 May 2003 22:55:18 -0400 Message-ID: <001801c327e9$3c01a5b0$01000001@trouble> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) In-Reply-To: <20030531180235.GF22469@libertyrms.info> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/305 X-Sequence-Number: 2084 I am working with a highly normalized database. Most of my meaningful queries involve joins from a primary table to 4-6 secondary tables. Would my query performance be significantly faster/slower using a View as opposed to a prepared query using join? (Assume all join fields are ints, say 10,000 records in main table and a few dozen records in each of the secondary tables). Thank you. Brian Tarbox From pgsql-performance-owner@postgresql.org Sun Jun 1 00:22:48 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 06118925007 for ; Sun, 1 Jun 2003 00:08:52 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 00556-05 for ; Sun, 1 Jun 2003 00:08:40 -0400 (EDT) Received: from simmts3-srv.bellnexxia.net (simmts3.bellnexxia.net [206.47.199.12]) by developer.postgresql.org (Postfix) with ESMTP id 6308E9257F9 for ; Sun, 1 Jun 2003 00:03:20 -0400 (EDT) Received: from [192.168.1.200] ([64.231.215.231]) by simmts3-srv.bellnexxia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20030601040311.ULJY3380.simmts3-srv.bellnexxia.net@[192.168.1.200]>; Sun, 1 Jun 2003 00:03:11 -0400 Subject: Re: are views typically any faster/slower than equivilent joins? From: Rod Taylor To: Brian Tarbox Cc: Postgresql Performance In-Reply-To: <001801c327e9$3c01a5b0$01000001@trouble> References: <001801c327e9$3c01a5b0$01000001@trouble> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-hn0s7XAM/1HaQLeYd4d/" Organization: Message-Id: <1054440158.11968.86.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.4 Date: 01 Jun 2003 00:02:39 -0400 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/2 X-Sequence-Number: 2086 --=-hn0s7XAM/1HaQLeYd4d/ Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Sat, 2003-05-31 at 22:55, Brian Tarbox wrote: > I am working with a highly normalized database. Most of my meaningful > queries involve joins from a primary table to 4-6 secondary tables. >=20 > Would my query performance be significantly faster/slower using a View as > opposed to a prepared query using join? There are some corner cases where a view would be slower than a standard query in 7.3 (bug fix / disabled optimization -- fixed right in 7.4), but generally you can assume it will be about the same speed. Some views such as unions will not be as fast as you would like, but thats a general issue with PostgreSQLs inability to throw away selects when it won't find results on one side of a union. CREATE VIEW sales AS SELECT * FROM sales_archive_2002 UNION ALL SELECT * FROM sales_current; SELECT * FROM sales WHERE timestamp =3D> CURRENT_TIMESTAMP - INTERVAL '1 day'; The above query would not be so quick. --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-hn0s7XAM/1HaQLeYd4d/ Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA+2Xrd6DETLow6vwwRAh98AJ9RICX3wyq8VsWE0LMYK4FcBP7HZACfbK7+ LtWGpApA8NbyEUDzvWdPufQ= =o9jx -----END PGP SIGNATURE----- --=-hn0s7XAM/1HaQLeYd4d/-- From pgsql-performance-owner@postgresql.org Sun Jun 1 00:19:01 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 7DB96925A01 for ; Sun, 1 Jun 2003 00:09:47 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 00783-04 for ; Sun, 1 Jun 2003 00:09:36 -0400 (EDT) Received: from simmts4-srv.bellnexxia.net (simmts4.bellnexxia.net [206.47.199.13]) by developer.postgresql.org (Postfix) with ESMTP id D1FF692592B for ; Sun, 1 Jun 2003 00:06:41 -0400 (EDT) Received: from [192.168.1.200] ([64.231.215.231]) by simmts4-srv.bellnexxia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20030601040630.WKIH20459.simmts4-srv.bellnexxia.net@[192.168.1.200]>; Sun, 1 Jun 2003 00:06:30 -0400 Subject: Re: are views typically any faster/slower than equivilent joins? From: Rod Taylor To: Brian Tarbox Cc: Postgresql Performance In-Reply-To: <001801c327e9$3c01a5b0$01000001@trouble> References: <001801c327e9$3c01a5b0$01000001@trouble> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-kojaQBjoR6414uAp8E7B" Organization: Message-Id: <1054440355.11968.90.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.4 Date: 01 Jun 2003 00:05:56 -0400 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/1 X-Sequence-Number: 2085 --=-kojaQBjoR6414uAp8E7B Content-Type: text/plain Content-Transfer-Encoding: quoted-printable > Would my query performance be significantly faster/slower using a View as > opposed to a prepared query using join? I missed this part. Views and prepared queries are not the same time.=20 Use of a view still needs to be optimized. Prepared queries will run the optimization portion on the entire query including the view segments of it. Think of a view as a MACRO.=20 Depending on the context of what surrounds it, the view may be executed very differently. --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-kojaQBjoR6414uAp8E7B Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA+2Xuj6DETLow6vwwRAgXBAJ9X9ge3noEA2lwqP+kKoBca4K3ZZwCghT9A SpEiUs+oCK/rqGzqxXcufBk= =+VOH -----END PGP SIGNATURE----- --=-kojaQBjoR6414uAp8E7B-- From pgsql-bugs-owner@postgresql.org Sun Jun 1 01:31:45 2003 X-Original-To: pgsql-bugs@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 22A35926109 for ; Sun, 1 Jun 2003 01:31:40 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 30692-09 for ; Sun, 1 Jun 2003 01:31:22 -0400 (EDT) Received: from wolff.to (wolff.to [66.93.249.74]) by developer.postgresql.org (Postfix) with SMTP id 7E3CF926104 for ; Sun, 1 Jun 2003 01:31:20 -0400 (EDT) Received: (qmail 26151 invoked by uid 500); 1 Jun 2003 05:33:39 -0000 Date: Sun, 1 Jun 2003 00:33:39 -0500 From: Bruno Wolff III To: Dave E Martin XXIII Cc: pgsql-bugs@postgresql.org Subject: Re: Index speeds up one row table (why)? Message-ID: <20030601053339.GB16259@wolff.to> Mail-Followup-To: Dave E Martin XXIII , pgsql-bugs@postgresql.org References: <3ED93338.80806@dave.to> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3ED93338.80806@dave.to> User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/4 X-Sequence-Number: 6099 On Sat, May 31, 2003 at 16:56:56 -0600, Dave E Martin XXIII wrote: > > (ok, experimented a bit more just now) > Hm, it appears that degredation occurs with the index as well, I guess > at the time I created the index, it just initially did better because it > got to skip all the already dead rows at creation time: but this is > disturbing, I do a vacuum, and the access times are better, but still > horrible: You really don't want to use an index, so this probably doesn't matter for the current application. The problem is that when data is inserted into an index that just increases (or decreases) in value space from deleted entries doesn't get reused. I believe this is fixed in 7.4. This case would apply to indexes based on counters, dates or times where new values are added and old values get deleted. From pgsql-performance-owner@postgresql.org Sun Jun 1 01:41:30 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id CAF5C9260E6 for ; Sun, 1 Jun 2003 01:41:29 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 35894-08 for ; Sun, 1 Jun 2003 01:41:19 -0400 (EDT) Received: from wolff.to (wolff.to [66.93.249.74]) by developer.postgresql.org (Postfix) with SMTP id BCA5F923489 for ; Sun, 1 Jun 2003 01:41:18 -0400 (EDT) Received: (qmail 26229 invoked by uid 500); 1 Jun 2003 05:43:37 -0000 Date: Sun, 1 Jun 2003 00:43:37 -0500 From: Bruno Wolff III To: Rod Taylor Cc: Brian Tarbox , Postgresql Performance Subject: Re: are views typically any faster/slower than equivilent joins? Message-ID: <20030601054337.GD16259@wolff.to> Mail-Followup-To: Rod Taylor , Brian Tarbox , Postgresql Performance References: <001801c327e9$3c01a5b0$01000001@trouble> <1054440158.11968.86.camel@jester> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1054440158.11968.86.camel@jester> User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/3 X-Sequence-Number: 2087 On Sun, Jun 01, 2003 at 00:02:39 -0400, Rod Taylor wrote: > > Some views such as unions will not be as fast as you would like, but > thats a general issue with PostgreSQLs inability to throw away selects > when it won't find results on one side of a union. > > CREATE VIEW sales AS SELECT * FROM sales_archive_2002 UNION ALL SELECT * > FROM sales_current; > > > SELECT * FROM sales WHERE timestamp => CURRENT_TIMESTAMP - INTERVAL '1 > day'; > > The above query would not be so quick. I thought some work had been done on pushing where conditions down into unions? If so the above wouldn't be too bad. It would still look at the archive table, but it should return no rows relatively quickly assuming an appropiate index exists. From pgsql-bugs-owner@postgresql.org Sun Jun 1 03:20:10 2003 X-Original-To: pgsql-bugs@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id BBBAB9260FC for ; Sun, 1 Jun 2003 03:20:09 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 48119-01 for ; Sun, 1 Jun 2003 03:19:58 -0400 (EDT) Received: from mail.quantium.net (b.ns.quantium.net [67.96.140.30]) by developer.postgresql.org (Postfix) with SMTP id 4989F9260C0 for ; Sun, 1 Jun 2003 03:19:57 -0400 (EDT) Received: (qmail 27386 invoked from network); 1 Jun 2003 07:19:50 -0000 Received: from 15-pool1.ras10.coden-le3.alerondial.net (HELO dave.to) (206.149.128.15) by quantium.net with SMTP; 1 Jun 2003 07:19:50 -0000 Message-ID: <3ED9A923.90500@dave.to> Date: Sun, 01 Jun 2003 01:20:03 -0600 From: Dave E Martin XXIII User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020623 Debian/1.0.0-0.woody.1 X-Accept-Language: en MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: Re: Index speeds up one row table (why)? References: <3ED93338.80806@dave.to> <1054434573.11968.42.camel@jester> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/6 X-Sequence-Number: 6101 Rod Taylor wrote: >An 8 k page will hold approx 140 tuples based on your structure. So, >for every ~100 updates you'll want to run vacuum (regular, not full) on >the table Alas, for this application, that means a vacuum once every 5 seconds or so. I'll see if I can set up a separate little task to do that (I assume at this rate, its better to just keep a connection open, than setup/teardown). I don't suppose there is a way to get a trigger to do a vacuum (which doesn't want to be in a transaction) (thinking it could check for id mod 100=0 or something)? I also assume a few pages isn't going to be that bad (just don't let it get to 11000 8). From pgsql-performance-owner@postgresql.org Sun Jun 1 07:56:37 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 2ABF5926018 for ; Sun, 1 Jun 2003 07:56:36 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 93596-04 for ; Sun, 1 Jun 2003 07:56:25 -0400 (EDT) Received: from simmts8-srv.bellnexxia.net (simmts8.bellnexxia.net [206.47.199.166]) by developer.postgresql.org (Postfix) with ESMTP id 4EA28925C61 for ; Sun, 1 Jun 2003 07:56:25 -0400 (EDT) Received: from [192.168.1.200] ([64.231.215.231]) by simmts8-srv.bellnexxia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20030601115624.ZAFZ20699.simmts8-srv.bellnexxia.net@[192.168.1.200]>; Sun, 1 Jun 2003 07:56:24 -0400 Subject: Re: are views typically any faster/slower than From: Rod Taylor To: Bruno Wolff III Cc: Brian Tarbox , Postgresql Performance In-Reply-To: <20030601054337.GD16259@wolff.to> References: <001801c327e9$3c01a5b0$01000001@trouble> <1054440158.11968.86.camel@jester> <20030601054337.GD16259@wolff.to> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-d7k9EV6Cwtzyzcp8DrLz" Organization: Message-Id: <1054468575.11968.95.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.4 Date: 01 Jun 2003 07:56:15 -0400 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/4 X-Sequence-Number: 2088 --=-d7k9EV6Cwtzyzcp8DrLz Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Sun, 2003-06-01 at 01:43, Bruno Wolff III wrote: > On Sun, Jun 01, 2003 at 00:02:39 -0400, > Rod Taylor wrote: > >=20 > > Some views such as unions will not be as fast as you would like, but > > thats a general issue with PostgreSQLs inability to throw away selects > > when it won't find results on one side of a union. > >=20 > > CREATE VIEW sales AS SELECT * FROM sales_archive_2002 UNION ALL SELECT * > > FROM sales_current; > >=20 > >=20 > > SELECT * FROM sales WHERE timestamp =3D> CURRENT_TIMESTAMP - INTERVAL '1 > > day'; > >=20 > > The above query would not be so quick. >=20 > I thought some work had been done on pushing where conditions down into > unions? If so the above wouldn't be too bad. It would still look at > the archive table, but it should return no rows relatively quickly > assuming an appropiate index exists. Certainly, if the index exists it won't be so bad (for any single archive table). It's when the index doesn't exist or there are several hundred archive tables then it starts to get a little worse. Anyway, anyone doing the above in PostgreSQL should probably be looking at partial indexes and merging the information back into a single table again. --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-d7k9EV6Cwtzyzcp8DrLz Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA+2ene6DETLow6vwwRAo/QAJ9IvScAW8kCxHpgz/OLPYv3Z3vaqQCfTB2F /1F0FiAoZAvhoVvksUwaw48= =+XuI -----END PGP SIGNATURE----- --=-d7k9EV6Cwtzyzcp8DrLz-- From pgsql-performance-owner@postgresql.org Sun Jun 1 08:14:38 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 0AA1492617A for ; Sun, 1 Jun 2003 08:14:37 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 97323-08 for ; Sun, 1 Jun 2003 08:14:26 -0400 (EDT) Received: from simmts3-srv.bellnexxia.net (simmts3.bellnexxia.net [206.47.199.12]) by developer.postgresql.org (Postfix) with ESMTP id BC1D8925524 for ; Sun, 1 Jun 2003 08:14:25 -0400 (EDT) Received: from [192.168.1.200] ([64.231.215.231]) by simmts3-srv.bellnexxia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20030601121424.YMBV3380.simmts3-srv.bellnexxia.net@[192.168.1.200]>; Sun, 1 Jun 2003 08:14:24 -0400 Subject: Re: Index speeds up one row table (why)? From: Rod Taylor To: Dave E Martin XXIII Cc: pgsql-performance@postgresql.org In-Reply-To: <3ED9A923.90500@dave.to> References: <3ED93338.80806@dave.to> <1054434573.11968.42.camel@jester> <3ED9A923.90500@dave.to> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-+4goO8r5posAty0VOel7" Organization: Message-Id: <1054469655.11968.109.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.4 Date: 01 Jun 2003 08:14:15 -0400 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/5 X-Sequence-Number: 2089 --=-+4goO8r5posAty0VOel7 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable sending thread to -performance from -bugs On Sun, 2003-06-01 at 03:20, Dave E Martin XXIII wrote: > Rod Taylor wrote: >=20 > >An 8 k page will hold approx 140 tuples based on your structure. So, > >for every ~100 updates you'll want to run vacuum (regular, not full) on > >the table >=20 > Alas, for this application, that means a vacuum once every 5 seconds or= =20 > so. I'll see if I can set up a separate little task to do that (I assume= =20 > at this rate, its better to just keep a connection open, than=20 > setup/teardown). I don't suppose there is a way to get a trigger to do a= =20 > vacuum (which doesn't want to be in a transaction) (thinking it could=20 > check for id mod 100=3D0 or something)? I also assume a few pages isn't= =20 > going to be that bad (just don't let it get to 11000 8). Sorry... Vacuum cannot be triggered -- nor would you want it to be.=20 There really isn't anything wrong with vacuuming once every 5 seconds or so, as it'll take a very short time if there is only a page or so to deal with. Setup a script to connect, issue a vacuum, count to 5, issue a vacuum, count to 5, etc. More than one page and you will want an index. Having an index is only going to slow things down in the long run as indexes will not shrink with a vacuum in 7.3 (7.4 puts an effort towards correcting this). This means you'll be running REINDEX every couple of minutes, which of course locks the table, where standard vacuum does not. --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-+4goO8r5posAty0VOel7 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA+2e4W6DETLow6vwwRAl1nAJ0TYf5E9vN2fAdk83BY3r/R+Tk6cwCdG4+9 sOLNr9ynUngMSzwCklOLtsE= =IISZ -----END PGP SIGNATURE----- --=-+4goO8r5posAty0VOel7-- From pgsql-bugs-owner@postgresql.org Sun Jun 1 15:02:04 2003 X-Original-To: pgsql-bugs@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id B15609261ED for ; Sun, 1 Jun 2003 15:02:01 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 73786-01 for ; Sun, 1 Jun 2003 15:01:49 -0400 (EDT) Received: from wolff.to (wolff.to [66.93.249.74]) by developer.postgresql.org (Postfix) with SMTP id DC1A592622B for ; Sun, 1 Jun 2003 15:01:48 -0400 (EDT) Received: (qmail 7892 invoked by uid 500); 1 Jun 2003 19:04:09 -0000 Date: Sun, 1 Jun 2003 14:04:09 -0500 From: Bruno Wolff III To: Dave E Martin XXIII Cc: pgsql-bugs@postgresql.org Subject: Re: Index speeds up one row table (why)? Message-ID: <20030601190409.GA7853@wolff.to> Mail-Followup-To: Dave E Martin XXIII , pgsql-bugs@postgresql.org References: <3ED93338.80806@dave.to> <1054434573.11968.42.camel@jester> <3ED9A923.90500@dave.to> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3ED9A923.90500@dave.to> User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/11 X-Sequence-Number: 6106 On Sun, Jun 01, 2003 at 01:20:03 -0600, Dave E Martin XXIII wrote: > Rod Taylor wrote: > > >An 8 k page will hold approx 140 tuples based on your structure. So, > >for every ~100 updates you'll want to run vacuum (regular, not full) on > >the table > > Alas, for this application, that means a vacuum once every 5 seconds or > so. I'll see if I can set up a separate little task to do that (I assume > at this rate, its better to just keep a connection open, than > setup/teardown). I don't suppose there is a way to get a trigger to do a > vacuum (which doesn't want to be in a transaction) (thinking it could > check for id mod 100=0 or something)? I also assume a few pages isn't > going to be that bad (just don't let it get to 11000 8). Maybe you should reconsider how badly you want the app to be totally database agnostic? Using a sequence might be less of a contortion than using vacuum a few times a minute. You are likely to have similar performance issues with other databases, so this section of code may not turn out to be very portable in any case. From pgsql-performance-owner@postgresql.org Sun Jun 1 21:13:27 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 5187D926264 for ; Sun, 1 Jun 2003 21:13:26 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 24314-10 for ; Sun, 1 Jun 2003 21:12:55 -0400 (EDT) Received: from hotmail.com (law8-f48.law8.hotmail.com [216.33.241.48]) by developer.postgresql.org (Postfix) with ESMTP id F402C926262 for ; Sun, 1 Jun 2003 21:12:54 -0400 (EDT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Sun, 1 Jun 2003 18:12:55 -0700 Received: from 35.12.25.73 by lw8fd.law8.hotmail.msn.com with HTTP; Mon, 02 Jun 2003 01:12:54 GMT X-Originating-IP: [35.12.25.73] X-Originating-Email: [praslar@hotmail.com] From: "Ricky Prasla" To: pgsql-performance@postgresql.org Subject: Select Query Performance Date: Sun, 01 Jun 2003 21:12:54 -0400 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 02 Jun 2003 01:12:55.0275 (UTC) FILETIME=[18D33BB0:01C328A4] X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/6 X-Sequence-Number: 2090 Hi, I am running Postgresql 7.2.3 on a linux Qube with 256 RAM. I have a tabe with about 100,000 records. The table has a postgis geometry column. I have a GIST index on the table on the geometry column. Here are my questions: 1)When I do a spatial select query on the geometry column in this table it takes a few seconds. What more can I do in terms of the Postgresql configuration or query tuning besides adding the GIST index? Here's a sample query I make: Select [column] from [table_name] where [spatial_column] && [the geometry object]; 2)Also, I execute this query over the web. If there are mltiple select queries then I have to execute one get its reultset and then send the other one. Is there a faster way to execute multiple select queries over the web? Thanks in advance. Riyaz _________________________________________________________________ Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail From pgsql-performance-owner@postgresql.org Sun Jun 1 21:49:02 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id ADC6A92627B for ; Sun, 1 Jun 2003 21:49:00 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 34215-05 for ; Sun, 1 Jun 2003 21:48:50 -0400 (EDT) Received: from simmts1-srv.bellnexxia.net (simmts1.bellnexxia.net [206.47.199.10]) by developer.postgresql.org (Postfix) with ESMTP id BC721926279 for ; Sun, 1 Jun 2003 21:48:49 -0400 (EDT) Received: from [192.168.1.200] ([64.231.215.231]) by simmts1-srv.bellnexxia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20030602014846.HTYN10472.simmts1-srv.bellnexxia.net@[192.168.1.200]>; Sun, 1 Jun 2003 21:48:46 -0400 Subject: Re: Select Query Performance From: Rod Taylor To: Ricky Prasla Cc: Postgresql Performance In-Reply-To: References: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-+J0N3oXGLc3BnDIgO0sv" Organization: Message-Id: <1054518510.77081.4.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.4 Date: 01 Jun 2003 21:48:31 -0400 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/7 X-Sequence-Number: 2091 --=-+J0N3oXGLc3BnDIgO0sv Content-Type: text/plain Content-Transfer-Encoding: quoted-printable > 2)Also, I execute this query over the web. If there are mltiple select=20 > queries then I have to execute one get its reultset and then send the oth= er=20 > one. Is there a faster way to execute multiple select queries over the we= b? Going with the assumption the result-set is not used to generate further queries, you might look into the use of Asynchronous connections. It'll enable you to easily establish several connections to the database for parallel work to be done. http://www.postgresql.org/docs/view.php?version=3D7.3&idoc=3D1&file=3Dlibpq= -connect.html Even PHP will let you use the Asynchronous query mechanism within PostgreSQL. --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-+J0N3oXGLc3BnDIgO0sv Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA+2qzu6DETLow6vwwRAlf7AJ4jNOk6lRqk6CtQmUGVfMOzJaH2JgCffVAX O1PRZeqHfb42LPdgEPmYo0I= =HpHp -----END PGP SIGNATURE----- --=-+J0N3oXGLc3BnDIgO0sv-- From pgsql-performance-owner@postgresql.org Mon Jun 2 00:58:54 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id A56C49262E8 for ; Mon, 2 Jun 2003 00:58:53 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 80662-10 for ; Mon, 2 Jun 2003 00:58:43 -0400 (EDT) Received: from ike.local.anstat.com.au (mole.anstat.com.au [202.92.123.11]) by developer.postgresql.org (Postfix) with ESMTP id 409719262E7 for ; Mon, 2 Jun 2003 00:58:42 -0400 (EDT) Received: by IKE with Internet Mail Service (5.5.2655.55) id ; Mon, 2 Jun 2003 14:56:19 +1000 Message-ID: <7395B46C07F8D51182AE000629570CC4804A31@IKE> From: George Papastamatopoulos To: pgsql-performance@postgresql.org Cc: Paul Smith Subject: FW: Query Plan problem Date: Mon, 2 Jun 2003 14:56:18 +1000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2655.55) Content-Type: text/plain; charset="iso-8859-1" X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/8 X-Sequence-Number: 2092 > Hi All, > > We have a performance problem with a specific query, where just getting > the QUERY PLAN (_not_ getting the results of the query itself) on this > query is taking up to 10 seconds, and spinning the CPU, and basically > blocking other access to the db. This same query on a dump/restore on > another server (different kernel, same postgres version, much less > powerful box) generates practically the same query plan, but the > generation of the query plan takes orders of magnitude less (almost > immmediately generates it). > > We noticed this significant performance loss when we upgraded from > Postgres 7.2.1 -> 7.2.3 over the weekend, we also upgraded our RedHat > kernel from "2.4.18-4smp i686" to "2.4.20-13.7smp i686", plus upgraded to > latest glibc at the same time (probably shouldn't have mixed all those > upgrades, but there you go). > > We did not do a dump restore as part of the postgres/kernal upgrade on our > production box (docs say upgrade is fine without it). We vacuumed every > which way possible. Several times. Vacuum full analyze. the lot. We > dropped the indexes and recreated them. We used REINDEX. > > This is a UNICODE database, and this table does contain some unicode > character sequences. > > The offending explain statement is: > > EXPLAIN SELECT tblUser.id, tblUser.first_name, tblUser.last_name, > tblUser.login, tblUser.comments, tblUser.title_id, tblUser.bh_phone, > tblUser.ah_phone, tblUser.mobile, tblUser.fax, tblUser.address, > tblUser.city, tblUser.state_id, tblUser.country_id, tblUser.postcode, > tblUser.plain_text_email, tblUser.email_freq_id, > tblUser.email_freq_day_id, tblUser.privilege, tblUser.secure_id, > tblUser.activeyn, tblUser.login_attempts, tblUser.hashed_password, > tblUser.last_password_change, tblUser.forwarding_user_id, > tblUser.role_name FROM tblUser WHERE tblUser.id IN > ('102','103','104','105','106','107','108','109','110','111','112','113',' > 114','115','116','117','118','119','120','121','122','123','124','125','12 > 6','127','128','129','130','131','132','133','134','135','136','137','138' > ,'139','140','141','142','143','144','145','146','147','148','149','150',' > 151','152','153','154','155','156','157','158','159','160','161','162','16 > 3','164','165','166','167','168','169','170','171','172','173','174','175' > ,'176','177','178','179','180','181','182','183','184','185','186','187',' > 188','189','190','191','192','193','194','195','196','197','198','199','20 > 0','201','202','203','204','205','206','207','208','209','210','211','212' > ,'213','215','216','217','218','219','220','221','222','223','224','225',' > 226','227','228','229','230','231','233','235','236','237','238','239','24 > 0','241','242','243','244','245','246','247','249','250','251','252','253' > ,'254','255','256','257','258','259','260','261','262','263','264','265',' > 266','267','268','269','270','271','272','273','274','275','276','277','27 > 8','279','280','281','282','283','284','285','286','287','288','289','290' > ,'291','292','293','294','295','296','297','298','299','300','301','302',' > 303','304','305','306','307','308','309','310','311','312','313','315','31 > 6','317','318','319','320','321','322','323','324','325','326','327','328' > ,'329','331','333','334','335','336','337','338','339','340','341','342',' > 343','344','345','346','347','348','349','350','351','352','353','354','35 > 5','356','357','358'); > NOTICE: QUERY PLAN: Seq Scan on tbluser (cost=0.00..670.82 rows=221 width=3726) > (this is what our App server generates as part of the query, I KNOW the > IN() is not the most efficient, but it's working fine on a number of other > machines, the tbluser table is only 1000 rows, and with an index on the id > column). > > My suspicion is that a dump/restore on our production box may fix this > problem, but I'd rather know some more about this issue. Can anyone help > explain this issue? > > regards, > > _________________________ > Paul Smith > Lawlex Compliance Solutions > phone: +61 3 9278 1511 > email: paul.smith@lawlex.com.au > > From pgsql-performance-owner@postgresql.org Mon Jun 2 01:32:21 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 9D1679234DD for ; Mon, 2 Jun 2003 01:32:19 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 88696-05 for ; Mon, 2 Jun 2003 01:32:08 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by developer.postgresql.org (Postfix) with ESMTP id 0E4CE921B8C for ; Mon, 2 Jun 2003 01:31:37 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h525VRU6002116; Mon, 2 Jun 2003 01:31:27 -0400 (EDT) To: George Papastamatopoulos Cc: pgsql-performance@postgresql.org, Paul Smith Subject: Re: FW: Query Plan problem In-reply-to: <7395B46C07F8D51182AE000629570CC4804A31@IKE> References: <7395B46C07F8D51182AE000629570CC4804A31@IKE> Comments: In-reply-to George Papastamatopoulos message dated "Mon, 02 Jun 2003 14:56:18 +1000" Date: Mon, 02 Jun 2003 01:31:27 -0400 Message-ID: <2115.1054531887@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/9 X-Sequence-Number: 2093 George Papastamatopoulos writes: >> ... WHERE tblUser.id IN >> ('102','103','104','105','106','107','108','109','110','111','112','113',' >> 114','115','116','117','118','119','120','121','122','123','124','125','12 > ... What's the datatype of tblUser.id? What indexes do you have on the table? Also, are both databases built with the same locale/encoding support and initdb-time choices? What are they? regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jun 2 01:33:59 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 46009925BAD for ; Mon, 2 Jun 2003 01:33:56 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 88745-07 for ; Mon, 2 Jun 2003 01:33:45 -0400 (EDT) Received: from ns1.bee.lt (ns.bi.lt [213.226.131.131]) by developer.postgresql.org (Postfix) with ESMTP id 42F63924C3A for ; Mon, 2 Jun 2003 01:33:44 -0400 (EDT) Received: from B027543 (inet.bee.lt [213.226.131.30]) by ns1.bee.lt (8.11.6/8.11.6) with SMTP id h525Xgi11514 for ; Mon, 2 Jun 2003 08:33:43 +0300 Message-ID: <005a01c328c8$885b9760$f20214ac@bite.lt> From: "Mindaugas Riauba" To: Subject: Degrading performance Date: Mon, 2 Jun 2003 08:33:38 +0300 MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1257" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/10 X-Sequence-Number: 2094 Hello, I have table with slowly degrading performance. Table is special is such way that all its rows are updated every 5 minutes (routers interfaces). vacuum does not help. vacuum full does but I'd like to avoid it. Below I added explain analyze output before and after vacuum full. How could I make that table not to grow? PostgreSQL 7.3.2 on Redhat Linux 7.1. max_fsm_pages=10000 max_fsm_relations=1000. Mindaugas router_db=# explain analyze select * from ifdata; QUERY PLAN ---------------------------------------------------------------------------- ------------------------------- Seq Scan on ifdata (cost=0.00..4894.76 rows=776 width=133) (actual time=31.65..1006.76 rows=776 loops=1) Total runtime: 1007.72 msec (2 rows) router_db=# VACUUM full verbose ifdata; INFO: --Relation public.ifdata-- INFO: Pages 4887: Changed 0, reaped 4883, Empty 0, New 0; Tup 776: Vac 46029, Keep/VTL 0/0, UnUsed 186348, MinLen 130, MaxLen 216; Re-using: Free/Avail. Space 38871060/15072128; EndEmpty/Avail. Pages 2981/1895. CPU 0.33s/0.04u sec elapsed 0.45 sec. INFO: Index ifdata_clientid_key: Pages 2825; Tuples 776: Deleted 46029. CPU 0.23s/0.32u sec elapsed 1.98 sec. INFO: Rel ifdata: Pages: 4887 --> 17; Tuple(s) moved: 776. CPU 0.30s/0.35u sec elapsed 1.65 sec. INFO: Index ifdata_clientid_key: Pages 2825; Tuples 776: Deleted 776. CPU 0.21s/0.04u sec elapsed 0.29 sec. VACUUM router_db=# explain analyze select * from ifdata; QUERY PLAN ---------------------------------------------------------------------------- ------------------------- Seq Scan on ifdata (cost=0.00..24.76 rows=776 width=133) (actual time=0.03..7.53 rows=776 loops=1) Total runtime: 8.17 msec (2 rows) From pgsql-performance-owner@postgresql.org Mon Jun 2 01:38:01 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id B11A192625F for ; Mon, 2 Jun 2003 01:37:59 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 93429-01 for ; Mon, 2 Jun 2003 01:37:49 -0400 (EDT) Received: from ike.local.anstat.com.au (mole.anstat.com.au [202.92.123.11]) by developer.postgresql.org (Postfix) with ESMTP id 53EDC92628F for ; Mon, 2 Jun 2003 01:37:48 -0400 (EDT) Received: by IKE with Internet Mail Service (5.5.2655.55) id ; Mon, 2 Jun 2003 15:35:26 +1000 Message-ID: <7395B46C07F8D51182AE000629570CC4B2E180@IKE> From: Paul Smith To: 'Tom Lane' , George Papastamatopoulos Cc: pgsql-performance@postgresql.org, Paul Smith Subject: Re: FW: Query Plan problem Date: Mon, 2 Jun 2003 15:35:25 +1000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2655.55) Content-Type: text/plain; charset="iso-8859-1" X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/11 X-Sequence-Number: 2095 Thanks Tom for the reply (if you could reply all, as I'm not currently subscribed just yet). [Since our post, we've down an explicit vacuum on the tbluser.id column, and things are looking much much better, there were 0 rows in the pg_stats table for that table...] Incidently, tbluser.Id is a bigint (hence the '' wrapped around the in clause, otherwise the infamous postgres issue crops up not matching the Int literal number with the bigint index, and reverts to nasty table scan). Both our production and our dump/restore servers are UNICODE. Incidently, if I do a VACUUM Analyze on this table: comptoolkit=# VACUUM analyze tbluser; ERROR: Invalid UNICODE character sequence found (0xf8335c) Me thinks somehow there is a hashed_password with some dodgy characters, but I'm not sure how we'll find that row, or what we'll do with that when we find it. (Any thoughts?). Could be why statistics getting removed? ANy thoughts along this would be good, we're over the performance hump, but it's always nice to know more... cheers, Paul Smith > -----Original Message----- > From: Tom Lane [mailto:tgl@sss.pgh.pa.us] > Sent: Monday, 2 June 2003 3:31 PM > To: George Papastamatopoulos > Cc: pgsql-performance@postgresql.org; Paul Smith > Subject: Re: [PERFORM] FW: Query Plan problem > > > George Papastamatopoulos > writes: > >> ... WHERE tblUser.id IN > >> > ('102','103','104','105','106','107','108','109','110','111',' > 112','113',' > >> > 114','115','116','117','118','119','120','121','122','123','12 > 4','125','12 > > ... > > What's the datatype of tblUser.id? What indexes do you have on the > table? > > Also, are both databases built with the same locale/encoding support > and initdb-time choices? What are they? > > regards, tom lane > From pgsql-bugs-owner@postgresql.org Mon Jun 2 03:14:32 2003 X-Original-To: pgsql-bugs@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id D753792615E for ; Mon, 2 Jun 2003 03:14:28 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 07349-08 for ; Mon, 2 Jun 2003 03:14:18 -0400 (EDT) Received: from mail.quantium.net (b.ns.quantium.net [67.96.140.30]) by developer.postgresql.org (Postfix) with SMTP id 7EA26926072 for ; Mon, 2 Jun 2003 03:14:17 -0400 (EDT) Received: (qmail 30532 invoked from network); 2 Jun 2003 07:14:15 -0000 Received: from 20-pool1.ras10.coden-le3.alerondial.net (HELO dave.to) (206.149.128.20) by quantium.net with SMTP; 2 Jun 2003 07:14:15 -0000 Message-ID: <3EDAF956.9010307@dave.to> Date: Mon, 02 Jun 2003 01:14:30 -0600 From: Dave E Martin XXIII User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020623 Debian/1.0.0-0.woody.1 X-Accept-Language: en MIME-Version: 1.0 To: Bruno Wolff III Cc: pgsql-bugs@postgresql.org Subject: Re: Index speeds up one row table (why)? References: <3ED93338.80806@dave.to> <1054434573.11968.42.camel@jester> <3ED9A923.90500@dave.to> <20030601190409.GA7853@wolff.to> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/13 X-Sequence-Number: 6108 Bruno Wolff III wrote: >Maybe you should reconsider how badly you want the app to be totally database >agnostic? Using a sequence might be less of a contortion than using vacuum >a few times a minute. You are likely to have similar performance issues >with other databases, so this section of code may not turn out to be very >portable in any case. > > Maybe I can further abstract out the generate unique-id portion, Since unique-id generation does seem to be a pretty common database extension (for some reason...), and then provide a generic schema definition, and a postgresql specific one (along with whatever others I can drum up). The generic one will rely on the software to come up with the unique id in the fashion I'm currently doing. Speaking of which, is there a better way than what i'm currently doing (when the database doesn't have any such support)? I've heard of one method based on something like "select max(id)+1 from table" but this seems error prone, at the very least, you'd have to have a unique index, and be prepared to redo on failure, which could get messy if its a big transaction, and frequent if there is a lot of concurrent inserting going on. From pgsql-bugs-owner@postgresql.org Mon Jun 2 03:51:42 2003 X-Original-To: pgsql-bugs@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 51CF1926290 for ; Mon, 2 Jun 2003 03:51:37 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 14667-01 for ; Mon, 2 Jun 2003 03:51:26 -0400 (EDT) Received: from smtp.blueyonder.co.uk (pc-80-195-188-198-gl.blueyonder.co.uk [80.195.188.198]) by developer.postgresql.org (Postfix) with ESMTP id 8DAE992628A for ; Mon, 2 Jun 2003 03:51:25 -0400 (EDT) Received: from reddragon.localdomain ([127.0.0.1] helo=localhost) by smtp.blueyonder.co.uk with esmtp (Exim 4.10) id 19Mk6f-0006hU-00 for pgsql-bugs@postgresql.org; Mon, 02 Jun 2003 08:51:49 +0100 Date: Mon, 2 Jun 2003 08:51:49 +0100 (BST) From: Peter Childs X-X-Sender: peter@RedDragon.Childs Cc: pgsql-bugs@postgresql.org Subject: Re: Index speeds up one row table (why)? In-Reply-To: <3EDAF956.9010307@dave.to> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/14 X-Sequence-Number: 6109 On Mon, 2 Jun 2003, Dave E Martin XXIII wrote: > Bruno Wolff III wrote: > > >Maybe you should reconsider how badly you want the app to be totally database > >agnostic? Using a sequence might be less of a contortion than using vacuum > >a few times a minute. You are likely to have similar performance issues > >with other databases, so this section of code may not turn out to be very > >portable in any case. > > > > > Maybe I can further abstract out the generate unique-id portion, Since > unique-id generation does seem to be a pretty common database extension > (for some reason...), and then provide a generic schema definition, and > a postgresql specific one (along with whatever others I can drum up). > The generic one will rely on the software to come up with the unique id > in the fashion I'm currently doing. > > Speaking of which, is there a better way than what i'm currently doing > (when the database doesn't have any such support)? I've heard of one > method based on something like "select max(id)+1 from table" but this > seems error prone, at the very least, you'd have to have a unique index, > and be prepared to redo on failure, which could get messy if its a big > transaction, and frequent if there is a lot of concurrent inserting > going on. > For a generic solution you could have an extra table that fed you ids and update it every time you took a value. (Maybe a trigger could be used?) Due to table locking during transactions no two concurrent requested would get the same answer. Implementation could be interesting but relatively simple. BEGIN; SELECT id from unqid where name='seq_name'; UPDATE unqid set id=id+1 where name='seq_name'; COMMIT; Peter Childs From pgsql-performance-owner@postgresql.org Mon Jun 2 09:36:47 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 54AC1925B2B for ; Mon, 2 Jun 2003 09:36:45 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 88458-06 for ; Mon, 2 Jun 2003 09:36:34 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by developer.postgresql.org (Postfix) with ESMTP id 84BBC925202 for ; Mon, 2 Jun 2003 09:36:34 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h52DaWU6007851; Mon, 2 Jun 2003 09:36:32 -0400 (EDT) To: "Mindaugas Riauba" Cc: pgsql-performance@postgresql.org Subject: Re: Degrading performance In-reply-to: <005a01c328c8$885b9760$f20214ac@bite.lt> References: <005a01c328c8$885b9760$f20214ac@bite.lt> Comments: In-reply-to "Mindaugas Riauba" message dated "Mon, 02 Jun 2003 08:33:38 +0300" Date: Mon, 02 Jun 2003 09:36:31 -0400 Message-ID: <7850.1054560991@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/12 X-Sequence-Number: 2096 "Mindaugas Riauba" writes: > I have table with slowly degrading performance. Table is special is > such way that all its rows are updated every 5 minutes (routers interfaces). > vacuum does not help. vacuum full does but I'd like to avoid it. VACUUM will do the trick, you just need to do it every five minutes or so. I suggest a cron job to vacuum just the one table. > INFO: Rel ifdata: Pages: 4887 --> 17; Tuple(s) moved: 776. > CPU 0.30s/0.35u sec elapsed 1.65 sec. That says you waited way too long to vacuum --- over two hundred update cycles, evidently. regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jun 2 11:38:02 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id C949B926411 for ; Mon, 2 Jun 2003 11:37:59 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 10807-07 for ; Mon, 2 Jun 2003 11:37:49 -0400 (EDT) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by developer.postgresql.org (Postfix) with ESMTP id EFBC69263B0 for ; Mon, 2 Jun 2003 11:37:48 -0400 (EDT) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h52FamWf003727; Mon, 2 Jun 2003 09:37:02 -0600 (MDT) Date: Mon, 2 Jun 2003 09:20:28 -0600 (MDT) From: "scott.marlowe" To: Robert Creager Cc: pgsql-performance Subject: Re: Enabling and Disabling Sequencial Scan In-Reply-To: <20030530212846.26a82109.Robert_Creager@LogicalChaos.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailScanner: Found to be clean X-MailScanner-SpamCheck: X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/13 X-Sequence-Number: 2097 On Fri, 30 May 2003, Robert Creager wrote: > On Fri, 30 May 2003 14:46:12 -0600 (MDT) > "scott.marlowe" said something like: > > > > > level cache is. On my machine it's about 800 meg. It's measured in 8k > blocks, so 100,000 * 8k ~ 800 meg. The smaller this is, the more > > Any thoughts on how to figure this out (disk buffer size)? For some > reason, my system (2xAMD 2800+, 2Gb RAM 2.4.21 - /proc/meminfo) only > shows a usage of 88kb of 'Buffers' usage, and that never changes. My > 'Cached' usage is 1.7Gb. I've hit the kernel mailing list, and the one > response I got said don't worry about it :-( Are you sure that's not 88213Kb or so of buffers? 88kb is awfully small. It's normal to have a cache size many times larger than the buffer size. Buffers are assigned to individual disks, and sit under the larger single pool that is the cache. I just take the approximate size of the cache under load and use that for the effective_cache_size. Since it's pretty much a "fudge factor" variable anyway. P.s. My use of the term fudge factor here is in no way meant to be derogatory. It's just that as long as the effective cache size is within some reasonable range of the actual cache/buffer in the machine, it'll be close enough to push the query planner in the right direction. Note that you can adopt two philosophies on the planner. One is that the planner will always make certain mistakes, and you've got to fool it in order to get the right query plan. The other philosophy is that you give the query planner all the variables you can reasonably give it to let it decide the proper course of action, and you fine tune each one so that eventually it makes the right choice for all the querys you throw at it. While the first philosophy provides for the fastest functional solutions on a static platform (i.e. we're running postgresql 7.0.2 and aren't going to upgrade.) but it kind of supports the idea that the query planner can never be given the right information and programmed with the right code to make the right decision 99% of the time, and when it makes the wrong decision, it's only a little wrong. The second choice will require you to spend more time fine tuning all the parameters fed to the query planner with your own queries using explain analyze and repeated testing with different settings. What I look for are the corner cases. I.e. if I do some select that returns 500 records with a seq scan, and it takes 5 seconds, and with 450 records it switches to index scan and takes 1 second, then likely the planner is choosing to switch to seq scans too quickly when I raise the result size from 450 to 500. At this point use the set seq_scan option to test the database performance with it on and off and increasing set size. Somewhere around 2,000 or so in this scenario, we'll notice that the seq scan has now the same speed as the index scan, and as we raise the number of rows we are getting, the index scan would now be slower than the seq scan. Assuming we set effective_cache_size right at the beginning, we now can turn seq_scan back on, and adjust the default cost options until the planner chooses a seq scan at the break point we found (in our imaginary case of 2000). It doesn't have to be perfect, since the performance at or around the break point is similar for index and seq scans alike. Then, throw the next query at it and see how it does. I've found that on fast machines, it's good to lower the cpu costs, especially the index one. I usually drop these by a divisor of 2 to 10. For the random_page_cost, settings of 1.x to 2.x seem a good choice for fast I/O subsystems. From pgsql-performance-owner@postgresql.org Mon Jun 2 11:40:45 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 350F992642F for ; Mon, 2 Jun 2003 11:40:42 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 11754-01 for ; Mon, 2 Jun 2003 11:40:31 -0400 (EDT) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by developer.postgresql.org (Postfix) with ESMTP id 453C19263B0 for ; Mon, 2 Jun 2003 11:40:31 -0400 (EDT) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h52FdUWf003894; Mon, 2 Jun 2003 09:39:30 -0600 (MDT) Date: Mon, 2 Jun 2003 09:23:11 -0600 (MDT) From: "scott.marlowe" To: Robert Creager Cc: pgsql-performance Subject: Re: Enabling and Disabling Sequencial Scan In-Reply-To: <20030530212846.26a82109.Robert_Creager@LogicalChaos.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailScanner: Found to be clean X-MailScanner-SpamCheck: X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/14 X-Sequence-Number: 2098 On Fri, 30 May 2003, Robert Creager wrote: > On Fri, 30 May 2003 14:46:12 -0600 (MDT) > "scott.marlowe" said something like: > > > > > level cache is. On my machine it's about 800 meg. It's measured in 8k > > blocks, so 100,000 * 8k ~ 800 meg. The smaller this is, the more > > My 'Cached' usage is 1.7Gb. I've hit the kernel mailing list, and the > one response I got said don't worry about it :-( Oh, yeah, just a bit on that. as far as the kernel developers are concerned, the buffer / cache is working perfectly, and they're right, it is. What they probably don't understand if your need to tell postgresql how much cache/buffer is allocated to it. so don't worry about the kernel, the linux kernel really is pretty good at caching disk access. From pgsql-performance-owner@postgresql.org Mon Jun 2 12:55:57 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 007CE92645A for ; Mon, 2 Jun 2003 12:55:57 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 25994-05 for ; Mon, 2 Jun 2003 12:55:46 -0400 (EDT) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by developer.postgresql.org (Postfix) with ESMTP id 1D91C926489 for ; Mon, 2 Jun 2003 12:52:43 -0400 (EDT) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h52Gp3Wf010720; Mon, 2 Jun 2003 10:51:03 -0600 (MDT) Date: Mon, 2 Jun 2003 10:34:43 -0600 (MDT) From: "scott.marlowe" To: Tom Lane Cc: Mindaugas Riauba , Subject: Re: Degrading performance In-Reply-To: <7850.1054560991@sss.pgh.pa.us> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailScanner: Found to be clean X-MailScanner-SpamCheck: X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/15 X-Sequence-Number: 2099 On Mon, 2 Jun 2003, Tom Lane wrote: > "Mindaugas Riauba" writes: > > I have table with slowly degrading performance. Table is special is > > such way that all its rows are updated every 5 minutes (routers interfaces). > > vacuum does not help. vacuum full does but I'd like to avoid it. > > VACUUM will do the trick, you just need to do it every five minutes or > so. I suggest a cron job to vacuum just the one table. > > > INFO: Rel ifdata: Pages: 4887 --> 17; Tuple(s) moved: 776. > > CPU 0.30s/0.35u sec elapsed 1.65 sec. > > That says you waited way too long to vacuum --- over two hundred update > cycles, evidently. Don't forget to crank up your fsm settings in $PGDATA/postgresql.conf as well. From pgsql-performance-owner@postgresql.org Mon Jun 2 13:26:24 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 7DBB89258E4 for ; Mon, 2 Jun 2003 13:26:18 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 39050-02 for ; Mon, 2 Jun 2003 13:26:06 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by developer.postgresql.org (Postfix) with ESMTP id 344AF92644E for ; Mon, 2 Jun 2003 13:25:42 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h52HPNU6009539; Mon, 2 Jun 2003 13:25:23 -0400 (EDT) To: "scott.marlowe" Cc: Mindaugas Riauba , pgsql-performance@postgresql.org Subject: Re: Degrading performance In-reply-to: References: Comments: In-reply-to "scott.marlowe" message dated "Mon, 02 Jun 2003 10:34:43 -0600" Date: Mon, 02 Jun 2003 13:25:22 -0400 Message-ID: <9538.1054574722@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/16 X-Sequence-Number: 2100 "scott.marlowe" writes: > On Mon, 2 Jun 2003, Tom Lane wrote: >>> INFO: Rel ifdata: Pages: 4887 --> 17; Tuple(s) moved: 776. >>> CPU 0.30s/0.35u sec elapsed 1.65 sec. >> >> That says you waited way too long to vacuum --- over two hundred update >> cycles, evidently. > Don't forget to crank up your fsm settings in $PGDATA/postgresql.conf as > well. The table's not very big though. As long as he keeps after it with sufficiently-frequent vacuuming, it won't need much FSM space. regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jun 2 14:00:54 2003 X-Original-To: pgsql-performance@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id CEAC89264A3 for ; Mon, 2 Jun 2003 14:00:53 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 48124-06 for ; Mon, 2 Jun 2003 14:00:43 -0400 (EDT) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by developer.postgresql.org (Postfix) with ESMTP id 97B1292645F for ; Mon, 2 Jun 2003 14:00:42 -0400 (EDT) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h52Hx8Wf017419; Mon, 2 Jun 2003 11:59:09 -0600 (MDT) Date: Mon, 2 Jun 2003 11:42:48 -0600 (MDT) From: "scott.marlowe" To: Tom Lane Cc: Mindaugas Riauba , Subject: Re: Degrading performance In-Reply-To: <9538.1054574722@sss.pgh.pa.us> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailScanner: Found to be clean X-MailScanner-SpamCheck: X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/17 X-Sequence-Number: 2101 On Mon, 2 Jun 2003, Tom Lane wrote: > "scott.marlowe" writes: > > On Mon, 2 Jun 2003, Tom Lane wrote: > >>> INFO: Rel ifdata: Pages: 4887 --> 17; Tuple(s) moved: 776. > >>> CPU 0.30s/0.35u sec elapsed 1.65 sec. > >> > >> That says you waited way too long to vacuum --- over two hundred update > >> cycles, evidently. > > > Don't forget to crank up your fsm settings in $PGDATA/postgresql.conf as > > well. > > The table's not very big though. As long as he keeps after it with > sufficiently-frequent vacuuming, it won't need much FSM space. Yeah, but I got the feeling he was updating like 40 rows a second or something. Sufficiently frequent for him may well be constant. :-) From pgsql-performance-owner@postgresql.org Thu Jun 5 15:59:12 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 72B36EFFFB for ; Thu, 5 Jun 2003 15:35:33 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 17511-03 for ; Thu, 5 Jun 2003 15:35:32 +0000 (GMT) Received: from imo-r01.mx.aol.com (imo-r01.mx.aol.com [152.163.225.97]) by svr1.postgresql.org (Postfix) with ESMTP id 99BB6EFFBA for ; Thu, 5 Jun 2003 15:35:31 +0000 (GMT) Received: from yusuf0478@netscape.net by imo-r01.mx.aol.com (mail_out_v36.3.) id k.c7.7dbf16e (16237) for ; Thu, 5 Jun 2003 11:35:23 -0400 (EDT) Received: from netscape.net (66-163-11-108.ip.tor.radiant.net [66.163.11.108]) by air-in03.mx.aol.com (v93.12) with ESMTP id MAILININ31-3f6d3edf633a17b; Thu, 05 Jun 2003 11:35:22 2000 Message-ID: <3EDF633A.8000502@netscape.net> Date: Thu, 05 Jun 2003 11:35:22 -0400 From: Yusuf User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance Subject: Enabling and disabling run time configuration parameters. Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Mailer: Unknown (No Version) X-Spam-Status: No, hits=0.6 tagged_above=0.0 required=5.0 tests=FROM_ENDS_IN_NUMS, USER_AGENT_MOZILLA_UA, X_ACCEPT_LANG X-Spam-Level: * X-Archive-Number: 200306/18 X-Sequence-Number: 2102 I have discovered that I could optimize queries by adjusting the following parameters such as enable_seqscan, enable_hashjoin, enable_mergejoin and enable_nestloop. Is it a good idea, to temporarily adjust those values before running a query to spend up the execution time? I've searched online and wasn't able to find articles about it. I need to speed up an enterprise application that I'm working on, and I wouldn't want to screw things up. My plan is for every query that could be optimized by adjusting parameters: I'll enable parameters that'll speed it up, run the query, then set the parameters back to their default values. Thanks in advance. From pgsql-performance-owner@postgresql.org Fri Jun 6 06:45:52 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 74F2AEFF3C for ; Thu, 5 Jun 2003 16:14:21 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 25097-02 for ; Thu, 5 Jun 2003 16:14:20 +0000 (GMT) Received: from mailav.tor1.inquent.com (mail.inquent.com [216.208.117.106]) by svr1.postgresql.org (Postfix) with ESMTP id 07E98EFF3A for ; Thu, 5 Jun 2003 16:14:20 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by mailav.tor1.inquent.com (Postfix) with ESMTP id 2BD2E1025C; Thu, 5 Jun 2003 12:08:25 -0400 (EDT) Received: from [10.0.2.10] (unknown [10.0.2.10]) by mailav.tor1.inquent.com (Postfix) with ESMTP id 4C8791024D; Thu, 5 Jun 2003 12:08:23 -0400 (EDT) Subject: Re: Enabling and disabling run time configuration parameters. From: Rod Taylor To: Yusuf Cc: pgsql-performance In-Reply-To: <3EDF633A.8000502@netscape.net> References: <3EDF633A.8000502@netscape.net> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-SgA/N4Hooa66+N8muCgQ" Organization: Message-Id: <1054829663.7579.38.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.4 Date: 05 Jun 2003 12:14:23 -0400 X-Virus-Scanned: by AMaViS perl-11 X-Archive-Number: 200306/22 X-Sequence-Number: 2106 --=-SgA/N4Hooa66+N8muCgQ Content-Type: text/plain Content-Transfer-Encoding: quoted-printable > My plan is for every query that could be optimized by adjusting=20 > parameters: I'll enable parameters that'll speed it up, run the query,=20 > then set the parameters back to their default values. Unless you intend to regularly test these, or have static data this may cause you more problems than it fixes. Any change in the data may make the plan you have forced a non-optimal one. A much better approach is to tweek the cost values that cause the planner to chose that particular plan. The random_page_cost will probably have the most effect on the plan chosen. #effective_cache_size =3D 1000 # typically 8KB each #random_page_cost =3D 4 # units are one sequential page fetch cost #cpu_tuple_cost =3D 0.01 # (same) #cpu_index_tuple_cost =3D 0.001 # (same) #cpu_operator_cost =3D 0.0025 # (same) --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-SgA/N4Hooa66+N8muCgQ Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA+32xe6DETLow6vwwRAl+3AJ9Y4NhTUcOhEaE8tt2+O3xdoC6TRQCfY8A0 N1+D3Ykdbhx68ruwooNq7qs= =EqO3 -----END PGP SIGNATURE----- --=-SgA/N4Hooa66+N8muCgQ-- From pgsql-performance-owner@postgresql.org Fri Jun 6 06:46:30 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id BCCF6EFF8E for ; Thu, 5 Jun 2003 16:12:36 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 24470-08 for ; Thu, 5 Jun 2003 16:12:32 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id D659CEFEC4 for ; Thu, 5 Jun 2003 16:12:31 +0000 (GMT) Received: (qmail 22155 invoked by uid 500); 5 Jun 2003 16:15:02 -0000 Date: Thu, 5 Jun 2003 11:15:02 -0500 From: Bruno Wolff III To: Yusuf Cc: pgsql-performance Subject: Re: Enabling and disabling run time configuration parameters. Message-ID: <20030605161502.GA22114@wolff.to> Mail-Followup-To: Yusuf , pgsql-performance References: <3EDF633A.8000502@netscape.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3EDF633A.8000502@netscape.net> User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/23 X-Sequence-Number: 2107 On Thu, Jun 05, 2003 at 11:35:22 -0400, Yusuf wrote: > I have discovered that I could optimize queries by adjusting the > following parameters such as enable_seqscan, enable_hashjoin, > enable_mergejoin and enable_nestloop. > > Is it a good idea, to temporarily adjust those values before running a > query to spend up the execution time? I've searched online and wasn't > able to find articles about it. That is a reasonable thing to do. However you should also look into adjusting some of the costs used by the planner so that it gets the right plan more often. If you manually hack how the query is done, then you have to worry about whether the hack is still right if the the data changes significantly. > I need to speed up an enterprise application that I'm working on, and I > wouldn't want to screw things up. There worst that would happen is that the plan you forced it to use was slower than what the planner would have used. > My plan is for every query that could be optimized by adjusting > parameters: I'll enable parameters that'll speed it up, run the query, > then set the parameters back to their default values. They only apply to the current backend session. You can also set them for just the current transaction which is safer if you are using persistant backend connections. (So that if you make a mistake the setting doesn't apply for a very long time.) From pgsql-performance-owner@postgresql.org Fri Jun 6 06:08:20 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 8080AEFF46 for ; Thu, 5 Jun 2003 16:20:33 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 25510-03 for ; Thu, 5 Jun 2003 16:20:32 +0000 (GMT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id A31A9EFEC4 for ; Thu, 5 Jun 2003 16:20:31 +0000 (GMT) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3094529; Thu, 05 Jun 2003 09:20:32 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: Yusuf , pgsql-performance Subject: Re: Enabling and disabling run time configuration parameters. Date: Thu, 5 Jun 2003 09:19:10 -0700 User-Agent: KMail/1.4.3 References: <3EDF633A.8000502@netscape.net> In-Reply-To: <3EDF633A.8000502@netscape.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200306050919.10717.josh@agliodbs.com> X-Archive-Number: 200306/21 X-Sequence-Number: 2105 Yusuf, > Is it a good idea, to temporarily adjust those values before running a > query to spend up the execution time? I've searched online and wasn't > able to find articles about it. No. The "enable_%" vars are intended as settings for *testing*, to tell you if you have a problem with your query structure or indexing, cost variables, or are in need of a VACUUM. Using them in a production capacity is a bad idea, because you haven't addressed the problem that was causing the query to be slow in the first place, and as your database changes over time your queries will become slow again. Adhjusting the *cost* variables is a good idea. Find you need ENABLE_SEQSCAN=FALSE a lot? Raise your cache_size and lower your random_tuple_cost variables, among other adjustments. For further adjustments, post some of your "bad queries" to this list. Be sure to include *all* of the following: 1) VACUUM FULL ANALYZE before testing. 2) Include the full query. 3) Include the EXPLAIN ANALYZE results of the query. 4) Include (possibly as a text attachment) the schema of relevant tables, including (especially!) indexes. -- Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Fri Jun 6 04:53:07 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 30DE7EFF8E for ; Thu, 5 Jun 2003 16:39:36 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 29897-07 for ; Thu, 5 Jun 2003 16:39:34 +0000 (GMT) Received: from mail.libertyrms.com (unknown [209.167.124.227]) by svr1.postgresql.org (Postfix) with ESMTP id 53F9AEFF8D for ; Thu, 5 Jun 2003 16:39:34 +0000 (GMT) Received: from [10.1.2.130] (helo=dba2) by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) id 19Nxm3-0000O1-00 for ; Thu, 05 Jun 2003 12:39:35 -0400 Received: by dba2 (Postfix, from userid 1019) id 3F0BED763; Thu, 5 Jun 2003 12:39:34 -0400 (EDT) Date: Thu, 5 Jun 2003 12:39:34 -0400 From: Andrew Sullivan To: pgsql-performance Subject: Re: Enabling and disabling run time configuration parameters. Message-ID: <20030605163934.GE4178@libertyrms.info> Mail-Followup-To: Andrew Sullivan , pgsql-performance References: <3EDF633A.8000502@netscape.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3EDF633A.8000502@netscape.net> User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/20 X-Sequence-Number: 2104 On Thu, Jun 05, 2003 at 11:35:22AM -0400, Yusuf wrote: > I have discovered that I could optimize queries by adjusting the > following parameters such as enable_seqscan, enable_hashjoin, > enable_mergejoin and enable_nestloop. > > Is it a good idea, to temporarily adjust those values before running a > query to spend up the execution time? I've searched online and wasn't > able to find articles about it. It sounds like you need more general tuning. If the planner is making mistakes, it'd be nice to know about it. Could you post some details? A -- ---- Andrew Sullivan 204-4141 Yonge Street Liberty RMS Toronto, Ontario Canada M2P 2A8 +1 416 646 3304 x110 From pgsql-performance-owner@postgresql.org Fri Jun 6 03:57:05 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id B4ED5EFF8E for ; Thu, 5 Jun 2003 17:00:30 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 35938-02 for ; Thu, 5 Jun 2003 17:00:29 +0000 (GMT) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by svr1.postgresql.org (Postfix) with ESMTP id 15B46EFF7C for ; Thu, 5 Jun 2003 17:00:29 +0000 (GMT) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h55GxT6m008730; Thu, 5 Jun 2003 10:59:29 -0600 (MDT) Date: Thu, 5 Jun 2003 10:42:01 -0600 (MDT) From: "scott.marlowe" To: Yusuf Cc: pgsql-performance Subject: Re: Enabling and disabling run time configuration parameters. In-Reply-To: <3EDF633A.8000502@netscape.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailScanner: Found to be clean X-MailScanner-SpamCheck: X-Archive-Number: 200306/19 X-Sequence-Number: 2103 On Thu, 5 Jun 2003, Yusuf wrote: > I have discovered that I could optimize queries by adjusting the > following parameters such as enable_seqscan, enable_hashjoin, > enable_mergejoin and enable_nestloop. Setting those to get a fast query is the brute force method. It works, but at some cost of flexibility. Have you run vacuum full and analyze? If not, the planner has no clue how to decide on which plans to choose. > Is it a good idea, to temporarily adjust those values before running a > query to spend up the execution time? I've searched online and wasn't > able to find articles about it. Yes, it's a great idea to do that in testing. No, it's a bad idea to rely on them in production. > I need to speed up an enterprise application that I'm working on, and I > wouldn't want to screw things up. Then you'll want to tune your databases cost estimates so it makes the right decision. > My plan is for every query that could be optimized by adjusting > parameters: I'll enable parameters that'll speed it up, run the query, > then set the parameters back to their default values. That's a good plan as long as you go the extra step of making the changes to the cost parameters so that the planner chooses correctly between the different options it has. Every server has different performance characteristics. A machine with 1 gig of RAM and 18 drives in a large RAID 1+0 is going to handle random page access a lot better than a machine with 256 Meg ram and a single IDE hard drive. The values you need to look at are these: random_page_cost cpu_index_tuple_cost cpu_operator_cost cpu_tuple_cost effective_cache_size They are covered in detail in the docs here: http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=runtime-config.html I'm gonna go offline and write a quick tutorial on tuning your database to your server. Look for a preliminary version today or tomorrow. Set effective cache size to approximately the size of all kernel cache buffer/pagesize (8192 for most pgsql setups). Then tune the *_cost options so the planner picks the right plan each time. From pgsql-performance-owner@postgresql.org Sat Jun 7 16:03:40 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id DEA5CEFFB0 for ; Fri, 6 Jun 2003 18:53:30 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 68521-08 for ; Fri, 6 Jun 2003 18:53:30 +0000 (GMT) Received: from imo-r01.mx.aol.com (imo-r01.mx.aol.com [152.163.225.97]) by svr1.postgresql.org (Postfix) with ESMTP id A45B7EFF9B for ; Fri, 6 Jun 2003 18:53:29 +0000 (GMT) Received: from yusuf0478@netscape.net by imo-r01.mx.aol.com (mail_out_v36.3.) id k.3.88f5d7b (16216) for ; Fri, 6 Jun 2003 14:53:25 -0400 (EDT) Received: from netscape.net (66-163-11-108.ip.tor.radiant.net [66.163.11.108]) by air-in01.mx.aol.com (v94.27) with ESMTP id MAILININ14-3f583ee0e32419a; Fri, 06 Jun 2003 14:53:24 -0400 Message-ID: <3EE0E322.50201@netscape.net> Date: Fri, 06 Jun 2003 14:53:22 -0400 From: Yusuf User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance Subject: [Fwd: Re: Enabling and disabling run time configuration parameters.] Content-Type: multipart/mixed; boundary="------------030801010800060509010101" X-Mailer: Unknown (No Version) X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=FROM_ENDS_IN_NUMS, FWD_MSG, USER_AGENT_MOZILLA_UA, X_ACCEPT_LANG X-Spam-Level: X-Archive-Number: 200306/24 X-Sequence-Number: 2108 --------------030801010800060509010101 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit --------- THE QUERY ---------------- select sum(item.charge) as currentCharges , sum(item.gst) as gst , sum(item.pst) as pst , sum(item.hst) as hst , sum(item.qst) as qst , sum(item.federaltax) as federalTax , sum(item.statetax) as stateTax , sum(item.localtax) as localTax , sum(item.othertax) as otherTax , consaccount.latePaymentCharge as latePaymentCharges , consaccount.PreviousBalance as balanceForward , consaccount.dateinserted as dateInserted , consaccount.userDateInserted as dateEntered , consaccount.issueDate as invoiceDate , consaccount.dueDate as dateDue , consaccount.consAccount_Id as consolidatedAccountId , consaccount.invoiceNumber as invoiceNumber , consaccountinfo.name as consolidatedAccountNumber , consaccount.vendor_Id as vendorId , consaccount.client_Id as clientId , consaccount.ponumber as ponumber , consaccount.ismanualentry as isManualEntry , consaccount_approvedby_user.approvedby_user_id as approved , consaccount_allocatedby_user.allocatedby_user_id as allocated , consaccount_paidby_user.paidby_user_id as paid , consaccountinfo.consaccountinfo_id as consAccountInfoId , consaccount_paidby_user.amountpaid as amountPaid from consaccount inner join consaccountinfo on consaccount.consAccountInfo_Id = consaccountinfo.ConsAccountInfo_Id left join consaccount_allocatedby_user on consaccount.consaccount_id = consaccount_allocatedby_user.consaccount_id left join consaccount_approvedby_user on consaccount.consaccount_id = consaccount_approvedby_user.consaccount_id left join consaccount_paidby_user on consaccount.consaccount_id = consaccount_paidby_user.consaccount_id inner join account on consaccount.consAccount_Id = account.ConsAccount_Id inner join phone on account.account_Id = phone.Account_Id inner join item on phone.phone_Id = item.Phone_Id where consaccount.consaccount_id in (36,37,38,40,41,42,43,44,45,48,16,49,50,15,14) group by consaccountinfo.name , consaccountinfo.consaccountinfo_id , consaccount.invoicenumber , consaccount.consaccount_id , consaccount.dateinserted , consaccount.userDateInserted , consaccount.duedate , consaccount.issuedate , consaccount.previousbalance , consaccount.latepaymentcharge , consaccount.vendor_id , consaccount.client_id , consaccount.ponumber , consaccount.ismanualentry , consaccount_approvedby_user.approvedby_user_id , consaccount_allocatedby_user.allocatedby_user_id , consaccount_paidby_user.paidby_user_id , consaccount.isManualEntry , consaccount_paidby_user.amountpaid order by consaccount.invoicenumber asc; ----------- THE QUERY PLAN ----------- QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=5938.90..5939.30 rows=161 width=256) (actual time=45187.21..45187.30 rows=15 loops=1) Sort Key: consaccount.invoicenumber -> Aggregate (cost=5820.52..5933.01 rows=161 width=256) (actual time=42859.84..45186.91 rows=15 loops=1) -> Group (cost=5820.52..5896.85 rows=1607 width=256) (actual time=42729.90..44465.25 rows=39078 loops=1) -> Sort (cost=5820.52..5824.54 rows=1607 width=256) (actual time=42729.85..43018.41 rows=39078 loops=1) Sort Key: consaccountinfo.name, consaccountinfo.consaccountinfo_id, consaccount.invoicenumber, consaccount.consaccount_id, consaccount.dateinserted, consaccount.userdateinserted, consaccount.duedate, consaccount.issuedate, consaccount.previousbalance, consaccount.latepaymentcharge, consaccount.vendor_id, consaccount.client_id, consaccount.ponumber, consaccount.ismanualentry, consaccount_approvedby_user.approvedby_user_id, consaccount_allocatedby_user.allocatedby_user_id, consaccount_paidby_user.paidby_user_id, consaccount_paidby_user.amountpaid -> Hash Join (cost=3208.20..5734.94 rows=1607 width=256) (actual time=7787.49..38027.69 rows=39078 loops=1) Hash Cond: ("outer".phone_id = "inner".phone_id) -> Seq Scan on item (cost=0.00..2140.77 rows=73177 width=95) (actual time=0.07..977.20 rows=73177 loops=1) -> Hash (cost=3200.10..3200.10 rows=3239 width=161) (actual time=7785.54..7785.54 rows=0 loops=1) -> Hash Join (cost=149.32..3200.10 rows=3239 width=161) (actual time=156.50..6589.78 rows=139977 loops=1) Hash Cond: ("outer".account_id = "inner".account_id) -> Seq Scan on phone (cost=0.00..2272.86 rows=147486 width=8) (actual time=0.12..1211.95 rows=147486 loops=1) -> Hash (cost=149.07..149.07 rows=103 width=153) (actual time=156.29..156.29 rows=0 loops=1) -> Hash Join (cost=51.60..149.07 rows=103 width=153) (actual time=13.62..128.92 rows=3412 loops=1) Hash Cond: ("outer".consaccount_id = "inner".consaccount_id) -> Seq Scan on account (cost=0.00..72.79 rows=4679 width=8) (actual time=0.02..36.21 rows=4679 loops=1) -> Hash (cost=51.56..51.56 rows=15 width=145) (actual time=7.27..7.27 rows=0 loops=1) -> Hash Join (cost=44.42..51.56 rows=15 width=145) (actual time=5.80..7.15 rows=15 loops=1) Hash Cond: ("outer".consaccount_id = "inner".consaccount_id) -> Hash Join (cost=44.41..51.48 rows=15 width=117) (actual time=5.71..6.76 rows=15 loops=1) Hash Cond: ("outer".consaccount_id = "inner".consaccount_id) -> Hash Join (cost=44.41..51.41 rows=15 width=109) (actual time=5.60..6.35 rows=15 loops=1) Hash Cond: ("outer".consaccount_id = "inner".consaccount_id) -> Merge Join (cost=43.40..50.32 rows=15 width=101) (actual time=5.37..5.82 rows=15 loops=1) Merge Cond: ("outer".consaccountinfo_id = "inner".consaccountinfo_id) -> Index Scan using consaccountinfo_pkey on consaccountinfo (cost=0.00..6.17 rows=197 width=18) (actual time=0.20..0.27 rows=7 loops=1) -> Sort (cost=43.40..43.44 rows=15 width=83) (actual time=5.06..5.15 rows=15 loops=1) Sort Key: consaccount.consaccountinfo_id -> Seq Scan on consaccount (cost=0.00..43.11 rows=15 width=83) (actual time=0.09..4.87 rows=15 loops=1) Filter: ((consaccount_id = 36) OR (consaccount_id = 37) OR (consaccount_id = 38) OR (consaccount_id = 40) OR (consaccount_id = 41) OR (consaccount_id = 42) OR (consaccount_id = 43) OR (consaccount_id = 44) OR (consaccount_id = 45) OR (consaccount_id = 48) OR (consaccount_id = 16) OR (consaccount_id = 49) OR (consaccount_id = 50) OR (consaccount_id = 15) OR (consaccount_id = 14)) -> Hash (cost=1.01..1.01 rows=1 width=8) (actual time=0.13..0.13 rows=0 loops=1) -> Seq Scan on consaccount_allocatedby_user (cost=0.00..1.01 rows=1 width=8) (actual time=0.09..0.10 rows=1 loops=1) -> Hash (cost=0.00..0.00 rows=1 width=8) (actual time=0.02..0.02 rows=0 loops=1) -> Seq Scan on consaccount_approvedby_user (cost=0.00..0.00 rows=1 width=8) (actual time=0.01..0.01 rows=0 loops=1) -> Hash (cost=0.00..0.00 rows=1 width=28) (actual time=0.02..0.02 rows=0 loops=1) -> Seq Scan on consaccount_paidby_user (cost=0.00..0.00 rows=1 width=28) (actual time=0.01..0.01 rows=0 loops=1) Total runtime: 45189.45 msec (38 rows) The total time when hashjoin=off and mergejoin=off is ~ 13.2 seconds ----------- ABOUT MY MACHINE ----------- The size of the database when I check PGDATA\base is about 400 MB FreeBSD Mem: 26M Active, 1695M Inact, 155M Wired, 52M Cache, 199M Buf, 82M Free Swap: 4080M Total, 8K Used, 4080M Free ----------- MY POSTGRES CONFIGURATION ----------- cpu_index_tuple_cost | 0.001 cpu_operator_cost | 0.0025 cpu_tuple_cost | 0.01 effective_cache_size | 1000 enable_hashjoin | on enable_indexscan | on enable_mergejoin | on enable_nestloop | on enable_seqscan | on enable_sort | on max_connections | 40 shared_buffers | 500 sort_mem | 1024 random_page_cost | 4 What should I set the config parameters to be, to improve performance? I've attached my schema. --------------030801010800060509010101 Content-Type: text/plain; name="schema.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="schema.txt" -- TABLES -- CONSACCOUNTINFO { consaccountinfo_id serial primary key, description } - has about 200 records CONSACCOUNT { consaccount_id serial primary key, consaccountinfo_id integer references Consaccountinfo(consaccountinfo_id), } - 700 records ACCOUNT { account_id serial primary key, consaccount_id integer references Consaccount(consaccount_id), ... } - 4700 records PHONE { phone_id serial primary key, account_id integer references account(account_id), ... } - 150 000 records - index on account_id ITEM { item_id serial primary key phone_id integer references phone(phone_id), ... } - 70 000 records - index on phone_id CONSACCOUNT_ALLOCATED { consaccount_id integer references Consaccount(consaccount_id), ... } - 1 record CONSACCOUNT_APPROVED{ consaccount_id integer references Consaccount(consaccount_id), ... } - 2 records CONSACCOUNT_PAID{ consaccount_id integer references Consaccount(consaccount_id), ... } - 2 records --------------030801010800060509010101-- From pgsql-performance-owner@postgresql.org Tue Jun 10 02:09:51 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id BBE7630F825 for ; Tue, 10 Jun 2003 05:09:48 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 27513-01 for ; Tue, 10 Jun 2003 02:09:38 -0300 (ADT) Received: from lewexch.lewis-stores.com (mail.lewis-stores.com [196.31.249.242]) by svr1.postgresql.org (Postfix) with ESMTP id B786530F584 for ; Mon, 9 Jun 2003 09:23:49 +0000 (GMT) Received: by LEWEXCH with Internet Mail Service (5.5.2650.21) id ; Mon, 9 Jun 2003 11:19:34 +0200 Message-ID: From: Howard Oblowitz To: pgsql-performance@postgresql.org Cc: rune.lending@inpoc.com Subject: FW: [ADMIN] Shared_buffers and kernel parameters, tuning Date: Mon, 9 Jun 2003 11:18:47 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain X-Archive-Number: 200306/26 X-Sequence-Number: 2110 > -----Original Message----- > From: Lending, Rune [SMTP:rune.lending@inpoc.com] > Sent: 05 June 2003 10:11 > To: 'pgsql-admin@postgresql.org' > Subject: [ADMIN] Shared_buffers and kernel parameters, tuning > > After days of searching and testing I have come up with this way of > configuring our postgresql 7.2 db. > I have not yet increased my shared_buffer as high as suggested below on > our > prod machine (24-7 high traffic), but after testing on our dev machines > this allows at least the databse to start up. It is very difficult to test > the actual performance since there is a hugh difference in traffic on dev > and prod. > Here is what we have: > > We have a high traffic system with a database described as followed: > > 4 pentium 3 633 cpu's > 3753456 kB RAM (3.5 Gb) > Red Hat Linux 7.2 > postgresql 7.2 > > > What I like to do is: > > /proc/sys/kernel/sem=250 32000 100 500 (after advise from forum/docs) > /proc/sys/kernel/shmmax=1921769472 (RAM / 2 * 1024 - this > piece of math I got from some of oracle's support pages (ooopps) actually > ) > > /proc/sys/kernel/shmall=1921769472 (RAM / 2 * 1024) > > in postgresql.conf: > > shared_buffers = 117248 (shmmax / 2 / 1024 / 8 ) This I got from this > forum. > > > Does this sound right or am I totally out of bounds here? I have, as said > before done this on our dev macine ( a lot smaller machine ), but it would > be nice with some feedback .. > > Thanx in advance for response. > > /rune > > From pgsql-performance-owner@postgresql.org Tue Jun 10 01:52:06 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 34551313746 for ; Tue, 10 Jun 2003 04:51:47 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 23659-08 for ; Tue, 10 Jun 2003 01:51:35 -0300 (ADT) Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) by svr1.postgresql.org (Postfix) with SMTP id 9E22830DE57 for ; Mon, 9 Jun 2003 20:40:09 +0000 (GMT) Received: (qmail 92813 invoked by uid 1001); 9 Jun 2003 20:40:09 -0000 Date: Mon, 9 Jun 2003 15:40:09 -0500 From: "Jim C. Nasby" To: pgsql-performance@postgresql.org Subject: Hash or merge join instead of inner loop Message-ID: <20030609204009.GJ40542@flake.decibel.org> Reply-To: jim@nasby.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 4.8-RELEASE i386 X-Distributed: Join the Effort! http://www.distributed.net X-Archive-Number: 200306/25 X-Sequence-Number: 2109 I have a query that's cauing pgsql choose either a hash or merge join depending on how I mess with the stats variables, but it won't choose an nested loop, even though it's the fastest. The estimate for the nested loop index scans always seems to be way high on the high end. Note that it's 0-3 in one case and 0-2 in the other, but the actual time is very low in both cases. Why is this? I haven't been able to make much of a difference by changing the optimizer variables. This is on a solaris machine, if that matters. Tinput_data, locality, and postal code have 1300, 28000 and 43000 rows, respectively, and locality and postal code are very narrow tables (full definition below). usps=# explain analyze SELECT key, pc.locality_id, l.state_code::varchar FROM Tinput_data i, postal_code pc, locality l WHERE i.zip = pc.postal_code AND l.locality_id = pc.locality_id; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=940.20..1417.94 rows=1380 width=36) (actual time=1727.30..2363.91 rows=1380 loops=1) Merge Cond: ("outer".locality_id = "inner".locality_id) -> Index Scan using locality_pkey on locality l (cost=0.00..455.99 rows=27789 width=10) (actual time=0.62..495.39 rows=27632 loops=1) -> Sort (cost=940.20..940.55 rows=1380 width=26) (actual time=1725.53..1726.71 rows=1380 loops=1) Sort Key: pc.locality_id -> Merge Join (cost=42.00..933.00 rows=1380 width=26) (actual time=56.27..1684.67 rows=1380 loops=1) Merge Cond: ("outer".postal_code = "inner".zip) -> Index Scan using postal_code_postal_code_key on postal_code pc (cost=0.00..869.31 rows=42704 width=13) (actual time=10.05..1396.11 rows=42418 loops=1) -> Sort (cost=42.00..42.34 rows=1380 width=13) (actual time=39.63..40.97 rows=1380 loops=1) Sort Key: i.zip -> Seq Scan on tinput_data i (cost=0.00..34.80 rows=1380 width=13) (actual time=0.02..12.13 rows=1380 loops=1) Total runtime: 2367.50 msec (12 rows) usps=# set enable_mergejoin=0; SET usps=# set enable_hashjoin=0; SET usps=# explain analyze SELECT key, pc.locality_id, l.state_code::varchar FROM Tinput_data i, postal_code pc, locality l WHERE i.zip = pc.postal_code AND l.locality_id = pc.locality_id; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=0.00..6991.66 rows=1380 width=36) (actual time=0.22..231.00 rows=1380 loops=1) -> Nested Loop (cost=0.00..4203.23 rows=1380 width=26) (actual time=0.14..132.70 rows=1380 loops=1) -> Seq Scan on tinput_data i (cost=0.00..34.80 rows=1380 width=13) (actual time=0.02..17.41 rows=1380 loops=1) -> Index Scan using postal_code_postal_code_key on postal_code pc (cost=0.00..3.01 rows=1 width=13) (actual time=0.06..0.06 rows=1 loops=1380) Index Cond: ("outer".zip = pc.postal_code) -> Index Scan using locality_pkey on locality l (cost=0.00..2.01 rows=1 width=10) (actual time=0.05..0.05 rows=1 loops=1380) Index Cond: (l.locality_id = "outer".locality_id) Total runtime: 233.60 msec (8 rows) Table "pg_temp_1.tinput_data" Column | Type | Modifiers ------------------+-----------------------+----------- key | integer | not null firm | character varying(40) | address | integer | address_v | character varying(10) | odd_even | character(1) | street_name | character varying(40) | street_metaphone | character varying(4) | apartment | integer | apartment_v | character varying(10) | apartment_label | character varying(5) | city | character varying(40) | city_metaphone | character varying(4) | state | character varying(40) | zip | character varying(5) | Indexes: tinput_data_pkey primary key btree ("key") usps=# \d postal_code Table "public.postal_code" Column | Type | Modifiers ----------------+-----------------------+------------------------------------------------------------------------- postal_code_id | integer | not null default nextval('public.postal_code_postal_code_id_seq'::text) postal_code | character varying(10) | not null locality_id | integer | not null Indexes: postal_code_pkey primary key btree (postal_code_id), postal_code_postal_code_key unique btree (postal_code) usps=# \d locality Table "public.locality" Column | Type | Modifiers -------------+-----------------------+------------------------------------------------------------------- locality_id | integer | not null default nextval('public.locality_locality_id_seq'::text) locality | character varying(10) | not null state_code | character(2) | not null Indexes: locality_pkey primary key btree (locality_id) Foreign Key constraints: $1 FOREIGN KEY (state_code) REFERENCES state(state_code) ON UPDATE NO ACTION ON DELETE NO ACTION -- Jim C. Nasby (aka Decibel!) jim@nasby.net Member: Triangle Fraternity, Sports Car Club of America Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?" From pgsql-performance-owner@postgresql.org Tue Jun 10 03:39:55 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id B0DD2310BB7 for ; Tue, 10 Jun 2003 06:39:41 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 40759-07 for ; Tue, 10 Jun 2003 03:39:31 -0300 (ADT) Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id 33272313616 for ; Tue, 10 Jun 2003 02:16:22 -0300 (ADT) Received: (from root@localhost) by www.pspl.co.in (8.11.6/8.11.6) id h5A5GHI22531 for ; Tue, 10 Jun 2003 10:46:17 +0530 Received: from daithan (daithan.intranet.pspl.co.in [192.168.7.161]) by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h5A5GHQ22526 for ; Tue, 10 Jun 2003 10:46:17 +0530 From: "Shridhar Daithankar" To: pgsql-performance@postgresql.org Date: Tue, 10 Jun 2003 10:45:25 +0530 MIME-Version: 1.0 Subject: Re: FW: [ADMIN] Shared_buffers and kernel parameters, tuning Reply-To: shridhar_daithankar@persistent.co.in Message-ID: <3EE5B6C5.31892.7FE833A@localhost> In-reply-to: X-mailer: Pegasus Mail for Windows (v4.02) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Archive-Number: 200306/27 X-Sequence-Number: 2111 On 9 Jun 2003 at 11:18, Howard Oblowitz wrote: > > in postgresql.conf: > > > > shared_buffers = 117248 (shmmax / 2 / 1024 / 8 ) This I got from this > > forum. > > > > > > Does this sound right or am I totally out of bounds here? I have, as said > > before done this on our dev macine ( a lot smaller machine ), but it would > > be nice with some feedback .. With that kind of RAM and that kind of shared buffers setting, you must set effective OS cache size so that postgresql can calculate when to flush buffers. While tuning database, it always help to pin down the target first and then try to reach it. If you could let us know what performance you are expecting out of this machine and for what kind of load in terms of concurrent users, database size and usage pattern etc., that would help. HTH Bye Shridhar -- QOTD: "I'm just a boy named 'su'..." From pgsql-performance-owner@postgresql.org Tue Jun 10 05:14:02 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id B6DF0311030 for ; Tue, 10 Jun 2003 08:13:58 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 53193-08 for ; Tue, 10 Jun 2003 05:13:45 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 58E4630F881 for ; Tue, 10 Jun 2003 03:15:16 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5A6FBU6000275; Tue, 10 Jun 2003 02:15:11 -0400 (EDT) To: jim@nasby.net Cc: pgsql-performance@postgresql.org Subject: Re: Hash or merge join instead of inner loop In-reply-to: <20030609204009.GJ40542@flake.decibel.org> References: <20030609204009.GJ40542@flake.decibel.org> Comments: In-reply-to "Jim C. Nasby" message dated "Mon, 09 Jun 2003 15:40:09 -0500" Date: Tue, 10 Jun 2003 02:15:11 -0400 Message-ID: <274.1055225711@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/28 X-Sequence-Number: 2112 "Jim C. Nasby" writes: > I have a query that's cauing pgsql choose either a hash or merge join > depending on how I mess with the stats variables, but it won't choose an > nested loop, even though it's the fastest. There's been some discussion about that before; you could check the archives (now that they're up again ;-)). I believe that the planner overestimates the cost of a nestloop with inner indexscan, because it costs the indexscans as though each one is an independent ab-initio index search. In reality, most of the upper btree levels will no doubt stay in memory during such a query, and so this estimate charges many more reads than really occur. Fixing this is on the todo list, but no one's got to it yet. (It's not clear to me how to put the consideration into the planner's cost algorithms in a clean way.) regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jun 10 06:12:35 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id E6AB33109B6 for ; Tue, 10 Jun 2003 09:12:32 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 62871-04 for ; Tue, 10 Jun 2003 06:12:22 -0300 (ADT) Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id 8C328310B2A for ; Tue, 10 Jun 2003 05:57:09 -0300 (ADT) Received: (from root@localhost) by www.pspl.co.in (8.11.6/8.11.6) id h5A8v9l24061 for ; Tue, 10 Jun 2003 14:27:09 +0530 Received: from daithan (daithan.intranet.pspl.co.in [192.168.7.161]) by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h5A8v8Q24050 for ; Tue, 10 Jun 2003 14:27:09 +0530 From: "Shridhar Daithankar" To: pgsql-performance@postgresql.org Date: Tue, 10 Jun 2003 14:26:17 +0530 MIME-Version: 1.0 Subject: Re: Hash or merge join instead of inner loop Reply-To: shridhar_daithankar@persistent.co.in Message-ID: <3EE5EA89.19260.8C8B669@localhost> References: <20030609204009.GJ40542@flake.decibel.org> In-reply-to: <274.1055225711@sss.pgh.pa.us> X-mailer: Pegasus Mail for Windows (v4.02) Content-type: text/plain; charset=ISO-8859-1 Content-description: Mail message body Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from Quoted-printable to 8bit by www.pspl.co.in id h5A8v8Q24050 X-Archive-Number: 200306/29 X-Sequence-Number: 2113 On 10 Jun 2003 at 2:15, Tom Lane wrote: > There's been some discussion about that before; you could check the > archives (now that they're up again ;-)). I believe that the planner > overestimates the cost of a nestloop with inner indexscan, because it > costs the indexscans as though each one is an independent ab-initio > index search. In reality, most of the upper btree levels will no doubt > stay in memory during such a query, and so this estimate charges many > more reads than really occur. Fixing this is on the todo list, but no > one's got to it yet. (It's not clear to me how to put the consideration > into the planner's cost algorithms in a clean way.) Just being na�ve here, but if planner and executor account for shared buffers+effective OS cache, even a boolean choice could be a start. Say a query needs 100MB of data according to estimates so if shared buffers+effective OS cache covers that, we can lower the cost. May be we should have two config. parameters for tuple cost? Disk read tuple cost and memory read tuple cost. Later being 1/10th of former? Bye Shridhar -- All new: Parts not interchangeable with previous model. From pgsql-performance-owner@postgresql.org Tue Jun 10 12:48:27 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 2611B30DBF8 for ; Tue, 10 Jun 2003 15:48:27 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 04345-04 for ; Tue, 10 Jun 2003 12:48:16 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id 3BAD030DBDB for ; Tue, 10 Jun 2003 12:48:16 -0300 (ADT) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3108070; Tue, 10 Jun 2003 08:48:21 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: Howard Oblowitz , pgsql-performance@postgresql.org Subject: Re: FW: [ADMIN] Shared_buffers and kernel parameters, tuning Date: Tue, 10 Jun 2003 08:46:21 -0700 User-Agent: KMail/1.4.3 Cc: rune.lending@inpoc.com References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200306100846.21875.josh@agliodbs.com> X-Archive-Number: 200306/30 X-Sequence-Number: 2114 Rune, > > shared_buffers = 117248 (shmmax / 2 / 1024 / 8 ) This I got from this > > forum. > > Does this sound right or am I totally out of bounds here? I have, as said Out of bounds, through no fault of your own .... I'm still working on documentation for this. However, let me qoute the upcoming supplimentary docs: SHARED_BUFFERS Sets the size of Postgres' memory buffer where queries are held before being fed into the Kernel buffer of the host system. It's very important to remember that this is only a holding area, and not the total memory available for the server. As such, resist the urge to set this number to a large portion of your RAM, as this will actually degrade performance on many OSes. Members of the pgsql-performance mailing list have found useful values in the range of 1000-6000, depending on available RAM, database size, and number of concurrent queries. No one has yet reported positive results for any number over 6000. -- Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Tue Jun 10 12:57:56 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1EFF230E3C6 for ; Tue, 10 Jun 2003 15:57:55 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 00729-10 for ; Tue, 10 Jun 2003 12:57:44 -0300 (ADT) Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id C0F9330DBF8 for ; Tue, 10 Jun 2003 12:57:41 -0300 (ADT) Received: (from root@localhost) by www.pspl.co.in (8.11.6/8.11.6) id h5AFveo25618 for ; Tue, 10 Jun 2003 21:27:40 +0530 Received: from daithan (daithan.intranet.pspl.co.in [192.168.7.161]) by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h5AFvd925613 for ; Tue, 10 Jun 2003 21:27:40 +0530 From: "Shridhar Daithankar" To: pgsql-performance@postgresql.org Date: Tue, 10 Jun 2003 21:26:49 +0530 MIME-Version: 1.0 Subject: Re: FW: [ADMIN] Shared_buffers and kernel parameters, tuning Reply-To: shridhar_daithankar@persistent.co.in Message-ID: <3EE64D19.30310.9E8DA9@localhost> References: In-reply-to: <200306100846.21875.josh@agliodbs.com> X-mailer: Pegasus Mail for Windows (v4.02) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Archive-Number: 200306/31 X-Sequence-Number: 2115 On 10 Jun 2003 at 8:46, Josh Berkus wrote: > SHARED_BUFFERS > Sets the size of Postgres' memory buffer where queries are held before being > fed into the Kernel buffer of the host system. It's very important to > remember that this is only a holding area, and not the total memory available > for the server. As such, resist the urge to set this number to a large > portion of your RAM, as this will actually degrade performance on many OSes. > Members of the pgsql-performance mailing list have found useful values in the > range of 1000-6000, depending on available RAM, database size, and number of > concurrent queries. No one has yet reported positive results for any number > over 6000. I was planning to document postgresql.conf with little hints, enough to get one started, drawing inspiration from lilo.conf of debian, which is beautiful to say the least.. I haven't find enough time to do that. But I will do it.. But I don't know all the parameters enough. Of course I will post a starter but any input would be welcome. Point is we should be able to say RTFC rather than RTFA as that would get a DBA single place to look at. I agree that no amount of simplicity is enough but still..:-) Bye Shridhar -- Brooke's Law: Whenever a system becomes completely defined, some damn fool discovers something which either abolishes the system or expands it beyond recognition. From pgsql-performance-owner@postgresql.org Tue Jun 10 13:05:58 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 9228030DC50 for ; Tue, 10 Jun 2003 16:05:56 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 08252-02 for ; Tue, 10 Jun 2003 13:05:46 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id 3C64630E4B6 for ; Tue, 10 Jun 2003 13:05:45 -0300 (ADT) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3108101; Tue, 10 Jun 2003 09:05:50 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: shridhar_daithankar@persistent.co.in, pgsql-performance@postgresql.org Subject: Re: FW: [ADMIN] Shared_buffers and kernel parameters, tuning Date: Tue, 10 Jun 2003 09:03:50 -0700 User-Agent: KMail/1.4.3 References: <3EE64D19.30310.9E8DA9@localhost> In-Reply-To: <3EE64D19.30310.9E8DA9@localhost> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200306100903.50738.josh@agliodbs.com> X-Archive-Number: 200306/32 X-Sequence-Number: 2116 Shridhar, > I was planning to document postgresql.conf with little hints, enough to get > one started, drawing inspiration from lilo.conf of debian, which is > beautiful to say the least.. This week, I am: 1) Submiting a patch to re-organize postgresql.conf.sample and "Run-Time Configuration" docs in a more logical order. 2) Finishing up a massive OpenOffice.org spreadsheet full information on each postgresql.conf option, including anecdotal advice from this list. Next week, I will try to turn the spreadsheet into a series of HTML pages for Techdocs. I would be thrilled to have your help on: a) editing + augmenting the spreadsheet contents b) transforming it into HTML pages. -- Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Tue Jun 10 14:19:12 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 0DB2830DBE8 for ; Tue, 10 Jun 2003 17:19:12 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 18990-02 for ; Tue, 10 Jun 2003 14:19:01 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id DC09D30DBDC for ; Tue, 10 Jun 2003 14:19:00 -0300 (ADT) Received: (qmail 17821 invoked by uid 500); 10 Jun 2003 17:21:42 -0000 Date: Tue, 10 Jun 2003 12:21:42 -0500 From: Bruno Wolff III To: Shridhar Daithankar Cc: pgsql-performance@postgresql.org Subject: Re: FW: [ADMIN] Shared_buffers and kernel parameters, tuning Message-ID: <20030610172142.GA17801@wolff.to> Mail-Followup-To: Shridhar Daithankar , pgsql-performance@postgresql.org References: <3EE64D19.30310.9E8DA9@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3EE64D19.30310.9E8DA9@localhost> User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/33 X-Sequence-Number: 2117 On Tue, Jun 10, 2003 at 21:26:49 +0530, Shridhar Daithankar wrote: > > Point is we should be able to say RTFC rather than RTFA as that would get a DBA > single place to look at. I agree that no amount of simplicity is enough but > still..:-) I believe there was discussion a couple of months ago that came to a different conclusion. There was concern about having documenation that wasn't in the documentation and have to versions of essentially the same information that both need to be maintained. From pgsql-performance-owner@postgresql.org Tue Jun 10 15:02:41 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 0D0B930DE36 for ; Tue, 10 Jun 2003 18:02:37 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 22604-09 for ; Tue, 10 Jun 2003 15:02:26 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id DAC9130DE77 for ; Tue, 10 Jun 2003 15:02:24 -0300 (ADT) Received: from [66.219.92.2] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3108444 for pgsql-performance@postgresql.org; Tue, 10 Jun 2003 11:02:30 -0700 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: pgsql-performance@postgresql.org Subject: Re-ordering .CONF params ... questions for this list Date: Tue, 10 Jun 2003 11:01:46 -0700 User-Agent: KMail/1.4.3 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="------------Boundary-00=_Y22ADXJSAL36M446LS4K" Message-Id: <200306101101.46304.josh@agliodbs.com> X-Archive-Number: 200306/34 X-Sequence-Number: 2118 --------------Boundary-00=_Y22ADXJSAL36M446LS4K Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Folks, We've been discussing this for a while on HACKERS. However, I haven't been= =20 getting much feedback on the specific order proposed. Attached is an outline of my proposed re-ordering of postgresql.conf.sample= .=20=20=20 Please send me comments. I need to submit a patch by Thursday, so don't ta= ke=20 too long. This is an effort to make the order of run-time params in=20 postgresql.conf.sample and in the docs more logical and less baffling to th= e=20 new DBA. Questions: 1) Should "enable_implicit_from" go in the "Version/Platform Compatibility"= =20 section where I have it now, or in "CLIENT CONNECTIONS-Statement Behavior",= =20 or somewhere else? 2) Where should "preload_libraries" go? I'm very reluctant to start a=20 "Misc." section. Perhaps I should start a "LIBRARIES" section? 3) I have re-ordered each subsection somewhat. The fixed ordering is base= d=20 on: a) My guess at the frequency with which that option will be changed= ,=20 with more common options toward the top of the subsection; b) Grouping for tightly related options and for options that cascad= e; c) where (a) and (b) are unclear, alpha order. Does this order make sense looking at the file? 3) Should we use indenting in PostgreSQL.conf.sample? I tend to think it= =20 would make the file easier to read, but I'm not sure what effect it would= =20 have, if any, on parsing the file and whether other people would find it ea= sy=20 to read. --=20 -Josh Berkus Aglio Database Solutions San Francisco --------------Boundary-00=_Y22ADXJSAL36M446LS4K Content-Type: text/plain; charset="us-ascii"; name="re_order_conf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="re_order_conf" #CONNECTIONS AND AUTHENTICATION #Connection Settings tcpip_socket max_connections superuser_reserved_connections port unix_socket_directory unix_socket_group unix_socket_permissions #Security & Authentication authentication_timeout ssl krb_server_keyfile virtual_host db_user_namespace #RESOURCE USAGE (except WAL) #Memory shared_buffers sort_mem vacuum_mem #Free Space Map max_fsm_pages max_fsm_relations #Disk Usage max_files_per_process #WRITE AHEAD LOG fsync wal_sync_method wal_buffers checkpoint_segments checkpoint_timeout checkpoint_warning commit_delay commit_siblings #QUERY TUNING #Planner Method Enabling enable_hashagg enable_hashjoin enable_indexscan enable_mergejoin enable_nestloop enable_seqscan enable_sort enable_tidscan #Planner Cost Constants effective_cache_size random_page_cost cpu_tuple_cost cpu_index_tuple_cost cpu_operator_cost default_statistics_target #Genetic Estimate Query Optimizer geqo geqo_threshold geqo_selection_bias geqo_pool_size geqo_effort geqo_generations geqo_random_seed #Other Query Modifiers explain_pretty_print from_collapse_limit join_collapse_limit max_expr_depth #CLIENT CONNECTION DEFAULTS #Statement Behaviour autocommit search_path default_transaction_isolation default_transaction_read_only statement_timeout #Locale and Formatting client_encoding australian_timezones datestyle timezone lc_messages lc_monetary lc_time lc_numeric #Other Defaults dynamic_library_path password_encryption #LOGGING & DEBUGGING #Debugging/Logging Levels server_min_messages client_min_messages log_min_error_statement debug_print_parse debug_print_rewritten debug_print_plan debug_pretty_print debug_assertions silent_mode #Additional Info to Log log_connections log_duration log_pid log_statement log_timestamp hostname_lookup show_source_port #Syslog syslog syslog_facility syslog_ident #STATISTICS #Statistics monitoring show_parser_stats show_planner_stats show_executor_stats show_statement_stats #Query/Index Statistics Collector stats_start_collector stats_reset_on_server_start stats_command_string stats_row_level stats_block_level #LOCK MANAGEMENT deadlock_timeout max_locks_per_transaction #VERSION/PLATFORM COMPATIBILITY OPTIONS enable_implicit_from have_rendezvous regex_flavor sql_inheritance transform_null_equals --------------Boundary-00=_Y22ADXJSAL36M446LS4K-- From pgsql-performance-owner@postgresql.org Tue Jun 10 15:13:04 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id A24F830E700 for ; Tue, 10 Jun 2003 18:13:03 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 24481-04 for ; Tue, 10 Jun 2003 15:12:52 -0300 (ADT) Received: from mail2.mediadesign.nl (md2.mediadesign.nl [212.19.205.67]) by svr1.postgresql.org (Postfix) with SMTP id 038F930E6E8 for ; Tue, 10 Jun 2003 15:12:51 -0300 (ADT) Received: (qmail 31622 invoked by uid 666); 10 Jun 2003 18:12:48 -0000 Date: Tue, 10 Jun 2003 20:12:48 +0200 From: Vincent van Leeuwen To: pgsql-performance@postgresql.org Subject: Re: FW: [ADMIN] Shared_buffers and kernel parameters, tuning Message-ID: <20030610181247.GX1535@md2.mediadesign.nl> Mail-Followup-To: pgsql-performance@postgresql.org References: <200306100846.21875.josh@agliodbs.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200306100846.21875.josh@agliodbs.com> User-Agent: Mutt/1.3.28i X-Archive-Number: 200306/35 X-Sequence-Number: 2119 On 2003-06-10 08:46:21 -0700, Josh Berkus wrote: > Rune, > > > > shared_buffers = 117248 (shmmax / 2 / 1024 / 8 ) This I got from this > > > forum. > > > Does this sound right or am I totally out of bounds here? I have, as said > > Out of bounds, through no fault of your own .... I'm still working on > documentation for this. However, let me qoute the upcoming supplimentary > docs: > > SHARED_BUFFERS > Sets the size of Postgres' memory buffer where queries are held before being > fed into the Kernel buffer of the host system. It's very important to > remember that this is only a holding area, and not the total memory available > for the server. As such, resist the urge to set this number to a large > portion of your RAM, as this will actually degrade performance on many OSes. > Members of the pgsql-performance mailing list have found useful values in the > range of 1000-6000, depending on available RAM, database size, and number of > concurrent queries. No one has yet reported positive results for any number > over 6000. > We run a dual P3 1GHz server, running Debian Linux (stable), kernel 2.4.20, with a 5-disk (10K rpm) RAID 5 array (ICP Vortex controller) and 4GB RAM, most of which is used for filesystem cache. This server runs Postgresql 7.3.2 exclusively, with a database of roughly 7GB. This database is used for a very busy community website, running an enormous amount of small and simple select/update/insert queries and a number of complex select queries, to search through all kinds of data. This server isn't running postgres that long, and we're still trying to figure out the best configuration parameters for the highest possible performance. Shared_buffers was one of the first things we looked at. We've tested with shared_buffers at 1024, 8192, 32768 and 131072. So far, performance with shared_buffers set at 32768 was the best we could attain. 8192 and 131072 came out roughly equal. 1024 was miserable. (yay, 3 lines in a row starting with the word 'shared_buffers'! ;)) Also, there was a very strong relation between the shared_buffers setting and the amount of cpu time spent in kernelland. Currently, the server spends roughly 20% of it's time in kernelspace (according to vmstat). When shared_buffers was 8192, this went up to about 30%. I don't have any hard performance statistics, we just threw the site live with different settings and watched the load on all servers, and the amount of requests/second our webservers could generate (the bottleneck is the postgresql server, not the webservers). I'm really eager for any useful tips regarding the various cost settings. I've been following this list for months and read through a large portion of the archives, but noone has been able to do more than handwaving around certain numbers, which are close to the defaults anyway. Currently, we have the following settings: shared_buffers = 32768 max_fsm_relations = 100 max_fsm_pages = 100000 sort_mem = 16384 vacuum_mem = 131072 effective_cache_size = 327680 random_page_cost = 1.5 cpu_tuple_cost = 0.005 #cpu_index_tuple_cost = 0.001 (default) #cpu_operator_cost = 0.0025 (default) Halving the cpu_tuple_cost has given a very impressive performance boost (performance roughly doubled). I'm not sure why, because the plans of the large queries I was checking haven't changed as far as I can see, but maybe some smaller queries I didn't bother to check are using a different plan now. Although I was quite sure those smaller queries were all using the correct indexes etc before the change anyway. Just to be absolutely sure: all *_cost parameters only influence the chosen plan, right? There is absolutely nothing else influenced which doesn't show up in an EXPLAIN ANALYZE, right? Regards, Vincent van Leeuwen Media Design - http://www.mediadesign.nl/ From pgsql-performance-owner@postgresql.org Tue Jun 10 15:28:55 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 40C1C30DE4F for ; Tue, 10 Jun 2003 18:28:52 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 27136-02 for ; Tue, 10 Jun 2003 15:28:41 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id 5771F30E63F for ; Tue, 10 Jun 2003 15:28:39 -0300 (ADT) Received: from [66.219.92.2] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3108523; Tue, 10 Jun 2003 11:28:45 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Vincent van Leeuwen , pgsql-performance@postgresql.org Subject: Re: FW: [ADMIN] Shared_buffers and kernel parameters, tuning Date: Tue, 10 Jun 2003 11:28:00 -0700 User-Agent: KMail/1.4.3 References: <200306100846.21875.josh@agliodbs.com> <20030610181247.GX1535@md2.mediadesign.nl> In-Reply-To: <20030610181247.GX1535@md2.mediadesign.nl> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200306101128.00609.josh@agliodbs.com> X-Archive-Number: 200306/36 X-Sequence-Number: 2120 Vincent, > This server isn't running postgres that long, and we're still trying to= =20 figure > out the best configuration parameters for the highest possible performanc= e. > Shared_buffers was one of the first things we looked at. We've tested with > shared_buffers at 1024, 8192, 32768 and 131072. So far, performance with > shared_buffers set at 32768 was the best we could attain. 8192 and 131072= =20 came > out roughly equal. 1024 was miserable. Cool! This is the first report we've had of a successful higher setting f= or=20 shared_buffers. I'll need to revise the text. What do people think of: SHARED_BUFFERS Sets the size of Postgres' memory buffer where queries are held before being fed into the Kernel buffer of the host system. It's very important to remember that this is only a holding area, and not the total memory availab= le for the server. As such, resist the urge to set this number to a large portion of your RAM, as this will actually degrade performance on many OSes. Members of the pgsql-performance mailing list have mostly found useful valu= es in the range of 1000-6000, depending on available RAM, database size, and number of concurrent queries. This can go up slightly for servers with a great deal of RAM; the useful maximum on Linux seems to be 6% to 10% of available RAM, with performance degrading at higher settings. Information on other OSes is not yet posted. On multi-purpose servers, of course, the setting should be lowered.=20 > Also, there was a very strong relation between the shared_buffers setting= =20 and > the amount of cpu time spent in kernelland. Currently, the server spends > roughly 20% of it's time in kernelspace (according to vmstat). When > shared_buffers was 8192, this went up to about 30%. This makes perfect sense ... less shared_buffers =3D more kernel_buffers, a= nd=20 vice-versa. > Currently, we have the following settings: > shared_buffers =3D 32768 > max_fsm_relations =3D 100 You might wanna increase this; current recommended is 300 just to make sure= =20 that you have one for every table. > Just to be absolutely sure: all *_cost parameters only influence the chos= en > plan, right? There is absolutely nothing else influenced which doesn't sh= ow=20 up > in an EXPLAIN ANALYZE, right? Yes, AFAIK. --=20 -Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Tue Jun 10 16:05:31 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id EC35430E798 for ; Tue, 10 Jun 2003 19:05:29 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 26629-06 for ; Tue, 10 Jun 2003 16:05:19 -0300 (ADT) Received: from anchor-post-39.mail.demon.net (anchor-post-39.mail.demon.net [194.217.242.80]) by svr1.postgresql.org (Postfix) with ESMTP id B978030E364 for ; Tue, 10 Jun 2003 16:05:18 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-39.mail.demon.net with esmtp (Exim 3.36 #2) id 19PoQm-0007ZX-0U; Tue, 10 Jun 2003 20:05:16 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 4D9B8162B1; Tue, 10 Jun 2003 20:05:15 +0100 (BST) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 6E81C162AC; Tue, 10 Jun 2003 20:05:14 +0100 (BST) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton To: josh@agliodbs.com, pgsql-performance@postgresql.org Subject: Re: Re-ordering .CONF params ... questions for this list Date: Tue, 10 Jun 2003 20:05:11 +0100 User-Agent: KMail/1.4.3 References: <200306101101.46304.josh@agliodbs.com> In-Reply-To: <200306101101.46304.josh@agliodbs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200306102005.11578.richardh@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Archive-Number: 200306/37 X-Sequence-Number: 2121 On Tuesday 10 Jun 2003 7:01 pm, Josh Berkus wrote: > Folks, > > We've been discussing this for a while on HACKERS. However, I haven't be= en > getting much feedback on the specific order proposed. > > Attached is an outline of my proposed re-ordering of > postgresql.conf.sample. Please send me comments. I need to submit a patch > by Thursday, so don't take too long. > > This is an effort to make the order of run-time params in > postgresql.conf.sample and in the docs more logical and less baffling to > the new DBA. > > Questions: > 1) Should "enable_implicit_from" go in the "Version/Platform Compatibilit= y" > section where I have it now, or in "CLIENT CONNECTIONS-Statement Behavior= ", > or somewhere else? Version compatibility I'd vote for (hesitantly) > 2) Where should "preload_libraries" go? I'm very reluctant to start a > "Misc." section. Perhaps I should start a "LIBRARIES" section? No useful ideas - sorry. > 3) I have re-ordered each subsection somewhat. The fixed ordering is > based on: > a) My guess at the frequency with which that option will be > changed, with more common options toward the top of the subsection; > b) Grouping for tightly related options and for options that > cascade; c) where (a) and (b) are unclear, alpha order. > Does this order make sense looking at the file? Looks good, I'd suggest the following perhaps: Logging & Debugging I'd like this near the top, but then I use syslogging. With a new install I= go=20 in and check tcpip_socket etc, fix the logging and just see if everything i= s=20 working. Then I go in and do a little tuning. Actually, maybe the syslog sub-section should go above the others - say whe= re=20 you'll log to, and then what you'll log. Of course, I'm biased since I use= =20 syslog. Client Connection Defaults/Other/password_encryption This should probably go in the security section. Actually, looking at it=20 "dynamic_librar_path" is in the wrong place too - cut & past error? Query Tuning/Planner Method Enabling I'm in two minds here - obviously it is more "basic" than the "cost=20 constraints" section, but that's the one people will be tinkering with firs= t.=20 Nope - thinking about it, you've got it right. > 3) Should we use indenting in PostgreSQL.conf.sample? I tend to think it > would make the file easier to read, but I'm not sure what effect it would > have, if any, on parsing the file and whether other people would find it > easy to read. Not sure it would help that much - the comments need a URL to the relevant= =20 page in the online docs though. A couple more lines of comments too: # Syslog # To log to syslog, use something like # syslog =3D 2, syslog_facility =3D 'LOCAL0', syslog_ident =3D 'postgres' # Don't forget to update your syslog.conf then too. # ...etc Otherwise, looks good to me. --=20 Richard Huxton Archonet Ltd From pgsql-performance-owner@postgresql.org Tue Jun 10 16:08:50 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 2A81130DCC2 for ; Tue, 10 Jun 2003 19:08:44 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 26483-08 for ; Tue, 10 Jun 2003 16:08:32 -0300 (ADT) Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) by svr1.postgresql.org (Postfix) with ESMTP id 12C7930DC90 for ; Tue, 10 Jun 2003 16:08:28 -0300 (ADT) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id h5AJ8Mq16858; Tue, 10 Jun 2003 15:08:22 -0400 (EDT) From: Bruce Momjian Message-Id: <200306101908.h5AJ8Mq16858@candle.pha.pa.us> Subject: Re: FW: [ADMIN] Shared_buffers and kernel parameters, tuning In-Reply-To: <200306101128.00609.josh@agliodbs.com> To: josh@agliodbs.com Date: Tue, 10 Jun 2003 15:08:22 -0400 (EDT) Cc: Vincent van Leeuwen , pgsql-performance@postgresql.org X-Mailer: ELM [version 2.4ME+ PL99 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Archive-Number: 200306/38 X-Sequence-Number: 2122 Josh Berkus wrote: > Vincent, > > > This server isn't running postgres that long, and we're still trying to > figure > > out the best configuration parameters for the highest possible performance. > > Shared_buffers was one of the first things we looked at. We've tested with > > shared_buffers at 1024, 8192, 32768 and 131072. So far, performance with > > shared_buffers set at 32768 was the best we could attain. 8192 and 131072 > came > > out roughly equal. 1024 was miserable. > > Cool! This is the first report we've had of a successful higher setting for > shared_buffers. I'll need to revise the text. What do people think of: I have been thinking about shared_buffers, and it seems it is the age-old issue of working set. Traditionally Unix doesn't use working set (though a few do). It just allocates memory proportionally among all processes, with unreferenced pages being paged out first. For PostgreSQL, if your working set is X, if you set your shared buffers to X, you will get optimal performance (assuming there is no memory pressure). If set allocate X/2, you will probably get worse performance. If you allocate X*2, you will also probably get slightly worse performance. Now, let's suppose you can't allocate X shared buffers, because of memory pressure. Suppose you can allocate X/2 shared buffers, and that will leave X/2 kernel buffers. It would be better to allocate X/4 shared buffers, and leave X*3/4 kernel buffers. If you can only allocate X/5 shared buffers, you might be better with X/10 shared buffers because you are going to be doing a lot of I/O, and you need lots of kernel buffers for that. I think that is what people are seeing when modifying shared buffers: X shared buffers is best >X shared buffers is too much overhead and starves kernel ; Tue, 10 Jun 2003 19:42:29 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 32679-08 for ; Tue, 10 Jun 2003 16:42:18 -0300 (ADT) Received: from flake.decibel.org (unknown [66.143.173.58]) by svr1.postgresql.org (Postfix) with SMTP id 2A41430E9E1 for ; Tue, 10 Jun 2003 16:42:07 -0300 (ADT) Received: (qmail 51173 invoked by uid 1001); 10 Jun 2003 19:42:07 -0000 Date: Tue, 10 Jun 2003 14:42:07 -0500 From: "Jim C. Nasby" To: pgsql-performance@postgresql.org Subject: Re: Hash or merge join instead of inner loop Message-ID: <20030610194206.GK40542@flake.decibel.org> Reply-To: jim@nasby.net References: <20030609204009.GJ40542@flake.decibel.org> <274.1055225711@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <274.1055225711@sss.pgh.pa.us> User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 4.8-RELEASE i386 X-Distributed: Join the Effort! http://www.distributed.net X-Archive-Number: 200306/39 X-Sequence-Number: 2123 On Tue, Jun 10, 2003 at 02:15:11AM -0400, Tom Lane wrote: > "Jim C. Nasby" writes: > > I have a query that's cauing pgsql choose either a hash or merge join > > depending on how I mess with the stats variables, but it won't choose an > > nested loop, even though it's the fastest. > > There's been some discussion about that before; you could check the > archives (now that they're up again ;-)). I believe that the planner > overestimates the cost of a nestloop with inner indexscan, because it > costs the indexscans as though each one is an independent ab-initio > index search. In reality, most of the upper btree levels will no doubt > stay in memory during such a query, and so this estimate charges many > more reads than really occur. Fixing this is on the todo list, but no > one's got to it yet. (It's not clear to me how to put the consideration > into the planner's cost algorithms in a clean way.) What about just ignoring all but the leaf pages? Unless you have a really, really big index, I think this would probably work well, or at least better than what we have right now. I can't think of an elegant way to figure out hit percentages either. Maybe as a ratio of how often an individual page at a given level of the btree is to be hit? IE: the root page will always be hit (only one page); if the next level up has 10 pages, each one is 10% likely to be in cache, and so-on. Or maybe a better way to look at it is how many pages sit underneath each page. So if we figure there's a 0.1% chance that a leaf page is in cache and each page in the layer above/below that has tuples for 100 leaf pages, then the odds of a page in that layer being in the cache is 10% It might also be worth giving index pages a higher priority in the internal buffer than table pages. -- Jim C. Nasby (aka Decibel!) jim@nasby.net Member: Triangle Fraternity, Sports Car Club of America Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?" From pgsql-performance-owner@postgresql.org Tue Jun 10 16:44:06 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id BAA0030DF7A for ; Tue, 10 Jun 2003 19:43:59 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 35034-03 for ; Tue, 10 Jun 2003 16:43:49 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id E2B6130E359 for ; Tue, 10 Jun 2003 16:43:47 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5AJhlU6004333; Tue, 10 Jun 2003 15:43:47 -0400 (EDT) To: Vincent van Leeuwen Cc: pgsql-performance@postgresql.org Subject: Re: FW: [ADMIN] Shared_buffers and kernel parameters, tuning In-reply-to: <20030610181247.GX1535@md2.mediadesign.nl> References: <200306100846.21875.josh@agliodbs.com> <20030610181247.GX1535@md2.mediadesign.nl> Comments: In-reply-to Vincent van Leeuwen message dated "Tue, 10 Jun 2003 20:12:48 +0200" Date: Tue, 10 Jun 2003 15:43:47 -0400 Message-ID: <4332.1055274227@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/40 X-Sequence-Number: 2124 Vincent van Leeuwen writes: > Halving the cpu_tuple_cost has given a very impressive performance boost > (performance roughly doubled). I'm not sure why, because the plans of the > large queries I was checking haven't changed as far as I can see, but maybe > some smaller queries I didn't bother to check are using a different plan now. That's very curious; I'd expect that parameter to have only marginal effect in the first place (unless you make huge changes in it, of course). It must have changed some plan that you didn't take note of. If you can find it I'd be interested to know. > Just to be absolutely sure: all *_cost parameters only influence the > chosen plan, right? There is absolutely nothing else influenced which > doesn't show up in an EXPLAIN ANALYZE, right? AFAIR, the only one of these parameters that the executor pays any attention to is SORT_MEM; that will determine how soon the runtime code starts to spill tuples to disk in sorts, hash tables, etc. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jun 10 17:07:03 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 688F030E5DB for ; Tue, 10 Jun 2003 20:07:00 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 33526-07 for ; Tue, 10 Jun 2003 17:06:49 -0300 (ADT) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id B9B4D30EA95 for ; Tue, 10 Jun 2003 17:06:45 -0300 (ADT) Received: from [206.19.64.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.0.6) with ESMTP-TLS id 1801392; Tue, 10 Jun 2003 12:42:07 -0700 Message-ID: <3EE639FA.5010407@joeconway.com> Date: Tue, 10 Jun 2003 13:05:14 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Richard Huxton Cc: josh@agliodbs.com, pgsql-performance@postgresql.org Subject: Re: Re-ordering .CONF params ... questions for this list References: <200306101101.46304.josh@agliodbs.com> <200306102005.11578.richardh@archonet.com> In-Reply-To: <200306102005.11578.richardh@archonet.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/41 X-Sequence-Number: 2125 Richard Huxton wrote: >>2) Where should "preload_libraries" go? I'm very reluctant to start a >>"Misc." section. Perhaps I should start a "LIBRARIES" section? > > No useful ideas - sorry. Sorry, I missed this earlier. This is a performance tuning option. Joe From pgsql-performance-owner@postgresql.org Tue Jun 10 17:57:02 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id C671E30E75C for ; Tue, 10 Jun 2003 20:56:58 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 37676-10 for ; Tue, 10 Jun 2003 17:56:48 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id BDB0130E4F3 for ; Tue, 10 Jun 2003 17:56:47 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5AKujU6004800; Tue, 10 Jun 2003 16:56:45 -0400 (EDT) To: jim@nasby.net Cc: pgsql-performance@postgresql.org Subject: Re: Hash or merge join instead of inner loop In-reply-to: <20030610194206.GK40542@flake.decibel.org> References: <20030609204009.GJ40542@flake.decibel.org> <274.1055225711@sss.pgh.pa.us> <20030610194206.GK40542@flake.decibel.org> Comments: In-reply-to "Jim C. Nasby" message dated "Tue, 10 Jun 2003 14:42:07 -0500" Date: Tue, 10 Jun 2003 16:56:45 -0400 Message-ID: <4799.1055278605@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/42 X-Sequence-Number: 2126 "Jim C. Nasby" writes: > On Tue, Jun 10, 2003 at 02:15:11AM -0400, Tom Lane wrote: >> ... In reality, most of the upper btree levels will no doubt >> stay in memory during such a query, and so this estimate charges many >> more reads than really occur. Fixing this is on the todo list, but no >> one's got to it yet. (It's not clear to me how to put the consideration >> into the planner's cost algorithms in a clean way.) > What about just ignoring all but the leaf pages? IIRC, we already know what cost model we want to use. The problem is that the planner's code structure makes it difficult for the indexscan coster to know that the indexscan will be applied repeatedly rather than just once. That's what has to be solved. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jun 10 17:58:15 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1308530EB23 for ; Tue, 10 Jun 2003 20:58:14 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 38029-05 for ; Tue, 10 Jun 2003 17:58:03 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id 8820130EB3F for ; Tue, 10 Jun 2003 17:58:02 -0300 (ADT) Received: from [66.219.92.2] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3109005; Tue, 10 Jun 2003 13:58:11 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Richard Huxton , pgsql-performance@postgresql.org Subject: Re: Re-ordering .CONF params ... questions for this list Date: Tue, 10 Jun 2003 13:57:24 -0700 User-Agent: KMail/1.4.3 References: <200306101101.46304.josh@agliodbs.com> <200306102005.11578.richardh@archonet.com> In-Reply-To: <200306102005.11578.richardh@archonet.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200306101357.24596.josh@agliodbs.com> X-Archive-Number: 200306/43 X-Sequence-Number: 2127 Richard, > Logging & Debugging > I'd like this near the top, but then I use syslogging. With a new install= I=20 go=20 > in and check tcpip_socket etc, fix the logging and just see if everything= is=20 > working. Then I go in and do a little tuning. > Actually, maybe the syslog sub-section should go above the others - say= =20 where=20 > you'll log to, and then what you'll log. Of course, I'm biased since I us= e=20 > syslog. I have no objection to moving the syslog section. Any other opinions? > Client Connection Defaults/Other/password_encryption > This should probably go in the security section. Actually, looking at it= =20 > "dynamic_librar_path" is in the wrong place too - cut & past error? Not the way I read the docs; according to the docs: password_encryption is whether or not the statement "ALTER USER joe_schmoe= =20 WITH PASSWORD 'xxxyyy'" is encrypted by default even if you don't use the= =20 "WITH ENCRYPTION" option. And it is SET-able on each client connection, b= y=20 regular users. So it goes in "CLIENT CONNECTION SETTINGS". "dynamic_library_path", while less obvious, is also SETable on each client= =20 connection. I'd be happy to revise this if someone understands/uses this= =20 option and has a better idea where to put it. > Not sure it would help that much - the comments need a URL to the relevan= t=20 > page in the online docs though. A couple more lines of comments too: Given that we're running out of time, I wasn't going to touch any of the=20 comments in PostgreSQL.conf.sample. Instead, I was going to leave the=20 comments as-is, and post extensive comments on Techdocs before 7.4 beta.=20= =20 Then, in 7.5 or 8.0 we can re-comment .conf. --=20 -Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Tue Jun 10 18:29:00 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 9AA3C30EB7F for ; Tue, 10 Jun 2003 21:28:58 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 46233-04 for ; Tue, 10 Jun 2003 18:28:48 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 4E39430EB5C for ; Tue, 10 Jun 2003 18:28:47 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5ALShU6005409; Tue, 10 Jun 2003 17:28:44 -0400 (EDT) To: josh@agliodbs.com Cc: Richard Huxton , pgsql-performance@postgresql.org Subject: Re: Re-ordering .CONF params ... questions for this list In-reply-to: <200306101357.24596.josh@agliodbs.com> References: <200306101101.46304.josh@agliodbs.com> <200306102005.11578.richardh@archonet.com> <200306101357.24596.josh@agliodbs.com> Comments: In-reply-to Josh Berkus message dated "Tue, 10 Jun 2003 13:57:24 -0700" Date: Tue, 10 Jun 2003 17:28:43 -0400 Message-ID: <5408.1055280523@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/44 X-Sequence-Number: 2128 Josh Berkus writes: > Given that we're running out of time, I wasn't going to touch any of the > comments in PostgreSQL.conf.sample. Instead, I was going to leave the > comments as-is, and post extensive comments on Techdocs before 7.4 > beta. I doubt anyone would object to improving the comments during beta; so you don't need to consider that part something that has to be done before feature freeze. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jun 10 18:30:32 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id A946C30DE60 for ; Tue, 10 Jun 2003 21:30:31 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 46770-04 for ; Tue, 10 Jun 2003 18:30:21 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id 85A3930EAD2 for ; Tue, 10 Jun 2003 18:30:20 -0300 (ADT) Received: from [66.219.92.2] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3109097; Tue, 10 Jun 2003 14:30:29 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Tom Lane Subject: Re: Re-ordering .CONF params ... questions for this list Date: Tue, 10 Jun 2003 14:29:42 -0700 User-Agent: KMail/1.4.3 Cc: Richard Huxton , pgsql-performance@postgresql.org References: <200306101101.46304.josh@agliodbs.com> <200306101357.24596.josh@agliodbs.com> <5408.1055280523@sss.pgh.pa.us> In-Reply-To: <5408.1055280523@sss.pgh.pa.us> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200306101429.43003.josh@agliodbs.com> X-Archive-Number: 200306/45 X-Sequence-Number: 2129 Tom, > I doubt anyone would object to improving the comments during beta; so > you don't need to consider that part something that has to be done > before feature freeze. Oh, cool. OK, then ... the hard part is just deciding on what comments to= =20 include. We'll work on that in this list. --=20 -Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Tue Jun 10 18:46:06 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id A662030DF4E; Tue, 10 Jun 2003 21:46:03 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 46954-04; Tue, 10 Jun 2003 18:45:53 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id AFCEB30DBDA; Tue, 10 Jun 2003 18:45:51 -0300 (ADT) Received: from [66.219.92.2] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3109168; Tue, 10 Jun 2003 14:46:00 -0700 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: pgsql-performance@postgresql.org Subject: Re: Re-ordering .CONF params ... questions for this list Date: Tue, 10 Jun 2003 14:45:13 -0700 User-Agent: KMail/1.4.3 Cc: pgsql-hackers@postgresql.org References: <200306101101.46304.josh@agliodbs.com> <5408.1055280523@sss.pgh.pa.us> <200306101429.43003.josh@agliodbs.com> In-Reply-To: <200306101429.43003.josh@agliodbs.com> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="------------Boundary-00=_DFCAU7B707AAYX1BODVC" Message-Id: <200306101445.13513.josh@agliodbs.com> X-Archive-Number: 200306/46 X-Sequence-Number: 2130 --------------Boundary-00=_DFCAU7B707AAYX1BODVC Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Folks, Revised ordering of options, based on information and suggestions received= =20 here on both mailing lists. --=20 -Josh Berkus ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco --------------Boundary-00=_DFCAU7B707AAYX1BODVC Content-Type: text/plain; charset="iso-8859-1"; name="re_order_conf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="re_order_conf" #CONNECTIONS AND AUTHENTICATION #Connection Settings tcpip_socket max_connections superuser_reserved_connections port unix_socket_directory unix_socket_group unix_socket_permissions #Security & Authentication authentication_timeout ssl krb_server_keyfile virtual_host db_user_namespace #RESOURCE USAGE (except WAL) #Memory shared_buffers sort_mem vacuum_mem #Free Space Map max_fsm_pages max_fsm_relations #Disk Resource Usage max_files_per_process preload_libraries #WRITE AHEAD LOG fsync wal_sync_method wal_buffers checkpoint_segments checkpoint_timeout checkpoint_warning commit_delay commit_siblings #QUERY TUNING #Planner Method Enabling enable_hashagg enable_hashjoin enable_indexscan enable_mergejoin enable_nestloop enable_seqscan enable_sort enable_tidscan #Planner Cost Constants effective_cache_size random_page_cost cpu_tuple_cost cpu_index_tuple_cost cpu_operator_cost default_statistics_target #Genetic Estimate Query Optimizer geqo geqo_threshold geqo_selection_bias geqo_pool_size geqo_effort geqo_generations geqo_random_seed #Other Query Modifiers explain_pretty_print from_collapse_limit join_collapse_limit max_expr_depth #LOGGING & DEBUGGING #Syslog syslog syslog_facility syslog_ident #Debugging/Logging Levels server_min_messages client_min_messages log_min_error_statement debug_print_parse debug_print_rewritten debug_print_plan debug_pretty_print debug_assertions silent_mode #Additional Info to Log log_connections log_duration log_pid log_statement log_timestamp hostname_lookup show_source_port #CLIENT CONNECTION DEFAULTS #Statement Behaviour XXXXXautocommitXXXXX REMOVED! search_path default_transaction_isolation default_transaction_read_only statement_timeout #Locale and Formatting datestyle timezone australian_timezones extra_float_digits lc_messages lc_monetary lc_time lc_numeric client_encoding #Other Defaults password_encryption dynamic_library_path #STATISTICS #Statistics monitoring show_parser_stats show_planner_stats show_executor_stats show_statement_stats default_statistics_target #Query/Index Statistics Collector stats_start_collector stats_reset_on_server_start stats_command_string stats_row_level stats_block_level #LOCK MANAGEMENT deadlock_timeout max_locks_per_transaction #VERSION/PLATFORM COMPATIBILITY OPTIONS #Previous Postgres Versions enable_implicit_from regex_flavor sql_inheritance #Compatibility with Platforms & Clients have_rendezvous transform_null_equals --------------Boundary-00=_DFCAU7B707AAYX1BODVC-- From pgsql-performance-owner@postgresql.org Tue Jun 10 20:10:53 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id D770030DC88 for ; Tue, 10 Jun 2003 23:10:50 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 50071-10 for ; Tue, 10 Jun 2003 20:10:40 -0300 (ADT) Received: from mail2.mediadesign.nl (md2.mediadesign.nl [212.19.205.67]) by svr1.postgresql.org (Postfix) with SMTP id A715130DCDC for ; Tue, 10 Jun 2003 20:10:38 -0300 (ADT) Received: (qmail 23817 invoked by uid 666); 10 Jun 2003 23:10:36 -0000 Date: Wed, 11 Jun 2003 01:10:36 +0200 From: Vincent van Leeuwen To: pgsql-performance@postgresql.org Subject: Re: FW: [ADMIN] Shared_buffers and kernel parameters, tuning Message-ID: <20030610231036.GZ1535@md2.mediadesign.nl> Mail-Followup-To: pgsql-performance@postgresql.org References: <200306101128.00609.josh@agliodbs.com> <200306101908.h5AJ8Mq16858@candle.pha.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200306101908.h5AJ8Mq16858@candle.pha.pa.us> User-Agent: Mutt/1.3.28i X-Archive-Number: 200306/47 X-Sequence-Number: 2131 On 2003-06-10 15:08:22 -0400, Bruce Momjian wrote: > For PostgreSQL, if your working set is X, if you set your shared buffers > to X, you will get optimal performance (assuming there is no memory > pressure). If set allocate X/2, you will probably get worse > performance. If you allocate X*2, you will also probably get slightly > worse performance. > > Now, let's suppose you can't allocate X shared buffers, because of > memory pressure. Suppose you can allocate X/2 shared buffers, and that > will leave X/2 kernel buffers. It would be better to allocate X/4 > shared buffers, and leave X*3/4 kernel buffers. If you can only > allocate X/5 shared buffers, you might be better with X/10 shared > buffers because you are going to be doing a lot of I/O, and you need > lots of kernel buffers for that. > > I think that is what people are seeing when modifying shared buffers: > > X shared buffers is best > >X shared buffers is too much overhead and starves kernel > more kernel buffers > > Add to this that it is very hard to estimate working set. > Makes a lot of sense to me. We're doing a lot of I/O on a small part of that 7GB, and the rest is accessed in a more or less random fashion, so 256MB of shared buffers sounds about right. I'll play more with this in the future to see at what setting it performs best. Is there any information available in the system tables or statistics collector that can help determine X? Could PostgreSQL be easily modified to provide more information in this area? Vincent van Leeuwen Media Design - http://www.mediadesign.nl/ From pgsql-performance-owner@postgresql.org Tue Jun 10 20:25:50 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 2AE1730DBA9 for ; Tue, 10 Jun 2003 23:25:50 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 64568-06 for ; Tue, 10 Jun 2003 20:25:39 -0300 (ADT) Received: from mail2.mediadesign.nl (md2.mediadesign.nl [212.19.205.67]) by svr1.postgresql.org (Postfix) with SMTP id DC9AF30DBB3 for ; Tue, 10 Jun 2003 20:25:38 -0300 (ADT) Received: (qmail 30329 invoked by uid 666); 10 Jun 2003 23:25:38 -0000 Date: Wed, 11 Jun 2003 01:25:38 +0200 From: Vincent van Leeuwen To: pgsql-performance@postgresql.org Subject: Re: FW: [ADMIN] Shared_buffers and kernel parameters, tuning Message-ID: <20030610232538.GA1535@md2.mediadesign.nl> Mail-Followup-To: pgsql-performance@postgresql.org References: <200306100846.21875.josh@agliodbs.com> <20030610181247.GX1535@md2.mediadesign.nl> <4332.1055274227@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4332.1055274227@sss.pgh.pa.us> User-Agent: Mutt/1.3.28i X-Archive-Number: 200306/48 X-Sequence-Number: 2132 On 2003-06-10 15:43:47 -0400, Tom Lane wrote: > Vincent van Leeuwen writes: > > Halving the cpu_tuple_cost has given a very impressive performance boost > > (performance roughly doubled). I'm not sure why, because the plans of the > > large queries I was checking haven't changed as far as I can see, but maybe > > some smaller queries I didn't bother to check are using a different plan now. > > That's very curious; I'd expect that parameter to have only marginal > effect in the first place (unless you make huge changes in it, of course). > It must have changed some plan that you didn't take note of. If you can > find it I'd be interested to know. > Unfortunately, we're not exactly in the best position to test a lot of things. Our website has been running on MySQL and PHP for the last 3 years, and I've been wanting to switch to PostgreSQL for about the last 2 years. A lot of preparation went in to the change, but once we switched our live site to use PostgreSQL as it's main database we were utterly dissapointed in our own preparations. I knew our website was somewhat optimized for MySQL usage, but looking back I am totally amazed that we were able to squeeze so much performance out of a database that locks entire tables for every update (yes, we used the MyISAM table format). One of the most surprising things we learned was that MySQL was totally bottlenecking on I/O, with a large chunk of CPU unused, and with PostgreSQL it's the other way around. The last couple of weeks have been a nice collection of whacky antics and performance tuning all over the place. The first week everything performed abysmal, and another week later we're close to our original performance again. Ofcourse, the goal is to exceed MySQL's performance by a comfortable margin, but we're not there yet :) So, basically, this server is pushed far harder than it should be. Average system load is at about 4, and there are always 50-200 postgresql threads running during daytime. A new server that will replace this one and which is roughly 2-3 times as fast will be put live in a few weeks, and until that's here this box will have to bear the burden on it's own. > > Just to be absolutely sure: all *_cost parameters only influence the > > chosen plan, right? There is absolutely nothing else influenced which > > doesn't show up in an EXPLAIN ANALYZE, right? > > AFAIR, the only one of these parameters that the executor pays any > attention to is SORT_MEM; that will determine how soon the runtime code > starts to spill tuples to disk in sorts, hash tables, etc. > Current sort_mem setting is based on monitoring the pgsql_tmp directory and concluding that sort_mem needed to be doubled to avoid swapping to disk. It's not as if this box doesn't have enough RAM :) But this means I'll have to look more closely at my query plans, more things are changing than I'm noticing when I tweak various settings. One of the hardest parts is that some queries which should use sequential scans are using indexes and some queries which should use indexes are using sequential scans :) We're currently using some ugly 'set enable_seqscan to off;' hacks in a few places, until everything is tweaked right, but I hope we can remove those as soon as possible. Regards, Vincent van Leeuwen Media Design - http://www.mediadesign.nl/ From pgsql-performance-owner@postgresql.org Wed Jun 11 00:52:44 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 6838230DDBA for ; Wed, 11 Jun 2003 03:52:43 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 01688-08 for ; Wed, 11 Jun 2003 00:52:31 -0300 (ADT) Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) by svr1.postgresql.org (Postfix) with ESMTP id 62F3430DE1C for ; Wed, 11 Jun 2003 00:52:28 -0300 (ADT) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id h5B3qH327246; Tue, 10 Jun 2003 23:52:17 -0400 (EDT) From: Bruce Momjian Message-Id: <200306110352.h5B3qH327246@candle.pha.pa.us> Subject: Re: FW: [ADMIN] Shared_buffers and kernel parameters, tuning In-Reply-To: <20030610231036.GZ1535@md2.mediadesign.nl> To: Vincent van Leeuwen Date: Tue, 10 Jun 2003 23:52:17 -0400 (EDT) Cc: pgsql-performance@postgresql.org X-Mailer: ELM [version 2.4ME+ PL99 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Archive-Number: 200306/49 X-Sequence-Number: 2133 Vincent van Leeuwen wrote: > On 2003-06-10 15:08:22 -0400, Bruce Momjian wrote: > > For PostgreSQL, if your working set is X, if you set your shared buffers > > to X, you will get optimal performance (assuming there is no memory > > pressure). If set allocate X/2, you will probably get worse > > performance. If you allocate X*2, you will also probably get slightly > > worse performance. > > > > Now, let's suppose you can't allocate X shared buffers, because of > > memory pressure. Suppose you can allocate X/2 shared buffers, and that > > will leave X/2 kernel buffers. It would be better to allocate X/4 > > shared buffers, and leave X*3/4 kernel buffers. If you can only > > allocate X/5 shared buffers, you might be better with X/10 shared > > buffers because you are going to be doing a lot of I/O, and you need > > lots of kernel buffers for that. > > > > I think that is what people are seeing when modifying shared buffers: > > > > X shared buffers is best > > >X shared buffers is too much overhead and starves kernel > > > more kernel buffers > > > > Add to this that it is very hard to estimate working set. > > > > Makes a lot of sense to me. We're doing a lot of I/O on a small part of that > 7GB, and the rest is accessed in a more or less random fashion, so 256MB of > shared buffers sounds about right. I'll play more with this in the future to > see at what setting it performs best. > > Is there any information available in the system tables or statistics > collector that can help determine X? Could PostgreSQL be easily modified to > provide more information in this area? Estimatinge working set is an old problem. You can look at pgsql_tmp under each database directory for sort mem, but for shared buffers, I am not sure how to know the proper size. Anyone else have an idea? -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 From pgsql-performance-owner@postgresql.org Wed Jun 11 13:43:08 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id F1EA230DC0C for ; Wed, 11 Jun 2003 16:43:07 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 34476-07 for ; Wed, 11 Jun 2003 13:42:57 -0300 (ADT) Received: from unimm.unisoftbg.com (unknown [194.12.229.207]) by svr1.postgresql.org (Postfix) with ESMTP id 64B8030E356 for ; Wed, 11 Jun 2003 13:40:12 -0300 (ADT) Received: (qmail 13973 invoked by uid 507); 11 Jun 2003 16:42:26 -0000 Received: from unknown (HELO t1.unisoftbg.com) (pginfo%t1.unisoftbg.com@194.12.229.193) by 0 with SMTP; 11 Jun 2003 16:42:26 -0000 Message-ID: <3EE74C2D.88390062@t1.unisoftbg.com> Date: Wed, 11 Jun 2003 17:35:10 +0200 From: pginfo X-Mailer: Mozilla 4.03 [en] (Win95; I) MIME-Version: 1.0 To: "pgsql-performance@postgresql.org" Subject: left join performance problem Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/50 X-Sequence-Number: 2134 Hi, I am using pg 7.3.1 on a dual r.h. 7.3 box. I have a big problem with pg left join performance. My plan is: =# explain analyze select D.IDS AS DIDS ,D.IDS_SKLAD, D.IDS_KO AS DIDSKO,KL.MNAME AS KLNAME, D.NOMER AS DNOMER,D.DATE_OP, S.MED AS MEDNAME, NOM.MNAME AS NOMNAME,S.IDS_NUM, S.KOL, S.CENA,S.VAL,S.TOT,S.DTO,S.PTO ,M.OTN AS MOTN FROM A_KLIENTI KL , A_NOMEN NOM, A_DOC D,A_SKLA D S left outer join A_MESKLAD M ON(S.IDS=M.IDS) WHERE D.OP=4 AND D.IDS=S.IDS_DOC AND D.IDS_KO=KL.IDS AND S.IDS_NUM=NOM.IDS AND KL.IDS_G RUPA = 'SOF_112' ; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=460869.55..470785.29 rows=20 width=1034) (actual time=50139.27..57565.34 rows=12990 loops=1) -> Hash Join (cost=460869.55..470662.48 rows=20 width=862) (actual time=50139.02..57246.35 rows=12990 loops=1) Hash Cond: ("outer".ids_doc = "inner".ids) -> Merge Join (cost=457324.89..463038.60 rows=815792 width=356) (actual time=48128.32..53430.02 rows=815926 loops=1) Merge Cond: ("outer".ids = "inner".ids) -> Index Scan using a_mesklad_pkey on a_mesklad m (cost=0.00..1395.47 rows=15952 width=72) (actual time=0.21..109.19 rows=15952 loops=1) -> Sort (cost=457324.89..459364.37 rows=815792 width=284) (actual time=48128.05..49380.06 rows=815926 loops=1) Sort Key: s.ids -> Seq Scan on a_sklad s (cost=0.00..74502.92 rows=815792 width=284) (actual time=4.32..16777.16 rows=815926 loops=1) -> Hash (cost=3544.65..3544.65 rows=3 width=506) (actual time=1104.34..1104.34 rows=0 loops=1) -> Hash Join (cost=905.35..3544.65 rows=3 width=506) (actual time=428.32..1098.52 rows=1966 loops=1) Hash Cond: ("outer".ids_ko = "inner".ids) -> Index Scan using i_doc_op on a_doc d (cost=0.00..2625.71 rows=677 width=244) (actual time=29.27..690.86 rows=1981 loops=1) Index Cond: (op = 4) -> Hash (cost=905.19..905.19 rows=65 width=262) (actual time=398.97..398.97 rows=0 loops=1) -> Seq Scan on a_klienti kl (cost=0.00..905.19 rows=65 width=262) (actual time=396.68..398.93 rows=7 loops=1) Filter: (ids_grupa = 'SOF_112'::name) -> Index Scan using a_nomen_pkey on a_nomen nom (cost=0.00..6.01 rows=1 width=172) (actual time=0.01..0.02 rows=1 loops=12990) Index Cond: ("outer".ids_num = nom.ids) Total runtime: 57749.24 msec (20 rows) If I remove the join ( I know it is not very correct and I receive 19 rows as answer) it is working very fast. The plan is: explain analyze select D.IDS AS DIDS ,D.IDS_SKLAD, D.IDS_KO AS DIDSKO,KL.MNAME AS KLNAME, D.NOMER AS DNOMER,D.DATE_OP, S.MED AS MEDNAME, NOM.MNAME AS NOMNAME,S.IDS_NUM, S.KOL, S.CENA,S.VAL,S.TOT,S.DTO,S.PTO ,M.OTN AS MOTN FROM A_KLIENTI KL , A_NOMEN NOM, A_DOC D,A_SKLAD S ,A_MESKLAD M WHERE S.IDS=M.IDS AND D.OP=4 AND D.IDS=S.IDS_DOC AND D.IDS_KO=KL.IDS AND S.IDS_NUM=NOM.IDS AND D.NOMER like '%0905' AND KL.IDS_GRUPA = 'SOF_112' ORDER BY D.IDS,S.IDS_NUM,S.ORDER_NUM ; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=18897.33..18897.33 rows=1 width=1038) (actual time=36.33..36.35 rows=48 loops=1) Sort Key: d.ids, s.ids_num, s.order_num -> Nested Loop (cost=0.00..18897.32 rows=1 width=1038) (actual time=30.90..35.93 rows=48 loops=1) -> Nested Loop (cost=0.00..18891.29 rows=1 width=866) (actual time=30.70..33.34 rows=48 loops=1) -> Nested Loop (cost=0.00..18885.28 rows=1 width=794) (actual time=30.44..31.98 rows=48 loops=1) -> Nested Loop (cost=0.00..2633.93 rows=1 width=506) (actual time=30.18..30.62 rows=1 loops=1) -> Index Scan using i_doc_op on a_doc d (cost=0.00..2627.40 rows=1 width=244) (actual time=29.93..30.36 rows=1 loops=1) Index Cond: (op = 4) Filter: (nomer ~~ '%0905'::text) -> Index Scan using a_klienti_pkey on a_klienti kl (cost=0.00..6.01 rows=1 width=262) (actual time=0.23..0.23 rows=1 loops=1) Index Cond: ("outer".ids_ko = kl.ids) Filter: (ids_grupa = 'SOF_112'::name) -> Index Scan using i_sklad_ids_doc on a_sklad s (cost=0.00..16200.36 rows=4079 width=288) (actual time=0.24..0.95 rows=48 loops=1) Index Cond: ("outer".ids = s.ids_doc) -> Index Scan using a_mesklad_pkey on a_mesklad m (cost=0.00..6.01 rows=1 width=72) (actual time=0.02..0.02 rows=1 loops=48) Index Cond: ("outer".ids = m.ids) -> Index Scan using a_nomen_pkey on a_nomen nom (cost=0.00..6.01 rows=1 width=172) (actual time=0.04..0.04 rows=1 loops=48) Index Cond: ("outer".ids_num = nom.ids) Total runtime: 36.98 msec (19 rows) Also S.IDS and M.IDS are name and primary key's. I can not find my problem. Any idea will help. Of cours I can make the query with two selects and will work fast, but I think it is not good solution. regards, ivan. From pgsql-performance-owner@postgresql.org Wed Jun 11 16:33:32 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 59C2230E553 for ; Wed, 11 Jun 2003 19:33:31 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 65281-02 for ; Wed, 11 Jun 2003 16:33:20 -0300 (ADT) Received: from mail2.mediadesign.nl (md2.mediadesign.nl [212.19.205.67]) by svr1.postgresql.org (Postfix) with SMTP id 3D9C730DF59 for ; Wed, 11 Jun 2003 16:33:19 -0300 (ADT) Received: (qmail 32104 invoked by uid 666); 11 Jun 2003 19:33:14 -0000 Date: Wed, 11 Jun 2003 21:33:14 +0200 From: Vincent van Leeuwen To: pgsql-performance@postgresql.org Subject: tweaking costs to favor nestloop Message-ID: <20030611193313.GE1535@md2.mediadesign.nl> Mail-Followup-To: pgsql-performance@postgresql.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="TB36FDmn/VVEgNH/" Content-Disposition: inline User-Agent: Mutt/1.3.28i X-Archive-Number: 200306/51 X-Sequence-Number: 2135 --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, I'm running PG 7.3.2 on a dual P3 1 GHz, 4GB RAM, 5-disk RAID 5 (hardware) on Debian Linux, kernel 2.4.21-rc3. I'm unable to tweak the various _cost settings in such a way that attached query will use the right plan. Attachment contains relevant config file settings, table defenitions and explain analyze output with some enable_* settings turned off. Could anyone tell me what I'm doing wrong in the query itself or tell me what I should do with which config file setting to let the planner choose the fastest plan by itself? Regards, Vincent van Leeuwen Media Design - http://www.mediadesign.nl/ --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=nestloop shared_buffers = 32768 max_fsm_relations = 500 max_fsm_pages = 1000000 sort_mem = 16384 vacuum_mem = 131072 effective_cache_size = 327680 random_page_cost = 1.25 cpu_tuple_cost = 0.005 cpu_index_tuple_cost = 0.001 cpu_operator_cost = 0.0001 cu2nl=> \d auth Table "public.auth" Column | Type | Modifiers -------------+--------------------------+------------------------------------------------------ id | integer | not null default nextval('public.auth_id_seq'::text) nick | character varying(16) | not null password | character varying(16) | not null email | character varying(64) | not null emailnew | character varying(64) | level | smallint | not null default 0 karma | smallint | not null default 127 datemailed | timestamp with time zone | datesmsed | timestamp with time zone | status | smallint | not null default 0 statusinfo | character varying(16) | statusdate | timestamp with time zone | gsmnr | bigint | gsmoperator | smallint | not null default 0 gsmstatus | smallint | not null default 255 Indexes: auth_pkey primary key btree (id), auth_gsmnr_key unique btree (gsmnr), auth_nick_key unique btree (nick), auth_nick_lower_key unique btree (lower(nick)), auth_email_lower_key btree (lower(email)), auth_email_strrevlower_key btree (strrevlower(email)), auth_password_lower_key btree (lower("password")) Triggers: counter_users cu2nl=> \d reportuser Table "public.reportuser" Column | Type | Modifiers --------------+--------------------------+--------------------- idreporter | integer | not null idtarget | integer | not null status | smallint | not null default 0 datecreated | timestamp with time zone | datemodified | timestamp with time zone | datelocked | timestamp with time zone | reason | character varying(255) | not null default '' Indexes: reportuser_datecreated_key btree (datecreated), reportuser_datecreated_status_3_key btree (datecreated) WHERE (status < 3), reportuser_datecreated_status_5_key btree (datecreated) WHERE (status < 5), reportuser_idreporter_key btree (idreporter), reportuser_idtarget_key btree (idtarget), reportuser_status_key btree (status) Triggers: counter_reportuser_status cu2nl=> EXPLAIN ANALYZE SELECT id, nick, karma, level, COUNT(*) AS count, (karma-128)*COUNT(*) AS x FROM reportuser, auth WHERE auth.id=reportuser.idreporter GROUP BY idreporter, auth.id, auth.nick, auth.karma, auth.level ORDER BY x DESC, count DESC, karma DESC LIMIT 11; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=15433.50..15433.50 rows=11 width=26) (actual time=6008.18..6008.20 rows=11 loops=1) -> Sort (cost=15433.50..15433.86 rows=3536 width=26) (actual time=6008.18..6008.19 rows=12 loops=1) Sort Key: ((auth.karma - 128) * count(*)), count(*), auth.karma -> Aggregate (cost=15396.87..15425.16 rows=3536 width=26) (actual time=5574.60..5867.46 rows=9940 loops=1) -> Group (cost=15396.87..15418.09 rows=35365 width=26) (actual time=5574.55..5763.71 rows=30148 loops=1) -> Sort (cost=15396.87..15400.41 rows=35365 width=26) (actual time=5574.53..5595.51 rows=30148 loops=1) Sort Key: reportuser.idreporter, auth.id, auth.nick, auth.karma, auth."level" -> Merge Join (cost=800.70..15290.00 rows=35365 width=26) (actual time=243.95..5289.00 rows=30148 loops=1) Merge Cond: ("outer".id = "inner".idreporter) -> Index Scan using auth_pkey on auth (cost=0.00..14407.97 rows=607336 width=22) (actual time=0.04..3923.71 rows=605168 loops=1) -> Sort (cost=800.70..804.23 rows=35365 width=4) (actual time=243.86..269.37 rows=35417 loops=1) Sort Key: reportuser.idreporter -> Seq Scan on reportuser (cost=0.00..693.83 rows=35365 width=4) (actual time=0.01..95.13 rows=35417 loops=1) Total runtime: 6026.86 msec (14 rows) cu2nl=> SET enable_mergejoin TO off; SET cu2nl=> EXPLAIN ANALYZE SELECT id, nick, karma, level, COUNT(*) AS count, (karma-128)*COUNT(*) AS x FROM reportuser, auth WHERE auth.id=reportuser.idreporter GROUP BY idreporter, auth.id, auth.nick, auth.karma, auth.level ORDER BY x DESC, count DESC, karma DESC LIMIT 11; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=88698.95..88698.96 rows=11 width=26) (actual time=11920.93..11920.95 rows=11 loops=1) -> Sort (cost=88698.95..88699.31 rows=3536 width=26) (actual time=11920.92..11920.93 rows=12 loops=1) Sort Key: ((auth.karma - 128) * count(*)), count(*), auth.karma -> Aggregate (cost=88662.32..88690.62 rows=3536 width=26) (actual time=11486.97..11780.27 rows=9940 loops=1) -> Group (cost=88662.32..88683.54 rows=35365 width=26) (actual time=11486.91..11676.86 rows=30148 loops=1) -> Sort (cost=88662.32..88665.86 rows=35365 width=26) (actual time=11486.88..11507.77 rows=30148 loops=1) Sort Key: reportuser.idreporter, auth.id, auth.nick, auth.karma, auth."level" -> Hash Join (cost=83859.05..88555.45 rows=35365 width=26) (actual time=3745.74..11100.43 rows=30148 loops=1) Hash Cond: ("outer".idreporter = "inner".id) -> Seq Scan on reportuser (cost=0.00..693.83 rows=35365 width=4) (actual time=0.01..89.23 rows=35417 loops=1) -> Hash (cost=11835.68..11835.68 rows=607336 width=22) (actual time=3745.25..3745.25 rows=0 loops=1) -> Seq Scan on auth (cost=0.00..11835.68 rows=607336 width=22) (actual time=0.03..2438.54 rows=607566 loops=1) Total runtime: 11931.21 msec (13 rows) cu2nl=> SET enable_hashjoin TO off; SET cu2nl=> EXPLAIN ANALYZE SELECT id, nick, karma, level, COUNT(*) AS count, (karma-128)*COUNT(*) AS x FROM reportuser, auth WHERE auth.id=reportuser.idreporter GROUP BY idreporter, auth.id, auth.nick, auth.karma, auth.level ORDER BY x DESC, count DESC, karma DESC LIMIT 11; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=109688.85..109688.85 rows=11 width=26) (actual time=1831.55..1831.57 rows=11 loops=1) -> Sort (cost=109688.85..109689.21 rows=3536 width=26) (actual time=1831.54..1831.55 rows=12 loops=1) Sort Key: ((auth.karma - 128) * count(*)), count(*), auth.karma -> Aggregate (cost=109652.22..109680.51 rows=3536 width=26) (actual time=1397.77..1691.03 rows=9940 loops=1) -> Group (cost=109652.22..109673.44 rows=35365 width=26) (actual time=1397.69..1587.60 rows=30148 loops=1) -> Sort (cost=109652.22..109655.76 rows=35365 width=26) (actual time=1397.67..1418.60 rows=30148 loops=1) Sort Key: reportuser.idreporter, auth.id, auth.nick, auth.karma, auth."level" -> Nested Loop (cost=0.00..109545.35 rows=35365 width=26) (actual time=0.07..997.10 rows=30148 loops=1) -> Seq Scan on reportuser (cost=0.00..693.83 rows=35365 width=4) (actual time=0.02..112.22 rows=35417 loops=1) -> Index Scan using auth_pkey on auth (cost=0.00..3.07 rows=1 width=22) (actual time=0.02..0.02 rows=1 loops=35417) Index Cond: (auth.id = "outer".idreporter) Total runtime: 1841.93 msec (12 rows) --TB36FDmn/VVEgNH/-- From pgsql-performance-owner@postgresql.org Wed Jun 11 17:18:10 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id EFCFB30E34A for ; Wed, 11 Jun 2003 20:18:07 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 67840-08 for ; Wed, 11 Jun 2003 17:17:56 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id F401E30D6E1 for ; Wed, 11 Jun 2003 17:17:54 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5BKHsU6023558; Wed, 11 Jun 2003 16:17:54 -0400 (EDT) To: Vincent van Leeuwen Cc: pgsql-performance@postgresql.org Subject: Re: tweaking costs to favor nestloop In-reply-to: <20030611193313.GE1535@md2.mediadesign.nl> References: <20030611193313.GE1535@md2.mediadesign.nl> Comments: In-reply-to Vincent van Leeuwen message dated "Wed, 11 Jun 2003 21:33:14 +0200" Date: Wed, 11 Jun 2003 16:17:53 -0400 Message-ID: <23557.1055362673@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/52 X-Sequence-Number: 2136 Vincent van Leeuwen writes: > I'm unable to tweak the various _cost settings in such a way that attached > query will use the right plan. You aren't going to be able to. You've already overshot a reasonable random_page_cost setting --- to judge by the relative actual costs of the merge and hash join, a value somewhere around 3 is appropriate for your setup. (Assuming I did the math right --- if you set it to 3, do you get a ratio of merge and hash estimated costs that agrees with the ratio of actual runtimes?) The problem here is that the costing of the repeated inner index scans isn't realistic: 35417 probes into "auth" are clearly taking much less than 35417 times what a single probe could be expected to take. We talked about how repeated scans would win from caching of the upper btree levels, but I think there's more to it than that. It occurs to me that the probes you are making are probably not random and uncorrelated. They are driven by the values of reportuser.idreporter ... is it fair to guess that most of the reportuser rows link to just a small fraction of the total auth population? If so, the caching could be eliminating most of the reads, not just the upper btree levels, because we're mostly hitting only small parts of the index and auth tables. I'm beginning to think that the only reasonable way to model this is to cost the entire nestloop join as a unit, so that we have access to statistics about the outer table as well as the indexed table. That would give us a shot at estimating how much of the index is likely to get touched. As of 7.3 I think all you can do is force nestloop by disabling the other two join types. regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jun 11 23:58:04 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id E8ED330E70D for ; Thu, 12 Jun 2003 02:58:02 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 31722-01 for ; Wed, 11 Jun 2003 23:57:52 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id E9E4F30E65A for ; Wed, 11 Jun 2003 23:57:51 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5C2vpU6026069; Wed, 11 Jun 2003 22:57:52 -0400 (EDT) To: pginfo Cc: "pgsql-performance@postgresql.org" Subject: Re: left join performance problem In-reply-to: <3EE74C2D.88390062@t1.unisoftbg.com> References: <3EE74C2D.88390062@t1.unisoftbg.com> Comments: In-reply-to pginfo message dated "Wed, 11 Jun 2003 17:35:10 +0200" Date: Wed, 11 Jun 2003 22:57:51 -0400 Message-ID: <26068.1055386671@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/53 X-Sequence-Number: 2137 pginfo writes: > I have a big problem with pg left join performance. I think the problem is that the LEFT JOIN clause is forcing the planner to join A_SKLAD to A_MESKLAD before anything else, whereas a good plan would do some of the other joins first to eliminate as many rows as possible. You will need to revise the query to let the LEFT JOIN happen later. For discussion see http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=explicit-joins.html regards, tom lane From pgsql-performance-owner@postgresql.org Thu Jun 12 02:52:48 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1A08430E5CD for ; Thu, 12 Jun 2003 05:52:44 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 96337-02 for ; Thu, 12 Jun 2003 02:52:08 -0300 (ADT) Received: from unimm.unisoftbg.com (mail.unisoftbg.com [194.12.229.207]) by svr1.postgresql.org (Postfix) with ESMTP id 31FEF30E5BA for ; Thu, 12 Jun 2003 02:51:54 -0300 (ADT) Received: (qmail 22920 invoked by uid 507); 12 Jun 2003 05:55:17 -0000 Received: from unknown (HELO t1.unisoftbg.com) (pginfo%t1.unisoftbg.com@194.12.229.193) by 0 with SMTP; 12 Jun 2003 05:55:17 -0000 Message-ID: <3EE8061B.1FAED8AD@t1.unisoftbg.com> Date: Thu, 12 Jun 2003 06:48:27 +0200 From: pginfo X-Mailer: Mozilla 4.03 [en] (Win95; I) MIME-Version: 1.0 To: Tom Lane Cc: "pgsql-performance@postgresql.org" Subject: Re: left join performance problem References: <3EE74C2D.88390062@t1.unisoftbg.com> <26068.1055386671@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="------------18E76A8EC6AEFB84026890A9" X-Archive-Number: 200306/54 X-Sequence-Number: 2138 --------------18E76A8EC6AEFB84026890A9 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Many thanks Tom, the doc do not contain solution for this case, but the idea to change the join order was excelent and all is working fine at the moment. regards, ivan. Tom Lane wrote: > pginfo writes: > > I have a big problem with pg left join performance. > > I think the problem is that the LEFT JOIN clause is forcing the > planner to join A_SKLAD to A_MESKLAD before anything else, whereas > a good plan would do some of the other joins first to eliminate > as many rows as possible. You will need to revise the query to > let the LEFT JOIN happen later. For discussion see > http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=explicit-joins.html > > regards, tom lane --------------18E76A8EC6AEFB84026890A9 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Many thanks Tom,
the doc do not contain solution for this case, but the idea to
change the join order was excelent and all is working fine at the moment.

regards,
ivan.

Tom Lane wrote:

pginfo <pginfo@t1.unisoftbg.com> writes:
> I have a big problem with pg left join performance.

I think the problem is that the LEFT JOIN clause is forcing the
planner to join A_SKLAD to A_MESKLAD before anything else, whereas
a good plan would do some of the other joins first to eliminate
as many rows as possible.  You will need to revise the query to
let the LEFT JOIN happen later.  For discussion see
http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=explicit-joins.html

                        regards, tom lane

  --------------18E76A8EC6AEFB84026890A9-- From pgsql-performance-owner@postgresql.org Thu Jun 12 06:32:37 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id C610930E71D for ; Thu, 12 Jun 2003 09:32:32 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 21953-07 for ; Thu, 12 Jun 2003 06:32:21 -0300 (ADT) Received: from viefep15-int.chello.at (viefep15-int.chello.at [213.46.255.19]) by svr1.postgresql.org (Postfix) with ESMTP id 3D72130E68A for ; Thu, 12 Jun 2003 06:32:18 -0300 (ADT) Received: from andi-lap ([80.108.209.54]) by viefep15-int.chello.at (InterMail vM.5.01.05.17 201-253-122-126-117-20021021) with SMTP id <20030612093205.FIQB1476.viefep15-int.chello.at@andi-lap>; Thu, 12 Jun 2003 11:32:05 +0200 Received: by andi-lap (sSMTP sendmail emulation); Thu, 12 Jun 2003 11:32:09 +0200 Subject: Re: Table Relationships From: Andreas Kostyrka To: Victor Yegorov Cc: Jeandre du Toit , pgsql-performance@postgresql.org In-Reply-To: <20030530101009.GD23596@nordlb.lv> References: <001c01c32689$82da1050$0403a8c0@fejleszt4> <20030530101009.GD23596@nordlb.lv> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-ViyGaq0SsXk06YrmMoFm" Organization: Message-Id: <1055357830.5850.5.camel@andi-lap> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 Date: 12 Jun 2003 11:32:09 +0200 X-Archive-Number: 200306/55 X-Sequence-Number: 2139 --=-ViyGaq0SsXk06YrmMoFm Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Fri, 2003-05-30 at 12:10, Victor Yegorov wrote: > Take a look at situation from another side. >=20 > Let's say: You own a store and have 3 customers and 5 products on your > store. All you going to keep in DB is track of all purchases. >=20 > So, each time a customer will by a product, an new record will be added. > What this means: >=20 > 1. Customer's name will be repeated as many times, as many purchases he h= ad > made. The same for each of products. In real world, you'll have about > 10,000 customers and about 100,000 products. Do you have enoght space = on > your disks to store all that stuff? Well, to play the devil's advocate, to do it correctly, you should probably store the customer data duplicate (one in the main record, and once in the purchase order). If you do not, you'll get an ERP system that is incapable to reproduce work done, which is basically a BAD THING(tm) :) > 2. Some of your customers decided to change it's name. What you're going = to > do? If you're going to insert new purchases of that customer with he's= new > name, then in all turnover reports you'll have to specify both: > old name and new one. If he will hange his name again - again, all > reports are to be updated. Well, again, a purchase order should keep records -> it shouldn't magically change the name or address of the customer, just because the customer moved. Andreas --=-ViyGaq0SsXk06YrmMoFm Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQA+53uGHJdudm4KnO0RAi4BAKDVfF+xXeWjQR14ZgRE6okJdwDQbQCgg+tg LimW7YtAKlcD+A37741ATX8= =zCRP -----END PGP SIGNATURE----- --=-ViyGaq0SsXk06YrmMoFm-- From pgsql-performance-owner@postgresql.org Thu Jun 12 13:40:12 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id AB8F330E988 for ; Thu, 12 Jun 2003 16:40:07 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 02674-03 for ; Thu, 12 Jun 2003 13:39:57 -0300 (ADT) Received: from fddlnint05.fds.com (fddlnint05.fds.com [208.15.91.52]) by svr1.postgresql.org (Postfix) with ESMTP id DF49530E944 for ; Thu, 12 Jun 2003 13:39:56 -0300 (ADT) Subject: new monster box CONF suggestion please To: pgsql-performance@postgresql.org X-Mailer: Lotus Notes Release 6.0 September 26, 2002 Message-ID: From: "Patrick Hatcher" Date: Thu, 12 Jun 2003 09:33:34 -0700 X-MIMETrack: Serialize by Router on FDDLNINT05/FSG/SVR/FDD(Release 5.0.4 |June 8, 2000) at 06/12/2003 12:35:37 PM MIME-Version: 1.0 Content-type: text/plain; charset=us-ascii X-Archive-Number: 200306/56 X-Sequence-Number: 2140 Howdy folks. We just received an new monster box, and I would like to field suggestion on setting up the Conf file for the best performance **************BOX INFO*************** Compaq 2 x 2GHZ XEON processors 7 gigs RAM 100 gigs HD ***************************************** **********Expected number of Users and connection type: 200 users with 80% connection via VB front end. 20% Web (PHP) **********Dbase Usage: This is a mostly a reporting database, so there will be heavy usage of aggregates (sum,avg, etc) *********Data Loading 95% of database is truncated and refreshed nightly from mulitple datasources. I have a concern with one particular summary table that takes 20 mins to do an insert/update from 4 individual talbes on our curent system. Not sure what other infomation I should provide. TIA -patrick Patrick Hatcher Macys.Com From pgsql-performance-owner@postgresql.org Fri Jun 13 00:50:49 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 0A5DA30EACD for ; Fri, 13 Jun 2003 03:50:21 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 35424-04 for ; Fri, 13 Jun 2003 00:50:10 -0300 (ADT) Received: from srvr3.iniquinet.com (srvr2.iniquinet.com [64.240.87.12]) by svr1.postgresql.org (Postfix) with SMTP id 5587630EAF3 for ; Fri, 13 Jun 2003 00:50:09 -0300 (ADT) Received: (qmail 15468 invoked by uid 104); 13 Jun 2003 03:52:11 -0000 Received: from Robert_Creager@LogicalChaos.org by srvr3.iniquinet.com by uid 101 with qmail-scanner-1.15 (clamscan: 0.54. spamassassin: 2.55. Clear:SA:0(-11.0/6.0):. Processed in 10.409785 secs); 13 Jun 2003 03:52:11 -0000 Received: from vsat-148-64-8-86.c119.t7.mrt.starband.net (HELO chaos.mshome.net) (148.64.8.86) by srvr3.iniquinet.com with SMTP; 13 Jun 2003 03:52:00 -0000 Received: from localhost.localdomain (thunder.mshome.net [192.168.0.250]) by localhost.mshome.net (Postfix) with ESMTP id 2D6F91B0F19; Thu, 12 Jun 2003 21:49:53 -0600 (MDT) Received: from logicalchaos.org (thunder.mshome.net [192.168.0.250]) by chaos.mshome.net (Postfix) with SMTP id A3DD21B0F19; Thu, 12 Jun 2003 21:49:35 -0600 (MDT) Date: Thu, 12 Jun 2003 21:49:34 -0600 From: Robert Creager To: pgsql-performance@postgresql.org Cc: Tom Lane Subject: Adjusting fsm values was Re: [BUGS] db growing out of proportion Message-Id: <20030612214934.67533e95.Robert_Creager@LogicalChaos.org> In-Reply-To: <20030530225002.5750376f.Robert_Creager@LogicalChaos.org> References: <8938.1054300299@sss.pgh.pa.us> <20030530212101.37cef86f.Robert_Creager@LogicalChaos.org> <17783.1054354286@sss.pgh.pa.us> <20030530225002.5750376f.Robert_Creager@LogicalChaos.org> Organization: Starlight Vision, LLC. X-Mailer: Sylpheed version 0.8.11claws (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg="pgp-sha1"; boundary="=.7.PWUEX9grzi:2" X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp) X-Archive-Number: 200306/57 X-Sequence-Number: 2141 --=.7.PWUEX9grzi:2 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Hey Tom, Sorry for the long delay. I'd been having mail trouble, and your and postgresql mail servers were bouncing me because Starband (my ISP) doesn't setup a full DNS entry for their clients. I'm now relaying through another host. I'm posting to the performance list, as it seems more appropriate there. The results were not as clear cut as I would of thought. If either fsm_relations, fsm_pages or sort_mem were dropped to their original values, the queries went from 3 hours to not completing 9/15 sets after 13 hours. When the shared buffers were reverted, the set completed in 12 hours. I didn't capture any explains for the problem settings, but will be happy to do so if you would like to see some of the results (if they are different). I'm almost caught up with importing new data (too much rain around here to take new data), and can explain away this weekend. Cheers, Rob On Fri, 30 May 2003 22:50:02 -0600 Robert Creager said something like: > On Sat, 31 May 2003 00:11:26 -0400 > Tom Lane said something like: > > > > Cool ... but it's not immediately obvious which of these changes did > > the trick for you. What settings were you at before? And what's > > the details of the problem query? > > > > The first three settings you mention all seem like reasonable > > choices, but I'd be hesitant to recommend 64M sort_mem for general > > use (it won't take very many concurrent sorts to drive you into the > > ground...). So I'm interested to narrow down exactly what was the > > issue here. > > > > regards, tom lane > > shared_buffers was 1024, now 8192 > max_fsm_relations was 1000, now 10000 > max_fsm_pages was 20000, now 100000 > wal_buffers was 8, now 16 > sort_mem was 1024, now 64000 > vacuum_mem was 1024, now 64000 > effective_cache_size was 1000, now 100000 > > I am in the process of reloading the dB, but obs_v and obs_i contain > ~750000 records each. I'd be happy to play around with the settings > if you would like to see the timing results. I'll also be able to get > some explain analyze results tomorrow when finished reloading. > Suggestions as to what values to change first? > > There is a 'C' language trigger on the obs_v and obs_i tables which > essentially combines the data from the the obs_? tables and updates > the catalog table when the obs_? records are updated. > > The query is: > > UPDATE obs_v > SET mag = obs_v.imag + zp.zero_v + cg.color_v * (obs_v.imag - i.imag), > use = true > FROM color_group AS cg, zero_pair AS zp, obs_i AS i, files AS f > WHERE obs_v.star_id = i.star_id > AND obs_v.file_id = f.file_id > AND cg.group_id = f.group_id > AND f.group_id = $group_id > AND zp.pair_id = f.pair_id > > which is called from a perl script (DBD::Pg - which sets $group_id), > and the relevant tables are: > > Table "public.obs_v" > Column | Type | Modifiers > ---------+---------+------------------------------------------------ > x | real | not null > y | real | not null > imag | real | not null > smag | real | not null > ra | real | not null > dec | real | not null > obs_id | integer | not null default nextval('"obs_id_seq"'::text) > file_id | integer | > use | boolean | default false > solve | boolean | default false > star_id | integer | > mag | real | > Indexes: obs_v_file_id_index btree (file_id), > obs_v_loc_index btree (ra, "dec"), > obs_v_obs_id_index btree (obs_id), > obs_v_star_id_index btree (star_id), > obs_v_use_index btree (use) > Foreign Key constraints: obs_v_files_constraint FOREIGN KEY (file_id) > REFERENCES files(file_id) ON UPDATE NO ACTION ON DELETE CASCADE > Triggers: obs_v_trig > > with obs_i being identical (inherited from same root table) > > Table "public.color_group" > Column | Type | Modifiers > ----------+---------+----------- > group_id | integer | > color_u | real | default 0 > color_b | real | default 0 > color_v | real | default 0 > color_r | real | default 0 > color_i | real | default 0 > Indexes: color_group_group_id_index btree (group_id) > Foreign Key constraints: $1 FOREIGN KEY (group_id) REFERENCES > groups(group_id) ON UPDATE NO ACTION ON DELETE CASCADE > > Table "public.zero_pair" > Column | Type | Modifiers > ---------+---------+----------- > pair_id | integer | not null > zero_u | real | default 0 > zero_b | real | default 0 > zero_v | real | default 0 > zero_r | real | default 0 > zero_i | real | default 0 > Indexes: zero_pair_pkey primary key btree (pair_id), > zero_pair_pair_id_index btree (pair_id) > Foreign Key constraints: $1 FOREIGN KEY (pair_id) REFERENCES > pairs(pair_id) ON UPDATE NO ACTION ON DELETE CASCADE > > Table "public.files" > Column | Type | Modifiers > > ----------+--------------------------+------------------------------- > ------------------------ > file_id | integer | not null default > nextval('"files_file_id_seq"'::text) group_id | integer > | > pair_id | integer | > date | timestamp with time zone | not null > name | character varying | not null > ra_min | real | default 0 > ra_max | real | default 0 > dec_min | real | default 0 > dec_max | real | default 0 > Indexes: files_pkey primary key btree (file_id), > files_name_key unique btree (name), > files_id_index btree (file_id, group_id, pair_id), > files_range_index btree (ra_min, ra_max, dec_min, dec_max), > imported__file_id_idex btree (file_id) > Foreign Key constraints: $1 FOREIGN KEY (group_id) REFERENCES > groups(group_id) ON UPDATE NO ACTION ON DELETE CASCADE, > $2 FOREIGN KEY (pair_id) REFERENCES > pairs(pair_id) ON UPDATE NO ACTION ON DELETE > CASCADE > > Table "public.catalog" > Column | Type | Modifiers > > ------------------+------------------+------------------------------- > ------------------ > star_id | integer | not null default > nextval('"star_id_seq"'::text) loc_count | integer | > default 0 ra | real | not null > ra_sum | double precision | default 0 > ra_sigma | real | default 0 > ra_sum_square | double precision | default 0 > dec | real | not null > dec_sum | double precision | default 0 > dec_sigma | real | default 0 > dec_sum_square | double precision | default 0 > mag_u_count | integer | default 0 > mag_u | real | default 99 > mag_u_sum | double precision | default 0 > mag_u_sigma | real | default 0 > mag_u_sum_square | double precision | default 0 > mag_b_count | integer | default 0 > mag_b | real | default 99 > mag_b_sum | double precision | default 0 > mag_b_sigma | real | default 0 > mag_b_sum_square | double precision | default 0 > mag_v_count | integer | default 0 > mag_v | real | default 99 > mag_v_sum | double precision | default 0 > mag_v_sigma | real | default 0 > mag_v_sum_square | double precision | default 0 > mag_r_count | integer | default 0 > mag_r | real | default 99 > mag_r_sum | double precision | default 0 > mag_r_sigma | real | default 0 > mag_r_sum_square | double precision | default 0 > mag_i_count | integer | default 0 > mag_i | real | default 99 > mag_i_sum | double precision | default 0 > mag_i_sigma | real | default 0 > mag_i_sum_square | double precision | default 0 > Indexes: catalog_pkey primary key btree (star_id), > catalog_ra_decl_index btree (ra, "dec"), > catalog_star_id_index btree (star_id) > > > > -- > O_ > -- O_ --=.7.PWUEX9grzi:2 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iEYEARECAAYFAj7pSc8ACgkQgy51bQc2FFkKBACcDtQHlk9LId7HbxVJkfWUR6Et xhYAmwYgSt8cxDk+mORMJWYZz3qUIhVL =s+t6 -----END PGP SIGNATURE----- --=.7.PWUEX9grzi:2-- From pgsql-bugs-owner@postgresql.org Fri Jun 13 02:35:51 2003 X-Original-To: pgsql-bugs-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 0390030EB2D for ; Fri, 13 Jun 2003 05:35:38 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 59599-04 for ; Fri, 13 Jun 2003 02:35:27 -0300 (ADT) Received: from louise.pinerecords.com (louise.pinerecords.com [213.168.176.16]) by svr1.postgresql.org (Postfix) with ESMTP id 34D1A30E903 for ; Fri, 13 Jun 2003 02:35:14 -0300 (ADT) Received: from louise.pinerecords.com (kala@localhost [127.0.0.1]) by louise.pinerecords.com with ESMTP id h5D5Z2Wg027372 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 13 Jun 2003 07:35:02 +0200 Received: (from kala@localhost) by louise.pinerecords.com (submit) id h5D5Yxqn027351; Fri, 13 Jun 2003 07:34:59 +0200 Date: Fri, 13 Jun 2003 07:34:59 +0200 From: Tomas Szepe To: Tom Lane Cc: pgsql-bugs@postgresql.org Subject: Re: db growing out of proportion Message-ID: <20030613053459.GB23789@louise.pinerecords.com> References: <8938.1054300299@sss.pgh.pa.us> <20030530225939.GE21944@louise.pinerecords.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030530225939.GE21944@louise.pinerecords.com> User-Agent: Mutt/1.4.1i X-Archive-Number: 200306/61 X-Sequence-Number: 6156 > [szepe@pinerecords.com] > > > Peter Childs writes: > > > On Fri, 30 May 2003, Tomas Szepe wrote: > > >> Trouble is, as the rows in the tables get deleted/inserted/updated > > >> (the frequency being a couple thousand rows per minute), the database > > >> is growing out of proportion in size. > > > > > Would more regular vacuum help. I think a vaccum every hour may do > > > the job. > > > > Also note that no amount of vacuuming will save you if the FSM is not > > large enough to keep track of all the free space. The default FSM > > settings, like all the other default settings in Postgres, are set up > > for a small installation. You'd probably need to raise them by at least > > a factor of 10 for this installation. > > Thanks, I'll try to tweak those settings and will let the list know how > things went. Well, raising max_fsm_pages to 500000 seems to have solved the problem entirely. My thanks go to everyone who've offered their help. -- Tomas Szepe From pgsql-performance-owner@postgresql.org Fri Jun 13 09:39:38 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 79E6030DC26 for ; Fri, 13 Jun 2003 12:39:35 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 11569-09 for ; Fri, 13 Jun 2003 09:39:25 -0300 (ADT) Received: from mail2.mediadesign.nl (md2.mediadesign.nl [212.19.205.67]) by svr1.postgresql.org (Postfix) with SMTP id 12D4430DBB2 for ; Fri, 13 Jun 2003 09:39:24 -0300 (ADT) Received: (qmail 6427 invoked by uid 666); 13 Jun 2003 12:39:22 -0000 Date: Fri, 13 Jun 2003 14:39:22 +0200 From: Vincent van Leeuwen To: pgsql-performance@postgresql.org Subject: Re: tweaking costs to favor nestloop Message-ID: <20030613123922.GX1535@md2.mediadesign.nl> Mail-Followup-To: pgsql-performance@postgresql.org References: <20030611193313.GE1535@md2.mediadesign.nl> <23557.1055362673@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <23557.1055362673@sss.pgh.pa.us> User-Agent: Mutt/1.3.28i X-Archive-Number: 200306/58 X-Sequence-Number: 2142 On 2003-06-11 16:17:53 -0400, Tom Lane wrote: > Vincent van Leeuwen writes: > > I'm unable to tweak the various _cost settings in such a way that attached > > query will use the right plan. > > You aren't going to be able to. You've already overshot a reasonable > random_page_cost setting --- to judge by the relative actual costs of > the merge and hash join, a value somewhere around 3 is appropriate for > your setup. (Assuming I did the math right --- if you set it to 3, > do you get a ratio of merge and hash estimated costs that agrees with > the ratio of actual runtimes?) > Well, random_page_cost is where it is right now because for a number of other queries it seems to give the best result. Specifically, 1.25 seems to be the sweet spot where a number of queries that were using seqscans but should use indexscans started to use indexscans. Tweaking the cpu_index_tuple_cost by rather large margins didn't seem to have any effect on the calculated costs. Going back to a setting of 3 will hurt overall performance, unless we can still get those other queries to use the right plan by tweaking other config parameters. How did you calculate the value of 3? Another problem we've noticed is that on an idle database certain queries are better off using an indexscan than a seqscan, something which the planner already wanted to do. But when the load on the database gets a lot higher, indexscans are consistently slower than seqscans (same query, same parameters). So we had to dick around a bit to favor seqscans more for those queries (we set cpu_operator_cost a lot lower to favor a seqscan+sort over a (reverse? dunno anymore) indexscan). > The problem here is that the costing of the repeated inner index scans > isn't realistic: 35417 probes into "auth" are clearly taking much less > than 35417 times what a single probe could be expected to take. We > talked about how repeated scans would win from caching of the upper > btree levels, but I think there's more to it than that. It occurs to me > that the probes you are making are probably not random and uncorrelated. > They are driven by the values of reportuser.idreporter ... is it fair > to guess that most of the reportuser rows link to just a small fraction > of the total auth population? If so, the caching could be eliminating > most of the reads, not just the upper btree levels, because we're > mostly hitting only small parts of the index and auth tables. > Exactly. I think the 'auth' table is already completely in kernel filesystemcache to begin with, and probably largely in shared_buffers too, since it's a small table that gets hit a lot. Especially on it's primary key, which we use here. > I'm beginning to think that the only reasonable way to model this is to > cost the entire nestloop join as a unit, so that we have access to > statistics about the outer table as well as the indexed table. That > would give us a shot at estimating how much of the index is likely to > get touched. > > As of 7.3 I think all you can do is force nestloop by disabling the > other two join types. > Does 7.4 already have changes in this area that will affect this query? Vincent van Leeuwen Media Design - http://www.mediadesign.nl/ From pgsql-performance-owner@postgresql.org Fri Jun 13 11:07:54 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 2D2F930DBB2 for ; Fri, 13 Jun 2003 14:07:53 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 40445-05 for ; Fri, 13 Jun 2003 11:07:42 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 7218830D18F for ; Fri, 13 Jun 2003 11:07:42 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5DE7gU6000408; Fri, 13 Jun 2003 10:07:42 -0400 (EDT) To: Vincent van Leeuwen Cc: pgsql-performance@postgresql.org Subject: Re: tweaking costs to favor nestloop In-reply-to: <20030613123922.GX1535@md2.mediadesign.nl> References: <20030611193313.GE1535@md2.mediadesign.nl> <23557.1055362673@sss.pgh.pa.us> <20030613123922.GX1535@md2.mediadesign.nl> Comments: In-reply-to Vincent van Leeuwen message dated "Fri, 13 Jun 2003 14:39:22 +0200" Date: Fri, 13 Jun 2003 10:07:42 -0400 Message-ID: <407.1055513262@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/59 X-Sequence-Number: 2143 Vincent van Leeuwen writes: > How did you calculate the value of 3? Estimated cost of an indexscan is approximately proportional to random_page_cost, but cost of a seqscan isn't affected by it. You had a hash join plan that used two seqscans (so its estimated cost is unaffected by random_page_cost) plus a merge join plan that had one indexscan input. I just extrapolated the change in the indexscan cost needed to make the ratio of total costs agree with reality. This is a pretty rough calculation of course, but I don't believe small values of random_page_cost except for situations where all your data is buffered in RAM. It's real easy to get led down the garden path by small test cases that get fully buffered (especially when you repeat them over and over), and pick cost values that will not reflect reality in a production environment. I can't say whether that actually happened to you, but it's something to be on your guard about. > Another problem we've noticed is that on an idle database certain queries are > better off using an indexscan than a seqscan, something which the planner > already wanted to do. But when the load on the database gets a lot higher, > indexscans are consistently slower than seqscans (same query, same > parameters). See above. Increasing load reduces the chances that any one query will find its data already buffered, since there's more competition for the available buffer space. > Does 7.4 already have changes in this area that will affect this query? No. regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jun 13 15:45:21 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 4E88030EA0C for ; Fri, 13 Jun 2003 18:45:19 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 86328-02 for ; Fri, 13 Jun 2003 15:45:08 -0300 (ADT) Received: from nitrogen.id.pl (smtp.id.pl [193.178.214.4]) by svr1.postgresql.org (Postfix) with SMTP id 4E04530EA6F for ; Fri, 13 Jun 2003 15:45:07 -0300 (ADT) Received: (qmail 24016 invoked by uid 0); 13 Jun 2003 18:45:06 -0000 Received: from siaco.id.pl (213.25.114.8) by smtp.id.pl with SMTP; 13 Jun 2003 18:45:06 -0000 Received: (qmail 21964 invoked by uid 1000); 13 Jun 2003 18:45:06 -0000 Date: Fri, 13 Jun 2003 20:45:06 +0200 From: Ryszard Lach To: pgsql-performance@postgresql.org Subject: 7.3 vs 7.2 - different query plan, bad performance Message-ID: <20030613184506.GE21614@siaco.id.pl> Reply-To: Ryszard Lach Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-My-GPG-Key: echo | mail -s "send key pub" ryszard@lach.name User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/60 X-Sequence-Number: 2144 Hi. I have a problem with performance after upgrading from 7.2 to 7.3. Let's see two simple tables: CREATE TABLE a ( id integer, parent_id integer ); with 1632 records, and CREATE TABLE b ( id integer ); with 5281 records, and a litle more complex view: CREATE VIEW v_c AS SELECT t1.id, (SELECT count(*) AS count FROM a t3 WHERE (t3.parent_id = t2.id)) AS children_count FROM (b t1 LEFT JOIN a t2 ON ((t1.id = t2.id))); Now see the query run under explain analyze: Postgresql 7.2: siaco=# explain analyze select count(*) from v_c; NOTICE: QUERY PLAN: Aggregate (cost=219.66..219.66 rows=1 width=8) (actual time=162.75..162.75 rows=1 loops=1) -> Merge Join (cost=139.66..207.16 rows=5000 width=8) (actual time=95.07..151.46 rows=5281 loops=1) -> Sort (cost=69.83..69.83 rows=1000 width=4) (actual time=76.18..82.37 rows=5281 loops=1) -> Seq Scan on b t1 (cost=0.00..20.00 rows=1000 width=4) (actual time=0.02..22.02 rows=5281 loops=1) -> Sort (cost=69.83..69.83 rows=1000 width=4) (actual time=18.86..25.38 rows=5281 loops=1) -> Seq Scan on a t2 (cost=0.00..20.00 rows=1000 width=4) (actual time=0.02..6.70 rows=1632 loops=1) Total runtime: 164.34 msec EXPLAIN Postgresql 7.3: siaco=# explain analyze select count(*) from v_c; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=224.66..224.66 rows=1 width=8) (actual time=5691.77..5691.77 rows=1 loops=1) -> Subquery Scan v_c (cost=139.66..212.16 rows=5000 width=8) (actual time=24.72..5687.77 rows=5281 loops=1) -> Merge Join (cost=139.66..212.16 rows=5000 width=8) (actual time=24.72..5681.55 rows=5281 loops=1) Merge Cond: ("outer".id = "inner".id) -> Sort (cost=69.83..72.33 rows=1000 width=4) (actual time=18.82..21.09 rows=5281 loops=1) Sort Key: t1.id -> Seq Scan on b t1 (cost=0.00..20.00 rows=1000 width=4) (actual time=0.01..7.28 rows=5281 loops=1) -> Sort (cost=69.83..72.33 rows=1000 width=4) (actual time=4.74..7.15 rows=5281 loops=1) Sort Key: t2.id -> Seq Scan on a t2 (cost=0.00..20.00 rows=1000 width=4) (actual time=0.02..2.13 rows=1632 loops=1) SubPlan -> Aggregate (cost=22.51..22.51 rows=1 width=0) (actual time=1.07..1.07 rows=1 loops=5281) -> Seq Scan on a t3 (cost=0.00..22.50 rows=5 width=0) (actual time=0.80..1.06 rows=1 loops=5281) Filter: (parent_id = $0) Total runtime: 5693.62 msec (15 rows) I can't understand where comes the big difference in query plan from, and (that's more important) - how to force postgres 7.3 to execute it more efficient? Notice, that both databases on both machines are identical and machine with postgres 7.3 is even faster than the other one. Richard. -- "First they ignore you. Then they laugh at you. Then they fight you. Then you win." - Mohandas Gandhi. From pgsql-performance-owner@postgresql.org Fri Jun 13 15:51:31 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 45C9030D6D2 for ; Fri, 13 Jun 2003 18:51:29 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 76057-09 for ; Fri, 13 Jun 2003 15:51:17 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 362AF30EB4C for ; Fri, 13 Jun 2003 15:51:16 -0300 (ADT) Received: (qmail 19818 invoked by uid 500); 13 Jun 2003 18:54:05 -0000 Date: Fri, 13 Jun 2003 13:54:05 -0500 From: Bruno Wolff III To: Ryszard Lach Cc: pgsql-performance@postgresql.org Subject: Re: 7.3 vs 7.2 - different query plan, bad performance Message-ID: <20030613185405.GB19711@wolff.to> Mail-Followup-To: Ryszard Lach , pgsql-performance@postgresql.org References: <20030613184506.GE21614@siaco.id.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030613184506.GE21614@siaco.id.pl> User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/61 X-Sequence-Number: 2145 On Fri, Jun 13, 2003 at 20:45:06 +0200, Ryszard Lach wrote: > I can't understand where comes the big difference in query plan from, and > (that's more important) - how to force postgres 7.3 to execute it more > efficient? I am guessing that your are really using 7.3.x and not 7.3. There was a bug in 7.3 that was fixed in 7.3.1 or 7.3.2 with subselects. However this fix was made with safety in mind (as it was a point release) and resulted in some queries running slower. A complete fix was made for 7.4. To test to see if this is really the problem, you could try a 7.4 snapshot or 7.3 to see if you get improved plans. From pgsql-performance-owner@postgresql.org Fri Jun 13 19:33:56 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 35CB130DE14 for ; Fri, 13 Jun 2003 22:33:55 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 11407-03 for ; Fri, 13 Jun 2003 19:33:44 -0300 (ADT) Received: from shire.ontko.com (shire.ontko.com [199.164.165.1]) by svr1.postgresql.org (Postfix) with ESMTP id 304DC30DDDF for ; Fri, 13 Jun 2003 19:33:44 -0300 (ADT) Received: from nick (bilbo.ontko.com [199.164.165.101]) by shire.ontko.com (8.12.3/8.12.3/Debian-6.4) with SMTP id h5DMXX3J005461; Fri, 13 Jun 2003 17:33:34 -0500 Reply-To: From: "Nick Fankhauser" To: , Subject: Re: Re-ordering .CONF params ... questions for this list Date: Fri, 13 Jun 2003 17:31:54 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 In-Reply-To: <200306101101.46304.josh@agliodbs.com> Importance: Normal X-Archive-Number: 200306/62 X-Sequence-Number: 2146 Josh- I took a quick look at your proposal on conf ordering- The groupings are great. Without a clear notion of dependencies, and only based on what I think people are likely to tweak the most, I'd suggest promoting the "client connection defaults", "version/platform compatibility" & "logging/debugging" groups to positions 2,3 & 4 respectively. Here's the thinking- You'd have all of the options that a neophyte might need to set to perform a particular task in a given environment in the first three groups. Problems encountered while setting these up might require the adventurous beginner to dip into logging/debugging to gather basic diagnostic info. With this ordering, everything you might have to touch in order to get a basic system up & running lives in the top 4 groups. (This also helps soften the dilemma of where enable_implicit_from should go by putting the two possible groups next to one another.) Below the top four groups are the tuning parameters best not messed with until one passes from neophyte to DB-Geek level. (And probably not worth messing with even then.) These are only needed when you've passed over from getting it running to needing it to run better. -Nick > -----Original Message----- > From: pgsql-performance-owner@postgresql.org > [mailto:pgsql-performance-owner@postgresql.org]On Behalf Of Josh Berkus > Sent: Tuesday, June 10, 2003 1:02 PM > To: pgsql-performance@postgresql.org > Subject: [PERFORM] Re-ordering .CONF params ... questions for this list > > > Folks, > > We've been discussing this for a while on HACKERS. However, I > haven't been > getting much feedback on the specific order proposed. > > Attached is an outline of my proposed re-ordering of > postgresql.conf.sample. > Please send me comments. I need to submit a patch by Thursday, > so don't take > too long. > > This is an effort to make the order of run-time params in > postgresql.conf.sample and in the docs more logical and less > baffling to the > new DBA. > > Questions: > 1) Should "enable_implicit_from" go in the "Version/Platform > Compatibility" > section where I have it now, or in "CLIENT CONNECTIONS-Statement > Behavior", > or somewhere else? > > 2) Where should "preload_libraries" go? I'm very reluctant to start a > "Misc." section. Perhaps I should start a "LIBRARIES" section? > > 3) I have re-ordered each subsection somewhat. The fixed > ordering is based > on: > a) My guess at the frequency with which that option will > be changed, > with more common options toward the top of the subsection; > b) Grouping for tightly related options and for options > that cascade; > c) where (a) and (b) are unclear, alpha order. > Does this order make sense looking at the file? > > 3) Should we use indenting in PostgreSQL.conf.sample? I tend to > think it > would make the file easier to read, but I'm not sure what effect it would > have, if any, on parsing the file and whether other people would > find it easy > to read. > > > > -- > -Josh Berkus > Aglio Database Solutions > San Francisco > From pgsql-performance-owner@postgresql.org Fri Jun 13 19:52:08 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 80D4830DEA6 for ; Fri, 13 Jun 2003 22:52:07 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 09655-08 for ; Fri, 13 Jun 2003 19:51:57 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id AE9F430E224 for ; Fri, 13 Jun 2003 19:51:56 -0300 (ADT) Received: from [66.219.92.2] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3117973; Fri, 13 Jun 2003 15:52:05 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: , Subject: Re: Re-ordering .CONF params ... questions for this list Date: Fri, 13 Jun 2003 15:51:14 -0700 User-Agent: KMail/1.4.3 References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200306131551.14891.josh@agliodbs.com> X-Archive-Number: 200306/63 X-Sequence-Number: 2147 Nick, > Without a clear notion of dependencies, and only based on what I think > people are likely to tweak the most, I'd suggest promoting the "client > connection defaults", "version/platform compatibility" & "logging/debuggi= ng" > groups to positions 2,3 & 4 respectively. I like your ideas, but there's two problems with them: 1) I mess around with postgresql.conf constantly, and seldom touch anything= in=20 the "client connection defaults" section. I do, however, mess with the stu= ff=20 in the "resource usage" section, as to most of the people on this list. 2) I just spent 4.5 hours re-arranging the Runtime-config docs page last=20 night, and am very reluctant to do it again. --=20 -Josh Berkus ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco From pgsql-advocacy-owner@postgresql.org Sat Jun 14 11:42:25 2003 X-Original-To: pgsql-advocacy-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 00BB230E86D; Sat, 14 Jun 2003 14:42:24 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 47824-03; Sat, 14 Jun 2003 11:42:13 -0300 (ADT) Received: from falcon.mail.pas.earthlink.net (falcon.mail.pas.earthlink.net [207.217.120.74]) by svr1.postgresql.org (Postfix) with ESMTP id 5782830E601; Sat, 14 Jun 2003 11:42:13 -0300 (ADT) Received: from 0-1pool116-90.nas15.indianapolis1.in.us.da.qwest.net ([65.128.116.90] helo=nick) by falcon.mail.pas.earthlink.net with smtp (Exim 3.33 #1) id 19RCEN-00013q-00; Sat, 14 Jun 2003 07:42:12 -0700 Reply-To: From: "Nick Fankhauser" To: , Cc: Subject: A bit OT- RE: [PERFORM] Re-ordering .CONF params ... questions for this list Date: Sat, 14 Jun 2003 09:40:30 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) In-Reply-To: <200306131551.14891.josh@agliodbs.com> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal X-Archive-Number: 200306/90 X-Sequence-Number: 1302 > 2) I just spent 4.5 hours re-arranging the Runtime-config docs page last > night, and am very reluctant to do it again. I like this reason... I think you've already done a great service by creating functional groups. The newbies won't be hurt by the need to scroll down a bit, and the functional groupings already serve to eliminate the confusion about what the params are for (which *does* hurt them). What you've done is a great improvement. My additional comments below are offered in the spirit of support for what you've already done along with thoughts to consider for future revisions. > 1) I mess around with postgresql.conf constantly, and seldom > touch anything in > the "client connection defaults" section. I do, however, mess > with the stuff > in the "resource usage" section, as to most of the people on this list. I agree... but are we the folks that the conf file needs to be made more intuitive for? If the intent is to make it easier for experienced folks like ourselves who are working with large or unusual databases to deal with PostgreSQL, then certainly the resource usage and tuning settings should go to the top. We'll set the other params once & never touch them again. On the other hand, I suspect that the majority of postgresql users play with the other params a bit during install to get their systems working and never touch the resource usage or tuning params ever. (And this is as it should be, given that the defaults are reasonable for most systems.) Part of my motivation in offering this advice is our sibling rivalry with MySQL- once we look under the hood, we usually find that PostgreSQL is the way to go, but all of us mechanics spend a silly amount of time wondering aloud why the many people who don't enjoy looking under the hood don't get it. If we want the legions of MySQL followers to get it, we need to put only the necessary instruments on the dashboard and not force non-mechanics to look under the hood. (And to stretch the metaphor a bit further- The hood latch still needs to be near the dashboard for the folks who are ready for the next step.) I'll cross-post this to advocacy because I'm tottering off on that tangent. I think the comments may be useful in this forum as well because the advocacy folks need to pass thoughts to the active developers & documenters in much the same way that marketing folks need to communicate well with engineers in the commercial world. Regards, -Nick From pgsql-performance-owner@postgresql.org Sun Jun 15 11:26:46 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 79B4030DBFE for ; Sun, 15 Jun 2003 14:26:46 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 42111-03 for ; Sun, 15 Jun 2003 11:26:36 -0300 (ADT) Received: from game.over.net (unknown [193.189.169.9]) by svr1.postgresql.org (Postfix) with ESMTP id 7654930D6D9 for ; Sun, 15 Jun 2003 11:26:35 -0300 (ADT) Received: from localhost.over.net ([127.0.0.1]:9 "EHLO zvezek.over.net") by mail.over.net with ESMTP id ; Sun, 15 Jun 2003 16:26:35 +0200 Message-Id: <5.2.1.1.0.20030615161722.025c7630@127.0.0.1> X-Sender: tmail@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Sun, 15 Jun 2003 16:26:36 +0200 To: pgsql-performance@postgresql.org From: Tomaz Borstnar Subject: any way to use indexscan to get last X values with "order by Y limit X" clause? Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200306/65 X-Sequence-Number: 2149 Similar question was http://archives.postgresql.org/pgsql-admin/2002-05/msg00148.php, but google did not have answer for it. Here is the structure: Column | Type | Modifiers -------------+--------------------------+---------------------- id | integer | not null default '0' datestamp | timestamp with time zone | not null thread | integer | not null default '0' parent | integer | not null default '0' author | character(37) | not null default '' subject | character(255) | not null default '' email | character(200) | not null default '' attachment | character(64) | default '' host | character(50) | not null default '' email_reply | character(1) | not null default 'N' approved | character(1) | not null default 'N' msgid | character(100) | not null default '' modifystamp | integer | not null default '0' userid | integer | not null default '0' closed | smallint | default '0' Indexes: tjavendanpri_key primary key btree (id), tjavendan_approved btree (approved), tjavendan_author btree (author), tjavendan_datestamp btree (datestamp), tjavendan_modifystamp btree (modifystamp), tjavendan_msgid btree (msgid), tjavendan_parent btree (parent), tjavendan_subject btree (subject), tjavendan_thread btree (thread), tjavendan_userid btree (userid) Here is the query: SELECT thread, modifystamp, count(id) AS tcount, abstime(modifystamp) AS latest, max(id) as maxid FROM tjavendan WHERE approved='Y' GROUP BY thread, modifystamp ORDER BY modifystamp desc, thread desc limit 40 and explain analyze for it: krtjavendan34=> EXPLAIN ANALYZE SELECT thread, modifystamp, count(id) AS tcount, abstime(modifystamp) AS latest, max(id) as maxid FROM tjavendan WHERE approved='Y' GROUP BY thread, modifystamp ORDER BY modifystamp desc, thread desc limit 40; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=18419.78..18419.88 rows=40 width=12) (actual time=6735.06..6735.69 rows=40 loops=1) -> Sort (cost=18419.78..18441.34 rows=8626 width=12) (actual time=6735.04..6735.25 rows=41 loops=1) Sort Key: modifystamp, thread -> Aggregate (cost=16777.53..17855.84 rows=8626 width=12) (actual time=4605.01..6711.27 rows=2938 loops=1) -> Group (cost=16777.53..17424.52 rows=86265 width=12) (actual time=4604.85..6164.29 rows=86265 loops=1) -> Sort (cost=16777.53..16993.19 rows=86265 width=12) (actual time=4604.82..5130.14 rows=86265 loops=1) Sort Key: thread, modifystamp -> Seq Scan on tjavendan (cost=0.00..9705.31 rows=86265 width=12) (actual time=0.13..3369.28 rows=86265 loops=1) Filter: (approved = 'Y'::bpchar) Total runtime: 6741.12 msec (10 rows) This is on 7.3.3. Having backwards reading of index would really help here. Thanks in advance. Tomaz From pgsql-performance-owner@postgresql.org Sun Jun 15 11:32:39 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 3156030DC43 for ; Sun, 15 Jun 2003 14:32:39 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 45673-01 for ; Sun, 15 Jun 2003 11:32:28 -0300 (ADT) Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id 39BB330D6D9 for ; Sun, 15 Jun 2003 11:32:27 -0300 (ADT) Received: (from root@localhost) by www.pspl.co.in (8.11.6/8.11.6) id h5FEWRu25590 for ; Sun, 15 Jun 2003 20:02:27 +0530 Received: from daithan (daithan.intranet.pspl.co.in [192.168.7.161]) by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h5FEWQ925578 for ; Sun, 15 Jun 2003 20:02:27 +0530 From: "Shridhar Daithankar" To: pgsql-performance@postgresql.org Date: Sun, 15 Jun 2003 20:01:38 +0530 MIME-Version: 1.0 Subject: Re: any way to use indexscan to get last X values with "order by Y limit X" clause? Reply-To: shridhar_daithankar@persistent.co.in Message-ID: <3EECD0A2.8545.2FA1D9@localhost> In-reply-to: <5.2.1.1.0.20030615161722.025c7630@127.0.0.1> X-mailer: Pegasus Mail for Windows (v4.02) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Archive-Number: 200306/66 X-Sequence-Number: 2150 On 15 Jun 2003 at 16:26, Tomaz Borstnar wrote: > > Here is the structure: > approved | character(1) | not null default 'N' > msgid | character(100) | not null default '' > modifystamp | integer | not null default '0' > userid | integer | not null default '0' > closed | smallint | default '0' > Indexes: tjavendanpri_key primary key btree (id), > tjavendan_approved btree (approved), > Here is the query: > SELECT thread, modifystamp, count(id) AS tcount, abstime(modifystamp) AS > latest, max(id) as maxid FROM tjavendan WHERE approved='Y' GROUP BY > thread, modifystamp ORDER BY modifystamp desc, thread desc limit 40 Question. The field approved seems to have boolean values. If probability of having either of value is 50%, I doubt planner will use index anyway. Even assuming all possible values of a char variable, the choice isn't too much, say if you have 1M row. Correct me if I am wrong. Bye Shridhar -- Either one of us, by himself, is expendable. Both of us are not. -- Kirk, "The Devil in the Dark", stardate 3196.1 From pgsql-performance-owner@postgresql.org Sun Jun 15 12:17:24 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id CF09B30E248 for ; Sun, 15 Jun 2003 15:17:23 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 42117-05 for ; Sun, 15 Jun 2003 12:17:13 -0300 (ADT) Received: from game.over.net (unknown [193.189.169.9]) by svr1.postgresql.org (Postfix) with ESMTP id D4D9430E23A for ; Sun, 15 Jun 2003 12:17:12 -0300 (ADT) Received: from localhost.over.net ([127.0.0.1]:12044 "EHLO zvezek.over.net") by mail.over.net with ESMTP id ; Sun, 15 Jun 2003 17:17:12 +0200 Message-Id: <5.2.1.1.0.20030615171224.01c32eb0@127.0.0.1> X-Sender: tmail@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Sun, 15 Jun 2003 17:17:04 +0200 To: pgsql-performance@postgresql.org From: Tomaz Borstnar Subject: Re: any way to use indexscan to get last X values In-Reply-To: <3EECD0A2.8545.2FA1D9@localhost> References: <5.2.1.1.0.20030615161722.025c7630@127.0.0.1> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200306/67 X-Sequence-Number: 2151 At 16:31 15.6.2003, Shridhar Daithankar wrote: >Question. The field approved seems to have boolean values. If probability of >having either of value is 50%, I doubt planner will use index anyway. True. It has Y or N only so index on approved is useless. But using index on ORDER BY part would help a lot since it knows to fetch last X ordered values. >Correct me if I am wrong. Unfortunately you are very right. I am not sure how to stuff modifystamp and thread into WHERE clause to make it use indexes on thread and/or modifystamp. So far I believe this would be the only way to use them, right? Tomaz From pgsql-performance-owner@postgresql.org Sun Jun 15 13:34:07 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id EA09530E8E0 for ; Sun, 15 Jun 2003 16:33:57 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 53259-02 for ; Sun, 15 Jun 2003 13:33:47 -0300 (ADT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by svr1.postgresql.org (Postfix) with ESMTP id 123E830E248 for ; Sun, 15 Jun 2003 13:33:47 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id EDF26D61F; Sun, 15 Jun 2003 09:33:45 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id E3AE25C0C; Sun, 15 Jun 2003 09:33:45 -0700 (PDT) Date: Sun, 15 Jun 2003 09:33:45 -0700 (PDT) From: Stephan Szabo To: Tomaz Borstnar Cc: Subject: Re: any way to use indexscan to get last X values with In-Reply-To: <5.2.1.1.0.20030615161722.025c7630@127.0.0.1> Message-ID: <20030615092752.C31532-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200306/68 X-Sequence-Number: 2152 On Sun, 15 Jun 2003, Tomaz Borstnar wrote: > Similar question was > http://archives.postgresql.org/pgsql-admin/2002-05/msg00148.php, but google > did not have answer for it. > > Here is the structure: > > Column | Type | Modifiers > -------------+--------------------------+---------------------- > id | integer | not null default '0' > datestamp | timestamp with time zone | not null > thread | integer | not null default '0' > parent | integer | not null default '0' > author | character(37) | not null default '' > subject | character(255) | not null default '' > email | character(200) | not null default '' > attachment | character(64) | default '' > host | character(50) | not null default '' > email_reply | character(1) | not null default 'N' > approved | character(1) | not null default 'N' > msgid | character(100) | not null default '' > modifystamp | integer | not null default '0' > userid | integer | not null default '0' > closed | smallint | default '0' > Indexes: tjavendanpri_key primary key btree (id), > tjavendan_approved btree (approved), > tjavendan_author btree (author), > tjavendan_datestamp btree (datestamp), > tjavendan_modifystamp btree (modifystamp), > tjavendan_msgid btree (msgid), > tjavendan_parent btree (parent), > tjavendan_subject btree (subject), > tjavendan_thread btree (thread), > tjavendan_userid btree (userid) > > Here is the query: > SELECT thread, modifystamp, count(id) AS tcount, abstime(modifystamp) AS > latest, max(id) as maxid FROM tjavendan WHERE approved='Y' GROUP BY > thread, modifystamp ORDER BY modifystamp desc, thread desc limit 40 I'm not sure that it'd help since I don't think it'd realize that it doesn't actually need to completely do the group by due to the order by, but in any case, in the above, the sort orders are different for the group by and the order by and you'd really want a two column index on (probably) (modifystamp, thread) in order to get the best results on replacing a scan + sort. From pgsql-performance-owner@postgresql.org Sun Jun 15 13:53:26 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 626C330E8D3 for ; Sun, 15 Jun 2003 16:53:25 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 47853-07 for ; Sun, 15 Jun 2003 13:53:14 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 4F6A630E8E0 for ; Sun, 15 Jun 2003 13:53:14 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5FGrAU6023330; Sun, 15 Jun 2003 12:53:10 -0400 (EDT) To: Tomaz Borstnar Cc: pgsql-performance@postgresql.org Subject: Re: any way to use indexscan to get last X values with "order by Y limit X" clause? In-reply-to: <5.2.1.1.0.20030615161722.025c7630@127.0.0.1> References: <5.2.1.1.0.20030615161722.025c7630@127.0.0.1> Comments: In-reply-to Tomaz Borstnar message dated "Sun, 15 Jun 2003 16:26:36 +0200" Date: Sun, 15 Jun 2003 12:53:10 -0400 Message-ID: <23329.1055695990@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/69 X-Sequence-Number: 2153 Tomaz Borstnar writes: > SELECT thread, modifystamp, count(id) AS tcount, abstime(modifystamp) AS > latest, max(id) as maxid FROM tjavendan WHERE approved='Y' GROUP BY > thread, modifystamp ORDER BY modifystamp desc, thread desc limit 40 > Having backwards reading of index would really help here. The only way that a fast-start plan is useful is if there is a way to do it with no explicit sort steps at all. A sort step must read its entire input before it can produce any output, so you completely blow the chance of not reading the whole table as soon as there's any sorting. There are a couple of reasons why this query can't be done using only an initial indexscan to sort the data: 1. You don't have a suitable index. Neither an index on modifystamp alone nor an index on thread alone is of any use to produce a two-column ordering; you need a two-column index on (modifystamp, thread). 2. The GROUP BY and ORDER BY steps require different sort orders, and so even if an index satisfied one, there'd still be a sort needed for the other. This is partly your fault (writing the columns in different orders) and partly the system's fault: it's implicitly taking the GROUP BY entries to be equivalent to ORDER BY ASC, which is overspecification. I've applied the attached patch to CVS tip to cure the latter problem. With this, a two-column index, and compatible column ordering in ORDER BY and GROUP BY, I get a reasonable-looking fast-start plan. The patch will not apply exactly against 7.3 because there's a renamed function call in there, but you could make it work with a little effort. regards, tom lane *** src/backend/parser/analyze.c.orig Fri Jun 6 11:04:02 2003 --- src/backend/parser/analyze.c Sun Jun 15 12:05:34 2003 *************** *** 1787,1799 **** */ qry->havingQual = transformWhereClause(pstate, stmt->havingClause); ! qry->groupClause = transformGroupClause(pstate, ! stmt->groupClause, ! qry->targetList); ! qry->sortClause = transformSortClause(pstate, stmt->sortClause, qry->targetList); qry->distinctClause = transformDistinctClause(pstate, stmt->distinctClause, --- 1787,1804 ---- */ qry->havingQual = transformWhereClause(pstate, stmt->havingClause); ! /* ! * Transform sorting/grouping stuff. Do ORDER BY first because both ! * transformGroupClause and transformDistinctClause need the results. ! */ qry->sortClause = transformSortClause(pstate, stmt->sortClause, qry->targetList); + + qry->groupClause = transformGroupClause(pstate, + stmt->groupClause, + qry->targetList, + qry->sortClause); qry->distinctClause = transformDistinctClause(pstate, stmt->distinctClause, *** src/backend/parser/parse_clause.c.orig Fri Jun 6 11:04:02 2003 --- src/backend/parser/parse_clause.c Sun Jun 15 12:19:14 2003 *************** *** 1124,1130 **** * transform a GROUP BY clause */ List * ! transformGroupClause(ParseState *pstate, List *grouplist, List *targetlist) { List *glist = NIL, *gl; --- 1124,1131 ---- * transform a GROUP BY clause */ List * ! transformGroupClause(ParseState *pstate, List *grouplist, ! List *targetlist, List *sortClause) { List *glist = NIL, *gl; *************** *** 1132,1152 **** foreach(gl, grouplist) { TargetEntry *tle; tle = findTargetlistEntry(pstate, lfirst(gl), targetlist, GROUP_CLAUSE); /* avoid making duplicate grouplist entries */ ! if (!targetIsInSortList(tle, glist)) ! { ! GroupClause *grpcl = makeNode(GroupClause); ! ! grpcl->tleSortGroupRef = assignSortGroupRef(tle, targetlist); ! grpcl->sortop = ordering_oper_opid(tle->resdom->restype); ! ! glist = lappend(glist, grpcl); } } return glist; --- 1133,1173 ---- foreach(gl, grouplist) { TargetEntry *tle; + Oid ordering_op; + GroupClause *grpcl; tle = findTargetlistEntry(pstate, lfirst(gl), targetlist, GROUP_CLAUSE); /* avoid making duplicate grouplist entries */ ! if (targetIsInSortList(tle, glist)) ! continue; ! /* ! * If the GROUP BY clause matches the ORDER BY clause, we want to ! * adopt the ordering operators from the latter rather than using ! * the default ops. This allows "GROUP BY foo ORDER BY foo DESC" to ! * be done with only one sort step. Note we are assuming that any ! * user-supplied ordering operator will bring equal values together, ! * which is all that GROUP BY needs. ! */ ! if (sortClause && ! ((SortClause *) lfirst(sortClause))->tleSortGroupRef == ! tle->resdom->ressortgroupref) ! { ! ordering_op = ((SortClause *) lfirst(sortClause))->sortop; ! sortClause = lnext(sortClause); } + else + { + ordering_op = ordering_oper_opid(tle->resdom->restype); + sortClause = NIL; /* disregard ORDER BY once match fails */ + } + + grpcl = makeNode(GroupClause); + grpcl->tleSortGroupRef = assignSortGroupRef(tle, targetlist); + grpcl->sortop = ordering_op; + glist = lappend(glist, grpcl); } return glist; *** src/include/parser/parse_clause.h.orig Fri Mar 21 20:49:38 2003 --- src/include/parser/parse_clause.h Sun Jun 15 12:03:13 2003 *************** *** 22,28 **** extern bool interpretInhOption(InhOption inhOpt); extern Node *transformWhereClause(ParseState *pstate, Node *where); extern List *transformGroupClause(ParseState *pstate, List *grouplist, ! List *targetlist); extern List *transformSortClause(ParseState *pstate, List *orderlist, List *targetlist); extern List *transformDistinctClause(ParseState *pstate, List *distinctlist, --- 22,28 ---- extern bool interpretInhOption(InhOption inhOpt); extern Node *transformWhereClause(ParseState *pstate, Node *where); extern List *transformGroupClause(ParseState *pstate, List *grouplist, ! List *targetlist, List *sortClause); extern List *transformSortClause(ParseState *pstate, List *orderlist, List *targetlist); extern List *transformDistinctClause(ParseState *pstate, List *distinctlist, From pgsql-performance-owner@postgresql.org Sun Jun 15 16:48:59 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id B67D630EAEA for ; Sun, 15 Jun 2003 19:48:57 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 77251-03 for ; Sun, 15 Jun 2003 16:48:47 -0300 (ADT) Received: from email02.aon.at (WARSL402PIP7.highway.telekom.at [195.3.96.94]) by svr1.postgresql.org (Postfix) with SMTP id 921D930E973 for ; Sun, 15 Jun 2003 16:48:46 -0300 (ADT) Received: (qmail 374320 invoked from network); 15 Jun 2003 19:48:40 -0000 Received: from m151p018.dipool.highway.telekom.at (HELO cantor) ([62.46.8.210]) (envelope-sender ) by qmail2rs.highway.telekom.at (qmail-ldap-1.03) with SMTP for ; 15 Jun 2003 19:48:40 -0000 From: Manfred Koizar To: Ryszard Lach Cc: pgsql-performance@postgresql.org Subject: Re: 7.3 vs 7.2 - different query plan, bad performance Date: Sun, 15 Jun 2003 21:48:08 +0200 Message-ID: References: <20030613184506.GE21614@siaco.id.pl> In-Reply-To: <20030613184506.GE21614@siaco.id.pl> X-Mailer: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/70 X-Sequence-Number: 2154 On Fri, 13 Jun 2003 20:45:06 +0200, Ryszard Lach wrote: >I have a problem with performance after upgrading from 7.2 to 7.3. Try VACUUM ANALYSE; and then re-run your query. If it is still slow, post the new EXPLAIN ANALYSE output here. Servus Manfred From pgsql-performance-owner@postgresql.org Sun Jun 15 19:38:17 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 6F2DE30ECA1 for ; Sun, 15 Jun 2003 22:38:16 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 86672-07 for ; Sun, 15 Jun 2003 19:38:06 -0300 (ADT) Received: from game.over.net (unknown [193.189.169.9]) by svr1.postgresql.org (Postfix) with ESMTP id 40C5A30D174 for ; Sun, 15 Jun 2003 19:38:05 -0300 (ADT) Received: from localhost.over.net ([127.0.0.1]:48907 "EHLO zvezek.over.net") by mail.over.net with ESMTP id ; Mon, 16 Jun 2003 00:38:05 +0200 Message-Id: <5.2.1.1.0.20030616002729.01bba2e0@127.0.0.1> X-Sender: tmail@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Mon, 16 Jun 2003 00:37:30 +0200 To: pgsql-performance@postgresql.org From: Tomaz Borstnar Subject: Re: any way to use indexscan to get last X values In-Reply-To: <23329.1055695990@sss.pgh.pa.us> References: <5.2.1.1.0.20030615161722.025c7630@127.0.0.1> <5.2.1.1.0.20030615161722.025c7630@127.0.0.1> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200306/71 X-Sequence-Number: 2155 At 18:53 15.6.2003, you wrote: >I've applied the attached patch to CVS tip to cure the latter problem. >With this, a two-column index, and compatible column ordering in ORDER >BY and GROUP BY, I get a reasonable-looking fast-start plan. The patch >will not apply exactly against 7.3 because there's a renamed function >call in there, but you could make it work with a little effort. You mean this: /* * ordering_oper_opid - convenience routine for oprid(ordering_oper()) * * This was formerly called any_ordering_op() */ A little later... WOW! 100 to 130 times faster on same dataset and additional index on (modifystamp,thread) which was not really useful before this patch! krtjavendan34=> EXPLAIN ANALYZE SELECT thread, modifystamp, count(id) AS tcount,abstime(modifystamp) AS latest, max(id) as maxid FROM tjavendan WHERE approved='Y' GROUP BY modifystamp, thread ORDER BY modifystamp desc, thread desc limit 40; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Limit (cost=0.00..97.13 rows=40 width=12) (actual time=1.07..48.71 rows=40 loops=1) -> Aggregate (cost=0.00..20947.38 rows=8626 width=12) (actual time=1.05..48.23 rows=41 loops=1) -> Group (cost=0.00..20516.06 rows=86265 width=12) (actual time=0.35..42.25 rows=843 loops=1) -> Index Scan Backward using tjavendan_modstamp_thrd on tjavendan (cost=0.00..20084.73 rows=86265 width=12) (actual time=0.34..31.29 rows=844 loops=1) Filter: (approved = 'Y'::bpchar) Total runtime: 50.20 msec (6 rows) Used to be between 5800 and 6741 msec before this patch! Thanks! From pgsql-performance-owner@postgresql.org Sun Jun 15 20:21:54 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 6A29030EB32 for ; Sun, 15 Jun 2003 23:21:51 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 93772-07 for ; Sun, 15 Jun 2003 20:21:40 -0300 (ADT) Received: from game.over.net (unknown [193.189.169.9]) by svr1.postgresql.org (Postfix) with ESMTP id 9637B30D174 for ; Sun, 15 Jun 2003 20:21:39 -0300 (ADT) Received: from localhost.over.net ([127.0.0.1]:56077 "EHLO zvezek.over.net") by mail.over.net with ESMTP id ; Mon, 16 Jun 2003 01:21:39 +0200 Message-Id: <5.2.1.1.0.20030616012108.02a9c1d8@127.0.0.1> X-Sender: tmail@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Mon, 16 Jun 2003 01:21:34 +0200 To: pgsql-performance@postgresql.org From: Tomaz Borstnar Subject: Re: any way to use indexscan to get last X values In-Reply-To: <5.2.1.1.0.20030616002729.01bba2e0@127.0.0.1> References: <23329.1055695990@sss.pgh.pa.us> <5.2.1.1.0.20030615161722.025c7630@127.0.0.1> <5.2.1.1.0.20030615161722.025c7630@127.0.0.1> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200306/72 X-Sequence-Number: 2156 Here is the 7.3.3 patch as it might help others too... diff -rcN postgresql-7.3.3/src/backend/parser/analyze.c postgresql-7.3.3-grouporderby/src/backend/parser/analyze.c *** postgresql-7.3.3/src/backend/parser/analyze.c Thu Feb 13 23:50:09 2003 --- postgresql-7.3.3-grouporderby/src/backend/parser/analyze.c Mon Jun 16 00:13:05 2003 *************** *** 1667,1679 **** */ qry->havingQual = transformWhereClause(pstate, stmt->havingClause); ! qry->groupClause = transformGroupClause(pstate, ! stmt->groupClause, ! qry->targetList); qry->sortClause = transformSortClause(pstate, stmt->sortClause, qry->targetList); qry->distinctClause = transformDistinctClause(pstate, stmt->distinctClause, --- 1667,1682 ---- */ qry->havingQual = transformWhereClause(pstate, stmt->havingClause); ! /* ! * Transform sorting/grouping stuff. Do ORDER BY first because both ! * transformGroupClause and transformDistinctClause need the results. ! */ qry->sortClause = transformSortClause(pstate, stmt->sortClause, qry->targetList); + + qry->groupClause = transformGroupClause(pstate, stmt->groupClause, qry->targetList, qry->sortClause); qry->distinctClause = transformDistinctClause(pstate, stmt->distinctClause, diff -rcN postgresql-7.3.3/src/backend/parser/parse_clause.c postgresql-7.3.3-grouporderby/src/backend/parser/parse_clause.c *** postgresql-7.3.3/src/backend/parser/parse_clause.c Mon Dec 16 19:39:56 2002 --- postgresql-7.3.3-grouporderby/src/backend/parser/parse_clause.c Mon Jun 16 00:24:58 2003 *************** *** 1145,1151 **** * */ List * ! transformGroupClause(ParseState *pstate, List *grouplist, List *targetlist) { List *glist = NIL, *gl; --- 1145,1151 ---- * */ List * ! transformGroupClause(ParseState *pstate, List *grouplist, List *targetlist, List *sortClause) { List *glist = NIL, *gl; *************** *** 1153,1173 **** foreach(gl, grouplist) { TargetEntry *tle; tle = findTargetlistEntry(pstate, lfirst(gl), targetlist, GROUP_CLAUSE); /* avoid making duplicate grouplist entries */ ! if (!targetIsInSortList(tle, glist)) ! { ! GroupClause *grpcl = makeNode(GroupClause); ! ! grpcl->tleSortGroupRef = assignSortGroupRef(tle, targetlist); ! ! grpcl->sortop = any_ordering_op(tle->resdom->restype); ! ! glist = lappend(glist, grpcl); ! } } return glist; --- 1153,1193 ---- foreach(gl, grouplist) { TargetEntry *tle; + Oid ordering_op; + GroupClause *grpcl; tle = findTargetlistEntry(pstate, lfirst(gl), targetlist, GROUP_CLAUSE); /* avoid making duplicate grouplist entries */ ! if (targetIsInSortList(tle, glist)) ! continue; ! ! /* ! * If the GROUP BY clause matches the ORDER BY clause, we want to ! * adopt the ordering operators from the latter rather than using ! * the default ops. This allows "GROUP BY foo ORDER BY foo DESC" to ! * be done with only one sort step. Note we are assuming that any ! * user-supplied ordering operator will bring equal values together, ! * which is all that GROUP BY needs. ! */ ! if (sortClause && ! ((SortClause *) lfirst(sortClause))->tleSortGroupRef == ! tle->resdom->ressortgroupref) ! { ! ordering_op = ((SortClause *) lfirst(sortClause))->sortop; ! sortClause = lnext(sortClause); ! } ! else ! { ! ordering_op = any_ordering_op(tle->resdom->restype); ! sortClause = NIL; /* disregard ORDER BY once match fails */ ! } ! ! grpcl = makeNode(GroupClause); ! grpcl->tleSortGroupRef = assignSortGroupRef(tle, targetlist); ! grpcl->sortop = ordering_op; ! glist = lappend(glist, grpcl); } return glist; diff -rcN postgresql-7.3.3/src/include/parser/parse_clause.h postgresql-7.3.3-grouporderby/src/include/parser/parse_clause.h *** postgresql-7.3.3/src/include/parser/parse_clause.h Thu Jun 20 22:29:51 2002 --- postgresql-7.3.3-grouporderby/src/include/parser/parse_clause.h Mon Jun 16 00:08:43 2003 *************** *** 22,28 **** extern bool interpretInhOption(InhOption inhOpt); extern Node *transformWhereClause(ParseState *pstate, Node *where); extern List *transformGroupClause(ParseState *pstate, List *grouplist, ! List *targetlist); extern List *transformSortClause(ParseState *pstate, List *orderlist, List *targetlist); extern List *transformDistinctClause(ParseState *pstate, List *distinctlist, --- 22,28 ---- extern bool interpretInhOption(InhOption inhOpt); extern Node *transformWhereClause(ParseState *pstate, Node *where); extern List *transformGroupClause(ParseState *pstate, List *grouplist, ! List *targetlist, List *sortClause); extern List *transformSortClause(ParseState *pstate, List *orderlist, List *targetlist); extern List *transformDistinctClause(ParseState *pstate, List *distinctlist, From pgsql-performance-owner@postgresql.org Mon Jun 16 02:10:50 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1D3F630EC38 for ; Mon, 16 Jun 2003 05:10:50 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 26438-09 for ; Mon, 16 Jun 2003 02:10:39 -0300 (ADT) Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) by svr1.postgresql.org (Postfix) with SMTP id 2607530EC10 for ; Mon, 16 Jun 2003 02:10:34 -0300 (ADT) Received: (qmail 7221 invoked by uid 1001); 16 Jun 2003 05:10:28 -0000 Date: Mon, 16 Jun 2003 00:10:28 -0500 From: "Jim C. Nasby" To: pgsql-performance@postgresql.org Subject: Re: left join performance problem Message-ID: <20030616001028.Q66185@flake.decibel.org> Reply-To: jim@nasby.net References: <3EE74C2D.88390062@t1.unisoftbg.com> <26068.1055386671@sss.pgh.pa.us> <3EE8061B.1FAED8AD@t1.unisoftbg.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <3EE8061B.1FAED8AD@t1.unisoftbg.com>; from pginfo@t1.unisoftbg.com on Thu, Jun 12, 2003 at 06:48:27AM +0200 X-Operating-System: FreeBSD 4.8-RELEASE i386 X-Distributed: Join the Effort! http://www.distributed.net X-Archive-Number: 200306/73 X-Sequence-Number: 2157 On Thu, Jun 12, 2003 at 06:48:27AM +0200, pginfo wrote: > Many thanks Tom, > the doc do not contain solution for this case, but the idea to > change the join order was excelent and all is working fine at the moment. Any chance of getting a TODO added that would provide the option of having the optimizer pick join order when you're using the ANSI join syntax? IMHO I think it's bad that using the ANSI syntax forces join order; it would be much better to come up with a custom syntax for this like everyone else does. But I'm sure people won't want to change the existing behavior, so special syntax to do the opposite is almost as good. -- Jim C. Nasby (aka Decibel!) jim@nasby.net Member: Triangle Fraternity, Sports Car Club of America Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?" From pgsql-performance-owner@postgresql.org Mon Jun 16 02:17:52 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 406C730ED94 for ; Mon, 16 Jun 2003 05:17:51 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 48318-07 for ; Mon, 16 Jun 2003 02:17:40 -0300 (ADT) Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) by svr1.postgresql.org (Postfix) with SMTP id 4AED930EC38 for ; Mon, 16 Jun 2003 02:17:40 -0300 (ADT) Received: (qmail 7335 invoked by uid 1001); 16 Jun 2003 05:17:40 -0000 Date: Mon, 16 Jun 2003 00:17:40 -0500 From: "Jim C. Nasby" To: pgsql-performance@postgresql.org Subject: Re: tweaking costs to favor nestloop Message-ID: <20030616001740.R66185@flake.decibel.org> Reply-To: jim@nasby.net References: <20030611193313.GE1535@md2.mediadesign.nl> <23557.1055362673@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <23557.1055362673@sss.pgh.pa.us>; from tgl@sss.pgh.pa.us on Wed, Jun 11, 2003 at 04:17:53PM -0400 X-Operating-System: FreeBSD 4.8-RELEASE i386 X-Distributed: Join the Effort! http://www.distributed.net X-Archive-Number: 200306/74 X-Sequence-Number: 2158 Tom- FWIW, these are the same kind of numbers I'm seeing for the project I'm working on.. ie: nested loop estimates at 0.00-3.01 but reality is much closer to 0.2. I agrees that it probably makes sense to take the correlation of both tables into account for nested-loop joins. On Wed, Jun 11, 2003 at 04:17:53PM -0400, Tom Lane wrote: > Vincent van Leeuwen writes: > > I'm unable to tweak the various _cost settings in such a way that attached > > query will use the right plan. > > You aren't going to be able to. You've already overshot a reasonable > random_page_cost setting --- to judge by the relative actual costs of > the merge and hash join, a value somewhere around 3 is appropriate for > your setup. (Assuming I did the math right --- if you set it to 3, > do you get a ratio of merge and hash estimated costs that agrees with > the ratio of actual runtimes?) > > The problem here is that the costing of the repeated inner index scans > isn't realistic: 35417 probes into "auth" are clearly taking much less > than 35417 times what a single probe could be expected to take. We > talked about how repeated scans would win from caching of the upper > btree levels, but I think there's more to it than that. It occurs to me > that the probes you are making are probably not random and uncorrelated. > They are driven by the values of reportuser.idreporter ... is it fair > to guess that most of the reportuser rows link to just a small fraction > of the total auth population? If so, the caching could be eliminating > most of the reads, not just the upper btree levels, because we're > mostly hitting only small parts of the index and auth tables. > > I'm beginning to think that the only reasonable way to model this is to > cost the entire nestloop join as a unit, so that we have access to > statistics about the outer table as well as the indexed table. That > would give us a shot at estimating how much of the index is likely to > get touched. > > As of 7.3 I think all you can do is force nestloop by disabling the > other two join types. > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html > -- Jim C. Nasby (aka Decibel!) jim@nasby.net Member: Triangle Fraternity, Sports Car Club of America Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?" From pgsql-performance-owner@postgresql.org Mon Jun 16 02:28:40 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 7097530ED6B for ; Mon, 16 Jun 2003 05:28:39 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 37083-10 for ; Mon, 16 Jun 2003 02:28:29 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id BA91330EBE9 for ; Mon, 16 Jun 2003 02:28:28 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5G5SRU6026715; Mon, 16 Jun 2003 01:28:27 -0400 (EDT) To: jim@nasby.net Cc: pgsql-performance@postgresql.org Subject: Re: left join performance problem In-reply-to: <20030616001028.Q66185@flake.decibel.org> References: <3EE74C2D.88390062@t1.unisoftbg.com> <26068.1055386671@sss.pgh.pa.us> <3EE8061B.1FAED8AD@t1.unisoftbg.com> <20030616001028.Q66185@flake.decibel.org> Comments: In-reply-to "Jim C. Nasby" message dated "Mon, 16 Jun 2003 00:10:28 -0500" Date: Mon, 16 Jun 2003 01:28:26 -0400 Message-ID: <26714.1055741306@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/75 X-Sequence-Number: 2159 "Jim C. Nasby" writes: > Any chance of getting a TODO added that would provide the option of > having the optimizer pick join order when you're using the ANSI join > syntax? No ... because it's already DONE. regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jun 16 02:31:36 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id EA2E130EBE9 for ; Mon, 16 Jun 2003 05:31:30 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 52647-02 for ; Mon, 16 Jun 2003 02:31:18 -0300 (ADT) Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) by svr1.postgresql.org (Postfix) with SMTP id E992C30E8CA for ; Mon, 16 Jun 2003 02:31:17 -0300 (ADT) Received: (qmail 8288 invoked by uid 1001); 16 Jun 2003 05:31:18 -0000 Date: Mon, 16 Jun 2003 00:31:18 -0500 From: "Jim C. Nasby" To: pgsql-performance@postgresql.org Subject: Partial index where clause not filtering through Message-ID: <20030616003118.S66185@flake.decibel.org> Reply-To: jim@nasby.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i X-Operating-System: FreeBSD 4.8-RELEASE i386 X-Distributed: Join the Effort! http://www.distributed.net X-Archive-Number: 200306/76 X-Sequence-Number: 2160 I have the following index: street_range__street_locality_high_low_v btree (street_name_id, locality_id, addr_high_v, addr_low_v) WHERE (addr_high_v IS NOT NULL) The query has a where clause like this: FROM street_range s, input i WHERE 1=1 AND i.address_v IS NOT NULL AND s.locality_id = i.locality_id AND s.street_name_id = i.street_name_id AND s.addr_low_v <= i.address_v AND s.addr_high_v >= i.address_v As-is, it won't use the index. i.address_v IS NOT NULL AND s.addr_high_v >= i.address_v should mandate that s.addr_high_v must be not-null, if I'm remembering how nulls work correctly. (Actually, having any kind of comparison on s.addr_high_v should mandate NOT NULL since NULL != NULL, right?) Therefore the optimizer should be able to deduce that it can use the index. Adding AND s.addr_high_v IS NOT NULL to the where clause makes everything work fine, so there is a work-around. Just seems like a minor item to add to the TODO. -- Jim C. Nasby (aka Decibel!) jim@nasby.net Member: Triangle Fraternity, Sports Car Club of America Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?" From pgsql-performance-owner@postgresql.org Mon Jun 16 02:36:40 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id A818630ED7F for ; Mon, 16 Jun 2003 05:36:39 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 42621-07 for ; Mon, 16 Jun 2003 02:36:29 -0300 (ADT) Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) by svr1.postgresql.org (Postfix) with SMTP id BE63D30ECAD for ; Mon, 16 Jun 2003 02:36:28 -0300 (ADT) Received: (qmail 8382 invoked by uid 1001); 16 Jun 2003 05:36:29 -0000 Date: Mon, 16 Jun 2003 00:36:29 -0500 From: "Jim C. Nasby" To: pgsql-performance@postgresql.org Subject: Re: left join performance problem Message-ID: <20030616003629.T66185@flake.decibel.org> Reply-To: jim@nasby.net References: <3EE74C2D.88390062@t1.unisoftbg.com> <26068.1055386671@sss.pgh.pa.us> <3EE8061B.1FAED8AD@t1.unisoftbg.com> <20030616001028.Q66185@flake.decibel.org> <26714.1055741306@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <26714.1055741306@sss.pgh.pa.us>; from tgl@sss.pgh.pa.us on Mon, Jun 16, 2003 at 01:28:26AM -0400 X-Operating-System: FreeBSD 4.8-RELEASE i386 X-Distributed: Join the Effort! http://www.distributed.net X-Archive-Number: 200306/77 X-Sequence-Number: 2161 On Mon, Jun 16, 2003 at 01:28:26AM -0400, Tom Lane wrote: > "Jim C. Nasby" writes: > > Any chance of getting a TODO added that would provide the option of > > having the optimizer pick join order when you're using the ANSI join > > syntax? > > No ... because it's already DONE. DOH, I forgot about the subselect trick. Nevermind. *wipes egg off face* -- Jim C. Nasby (aka Decibel!) jim@nasby.net Member: Triangle Fraternity, Sports Car Club of America Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?" From pgsql-performance-owner@postgresql.org Mon Jun 16 02:43:49 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 3B8DA30EC11 for ; Mon, 16 Jun 2003 05:43:47 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 52188-04 for ; Mon, 16 Jun 2003 02:43:36 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 7247430E8CA for ; Mon, 16 Jun 2003 02:43:36 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5G5hYU6026794; Mon, 16 Jun 2003 01:43:34 -0400 (EDT) To: jim@nasby.net Cc: pgsql-performance@postgresql.org Subject: Re: Partial index where clause not filtering through In-reply-to: <20030616003118.S66185@flake.decibel.org> References: <20030616003118.S66185@flake.decibel.org> Comments: In-reply-to "Jim C. Nasby" message dated "Mon, 16 Jun 2003 00:31:18 -0500" Date: Mon, 16 Jun 2003 01:43:34 -0400 Message-ID: <26793.1055742214@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/78 X-Sequence-Number: 2162 "Jim C. Nasby" writes: > As-is, it won't use the index. i.address_v IS NOT NULL AND s.addr_high_v > >= i.address_v should mandate that s.addr_high_v must be not-null, Actually, if the >= operator is strict then it implies both NOT NULL conditions. But I am not excited about putting some kind of theorem prover into the partial-index logic. That is a recipe for chewing up huge numbers of cycles trying (and, likely, failing) to prove that a partial index is safe to use with the current query. Inference rules that are limited to strict operators and NOT NULL clauses wouldn't cost as much as a general theorem prover, but they'd not find useful improvements as often, either. So the question is still whether the game is worth the candle. How often do you think this would win, and is that worth the planner cycles expended on every query to find out if it wins? regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jun 16 03:16:55 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id C185630DB8F for ; Mon, 16 Jun 2003 06:16:53 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 53269-09 for ; Mon, 16 Jun 2003 03:16:43 -0300 (ADT) Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id B649730DBE2 for ; Mon, 16 Jun 2003 03:16:41 -0300 (ADT) Received: (from root@localhost) by www.pspl.co.in (8.11.6/8.11.6) id h5G6GeQ23513 for ; Mon, 16 Jun 2003 11:46:40 +0530 Received: from daithan (daithan.intranet.pspl.co.in [192.168.7.161]) by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h5G6Ge923508 for ; Mon, 16 Jun 2003 11:46:40 +0530 From: "Shridhar Daithankar" To: pgsql-performance@postgresql.org Date: Mon, 16 Jun 2003 11:45:52 +0530 MIME-Version: 1.0 Subject: Re: any way to use indexscan to get last X values Reply-To: shridhar_daithankar@persistent.co.in Message-ID: <3EEDADF0.29611.3901BC1@localhost> In-reply-to: <5.2.1.1.0.20030616002729.01bba2e0@127.0.0.1> References: <23329.1055695990@sss.pgh.pa.us> X-mailer: Pegasus Mail for Windows (v4.02) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Archive-Number: 200306/79 X-Sequence-Number: 2163 On 16 Jun 2003 at 0:37, Tomaz Borstnar wrote: > > krtjavendan34=> EXPLAIN ANALYZE SELECT thread, modifystamp, count(id) AS > tcount,abstime(modifystamp) AS latest, max(id) as maxid FROM tjavendan > WHERE approved='Y' GROUP BY modifystamp, thread ORDER BY modifystamp desc, > thread desc limit 40; > QUERY > PLAN > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ > Limit (cost=0.00..97.13 rows=40 width=12) (actual time=1.07..48.71 > rows=40 loops=1) > -> Aggregate (cost=0.00..20947.38 rows=8626 width=12) (actual > time=1.05..48.23 rows=41 loops=1) > -> Group (cost=0.00..20516.06 rows=86265 width=12) (actual > time=0.35..42.25 rows=843 loops=1) > -> Index Scan Backward using tjavendan_modstamp_thrd on > tjavendan (cost=0.00..20084.73 rows=86265 width=12) (actual > time=0.34..31.29 rows=844 loops=1) > Filter: (approved = 'Y'::bpchar) > Total runtime: 50.20 msec > (6 rows) > > Used to be between 5800 and 6741 msec before this patch! Good that the patch works for you. But as I see there is an improvement in plan. Not nitpicking but what does actual performance difference between system before patch and after patch? Bye Shridhar -- QOTD: "In the shopping mall of the mind, he's in the toy department." From pgsql-performance-owner@postgresql.org Mon Jun 16 03:25:18 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 8FDD930EBDC for ; Mon, 16 Jun 2003 06:25:17 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 58267-08 for ; Mon, 16 Jun 2003 03:25:07 -0300 (ADT) Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) by svr1.postgresql.org (Postfix) with SMTP id 7595C30DBAD for ; Mon, 16 Jun 2003 03:25:01 -0300 (ADT) Received: (qmail 9891 invoked by uid 1001); 16 Jun 2003 06:24:56 -0000 Date: Mon, 16 Jun 2003 01:24:56 -0500 From: "Jim C. Nasby" To: pgsql-performance@postgresql.org Subject: Re: Partial index where clause not filtering through Message-ID: <20030616012456.U66185@flake.decibel.org> Reply-To: jim@nasby.net References: <20030616003118.S66185@flake.decibel.org> <26793.1055742214@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <26793.1055742214@sss.pgh.pa.us>; from tgl@sss.pgh.pa.us on Mon, Jun 16, 2003 at 01:43:34AM -0400 X-Operating-System: FreeBSD 4.8-RELEASE i386 X-Distributed: Join the Effort! http://www.distributed.net X-Archive-Number: 200306/80 X-Sequence-Number: 2164 On Mon, Jun 16, 2003 at 01:43:34AM -0400, Tom Lane wrote: > "Jim C. Nasby" writes: > > As-is, it won't use the index. i.address_v IS NOT NULL AND s.addr_high_v > > >= i.address_v should mandate that s.addr_high_v must be not-null, > > Actually, if the >= operator is strict then it implies both NOT NULL > conditions. But I am not excited about putting some kind of theorem > prover into the partial-index logic. That is a recipe for chewing up > huge numbers of cycles trying (and, likely, failing) to prove that > a partial index is safe to use with the current query. > > Inference rules that are limited to strict operators and NOT NULL > clauses wouldn't cost as much as a general theorem prover, but they'd > not find useful improvements as often, either. So the question is > still whether the game is worth the candle. How often do you think > this would win, and is that worth the planner cycles expended on every > query to find out if it wins? Well, it would only need to make the checks if the table had partial indexes. Even then, it probably makes sense to only do the check if other query planning steps decide it would be useful to use the partial index. So that means that for a lot of general use cases, performance won't be impacted. When you get to the cases that would be impacted, the planner should probably look for key clauses first; so if you were worried about planning time, you would put an explicit clause in the query (I'm in the habit of doing this for joins when joining three tables on the same key... FROM a, b, c WHERE a.f1=b.f1 and b.f1=c.f1 and a.f1=c.f1. I would hope the planner would figure out that a.f1 must = c.f1, but some don't). In many cases, planning time isn't a big deal; either the query is run often enough that it should stay in the plan cache (pgsql does cache plans, right?), or it's run infrequently enough that it's not a big deal. Of course, this might extend well beyond just partial indexes, as my a, b, c example shows. -- Jim C. Nasby (aka Decibel!) jim@nasby.net Member: Triangle Fraternity, Sports Car Club of America Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?" From pgsql-performance-owner@postgresql.org Mon Jun 16 03:40:57 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 9421B30DBDD for ; Mon, 16 Jun 2003 06:40:55 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 65502-01 for ; Mon, 16 Jun 2003 03:40:44 -0300 (ADT) Received: from nitrogen.id.pl (smtp.id.pl [193.178.214.4]) by svr1.postgresql.org (Postfix) with SMTP id 6A72630DBD7 for ; Mon, 16 Jun 2003 03:40:43 -0300 (ADT) Received: (qmail 25548 invoked by uid 0); 16 Jun 2003 06:38:51 -0000 Received: from siaco.id.pl (213.25.114.8) by smtp.id.pl with SMTP; 16 Jun 2003 06:38:51 -0000 Received: (qmail 31868 invoked by uid 1000); 16 Jun 2003 06:38:50 -0000 Date: Mon, 16 Jun 2003 08:38:50 +0200 From: siaco@allegro.pl To: pgsql-performance@postgresql.org Subject: Re: 7.3 vs 7.2 - different query plan, bad performance Message-ID: <20030616063850.GA31813@siaco.id.pl> References: <20030613184506.GE21614@siaco.id.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline In-Reply-To: X-My-GPG-Key: echo | mail -s "send key pub" ryszard@lach.name User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/81 X-Sequence-Number: 2165 On Sun, Jun 15, 2003 at 09:48:08PM +0200, Manfred Koizar wrote: > On Fri, 13 Jun 2003 20:45:06 +0200, Ryszard Lach > wrote: > >I have a problem with performance after upgrading from 7.2 to 7.3. > > Try > VACUUM ANALYSE; > > and then re-run your query. If it is still slow, post the new EXPLAIN > ANALYSE output here. > Hm. I've tried it too. I don't see a big difference: siaco=# explain analyze select count(*) from v_c; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=210.83..210.83 rows=1 width=8) (actual time=5418.09..5418.09 rows=1 loops=1) -> Subquery Scan v_c (cost=28.40..197.63 rows=5281 width=8) (actual time=4.59..5414.13 rows=5281 loops=1) -> Hash Join (cost=28.40..197.63 rows=5281 width=8) (actual time=4.58..5407.73 rows=5281 loops=1) Hash Cond: ("outer".id = "inner".id) -> Seq Scan on b t1 (cost=0.00..76.81 rows=5281 width=4) (actual time=0.01..9.68 rows=5281 loops=1) -> Hash (cost=24.32..24.32 rows=1632 width=4) (actual time=3.29..3.29 rows=0 loops=1) -> Seq Scan on a t2 (cost=0.00..24.32 rows=1632 width=4) (actual time=0.01..1.88 rows=1632 loops=1) SubPlan -> Aggregate (cost=28.41..28.41 rows=1 width=0) (actual time=1.02..1.02 rows=1 loops=5281) -> Seq Scan on a t3 (cost=0.00..28.40 rows=3 width=0) (actual time=0.76..1.01 rows=1 loops=5281) Filter: (parent_id = $0) Total runtime: 5433.65 msec -- "First they ignore you. Then they laugh at you. Then they fight you. Then you win." - Mohandas Gandhi. From pgsql-performance-owner@postgresql.org Mon Jun 16 04:09:25 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id E0AA930DBAD for ; Mon, 16 Jun 2003 07:09:20 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 63291-03 for ; Mon, 16 Jun 2003 04:09:10 -0300 (ADT) Received: from game.over.net (unknown [193.189.169.9]) by svr1.postgresql.org (Postfix) with ESMTP id B021830D16A for ; Mon, 16 Jun 2003 04:09:09 -0300 (ADT) Received: from localhost.over.net ([127.0.0.1]:4612 "EHLO zvezek.over.net") by mail.over.net with ESMTP id ; Mon, 16 Jun 2003 09:09:08 +0200 Message-Id: <5.2.1.1.0.20030616090124.02a85678@127.0.0.1> X-Sender: tmail@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Mon, 16 Jun 2003 09:08:49 +0200 To: pgsql-performance@postgresql.org From: Tomaz Borstnar Subject: Re: any way to use indexscan to get last X values In-Reply-To: <3EEDADF0.29611.3901BC1@localhost> References: <5.2.1.1.0.20030616002729.01bba2e0@127.0.0.1> <23329.1055695990@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200306/82 X-Sequence-Number: 2166 At 08:15 16.6.2003, Shridhar Daithankar wrote: > > Total runtime: 50.20 msec > > Used to be between 5800 and 6741 msec before this patch! > >Good that the patch works for you. But as I see there is an improvement in >plan. Not nitpicking but what does actual performance difference between >system >before patch and after patch? A lot since this is query to get list of last active threads sorted by last modified date. With times less than 300ms you mostly do not notice slower query as there could be other factors to affect the speed like network delays and such. But people on fast links will notice that it takes a bit long to display list of threads - especially when the system is using PHP accelerator and compression. So this really means major increase of performance for real situation - forum with over 85 000 messages where you get rid of full scan and 2 full sorts to display list of msgs which happens a lot. You can always use some query/page caching things, but then people start to post duplicates, because they think the message did not make it into the database. Tomaz From pgsql-performance-owner@postgresql.org Mon Jun 16 04:23:04 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 4961430ED64 for ; Mon, 16 Jun 2003 07:23:02 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 59361-07 for ; Mon, 16 Jun 2003 04:22:51 -0300 (ADT) Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id 21D9530EC62 for ; Mon, 16 Jun 2003 04:22:50 -0300 (ADT) Received: (from root@localhost) by www.pspl.co.in (8.11.6/8.11.6) id h5G7MnU02144 for ; Mon, 16 Jun 2003 12:52:49 +0530 Received: from daithan (daithan.intranet.pspl.co.in [192.168.7.161]) by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h5G7Mm902139 for ; Mon, 16 Jun 2003 12:52:49 +0530 From: "Shridhar Daithankar" To: pgsql-performance@postgresql.org Date: Mon, 16 Jun 2003 12:52:00 +0530 MIME-Version: 1.0 Subject: Re: any way to use indexscan to get last X values Reply-To: shridhar_daithankar@persistent.co.in Message-ID: <3EEDBD70.15023.3CCA80F@localhost> In-reply-to: <5.2.1.1.0.20030616090124.02a85678@127.0.0.1> References: <3EEDADF0.29611.3901BC1@localhost> X-mailer: Pegasus Mail for Windows (v4.02) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Archive-Number: 200306/83 X-Sequence-Number: 2167 On 16 Jun 2003 at 9:08, Tomaz Borstnar wrote: > So this really means major increase of performance for real situation - > forum with over 85 000 messages where you get rid of full scan and 2 full > sorts to display list of msgs which happens a lot. You can always use some > query/page caching things, but then people start to post duplicates, > because they think the message did not make it into the database. OTOH, I was thinking of your original problem. If you could have two identical tables, one to store incoming posts and other to store approved posts, that should be lot more simpler. Of course you need to vacuum much more if you are deleting from in queue but the kind of database you are handling, me need not tell you about vacuum.. Just a though.. Bye Shridhar -- Drew's Law of Highway Biology: The first bug to hit a clean windshield lands directly in front of your eyes. From pgsql-performance-owner@postgresql.org Mon Jun 16 05:05:11 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 9199B30EDB7 for ; Mon, 16 Jun 2003 08:04:34 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 61767-06 for ; Mon, 16 Jun 2003 05:04:24 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 9D86930EDBC for ; Mon, 16 Jun 2003 05:04:23 -0300 (ADT) Received: (qmail 25971 invoked by uid 500); 16 Jun 2003 08:07:18 -0000 Date: Mon, 16 Jun 2003 03:07:18 -0500 From: Bruno Wolff III To: "Jim C. Nasby" Cc: pgsql-performance@postgresql.org Subject: Re: left join performance problem Message-ID: <20030616080718.GB25847@wolff.to> Mail-Followup-To: "Jim C. Nasby" , pgsql-performance@postgresql.org References: <3EE74C2D.88390062@t1.unisoftbg.com> <26068.1055386671@sss.pgh.pa.us> <3EE8061B.1FAED8AD@t1.unisoftbg.com> <20030616001028.Q66185@flake.decibel.org> <26714.1055741306@sss.pgh.pa.us> <20030616003629.T66185@flake.decibel.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030616003629.T66185@flake.decibel.org> User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/84 X-Sequence-Number: 2168 On Mon, Jun 16, 2003 at 00:36:29 -0500, "Jim C. Nasby" wrote: > On Mon, Jun 16, 2003 at 01:28:26AM -0400, Tom Lane wrote: > > "Jim C. Nasby" writes: > > > Any chance of getting a TODO added that would provide the option of > > > having the optimizer pick join order when you're using the ANSI join > > > syntax? > > > > No ... because it's already DONE. > > DOH, I forgot about the subselect trick. Nevermind. In 7.4 there is a GUC setting to control this. I believe the default is to not constrain the join order any more than is necessary to preserve semantics. From pgsql-performance-owner@postgresql.org Mon Jun 16 17:34:18 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1812630E35D for ; Mon, 16 Jun 2003 20:34:18 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 21166-09 for ; Mon, 16 Jun 2003 17:34:07 -0300 (ADT) Received: from smaug.securitymatrix.com (unknown [64.25.5.177]) by svr1.postgresql.org (Postfix) with ESMTP id 2616830EEFF for ; Mon, 16 Jun 2003 17:33:58 -0300 (ADT) Received: from kaos.securitymatrix.com ([172.16.0.101]) by smaug.securitymatrix.com (8.11.6/8.11.6) with ESMTP id h5GKXLV21252 for ; Mon, 16 Jun 2003 16:33:21 -0400 Subject: Postgres Connections Requiring Large Amounts of Memory From: Dawn Hollingsworth To: pgsql-performance@postgresql.org Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 16 Jun 2003 08:32:17 +0000 Message-Id: <1055752337.2182.49.camel@kaos> Mime-Version: 1.0 X-Archive-Number: 200306/98 X-Sequence-Number: 2182 PostgreSQL Version: 7.2.3 OS : Red Hat 7.3 with Kernel 2.4.18-5 and SGI_XFS I currently have two processes which create several persistent connections to the database. One process primarily does inserts and the other primarily does selects. Both processes run 24/7. My problem is that the memory used by the connections appears to grow over time, especially when the amount of data entering the system is increased. The connections sometimes take up wards of 450 MB of memory causing other applications on the system to swap. Is there anyway to limit the amount of memory used by a given connection or is there something I may be doing that is requiring the connection to need more memory? -Dawn From pgsql-performance-owner@postgresql.org Mon Jun 16 17:59:29 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 0DBA530ED11 for ; Mon, 16 Jun 2003 20:59:29 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 07316-10 for ; Mon, 16 Jun 2003 17:59:18 -0300 (ADT) Received: from smaug.securitymatrix.com (unknown [64.25.5.177]) by svr1.postgresql.org (Postfix) with ESMTP id 30C1A30EF1B for ; Mon, 16 Jun 2003 17:59:18 -0300 (ADT) Received: from kaos.securitymatrix.com ([172.16.0.101]) by smaug.securitymatrix.com (8.11.6/8.11.6) with ESMTP id h5GKwdV21285; Mon, 16 Jun 2003 16:58:40 -0400 Subject: Re: Postgres Connections Requiring Large Amounts of Memory From: Dawn Hollingsworth To: Tom Lane Cc: pgsql-performance@postgresql.org In-Reply-To: <6634.1055796302@sss.pgh.pa.us> References: <1055752337.2182.49.camel@kaos> <6634.1055796302@sss.pgh.pa.us> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 16 Jun 2003 08:57:35 +0000 Message-Id: <1055753856.5467.57.camel@kaos> Mime-Version: 1.0 X-Archive-Number: 200306/100 X-Sequence-Number: 2184 We have just recently hired a database consultant familiar with Postgres and just on his cursory glance we are not doing anything really crazy. There are two things which might be considered off the beaten path though: 1. We have tables that have over 500 columns which we continually insert into and select from. 2. Our stored procedures take more than 16 parameters so in the file config.h the value INDEX_MAX_KEYS was increased to 100. -Dawn On Mon, 2003-06-16 at 20:45, Tom Lane wrote: > Dawn Hollingsworth writes: > > PostgreSQL Version: 7.2.3 > > > My problem is that the memory used by the connections appears to grow > > over time, especially when the amount of data entering the system is > > increased. > > We have fixed memory-leak problems in the past, and I wouldn't be > surprised if some remain, but you'll have to give a lot more detail > about what you're doing if you want help. A leak that persists across > transaction boundaries is fairly surprising --- I think I can safely > say that there are none in the normal code paths. I'm guessing you must > be using some off-the-beaten-path feature. > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 7: don't forget to increase your free space map settings From pgsql-performance-owner@postgresql.org Mon Jun 16 07:31:53 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id D198930EE13 for ; Mon, 16 Jun 2003 10:31:51 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 94480-06 for ; Mon, 16 Jun 2003 07:31:41 -0300 (ADT) Received: from email03.aon.at (WARSL402PIP6.highway.telekom.at [195.3.96.93]) by svr1.postgresql.org (Postfix) with SMTP id CA98D30EE07 for ; Mon, 16 Jun 2003 07:31:40 -0300 (ADT) Received: (qmail 338052 invoked from network); 16 Jun 2003 10:31:39 -0000 Received: from m149p004.dipool.highway.telekom.at (HELO cantor) ([62.46.8.132]) (envelope-sender ) by qmail3rs.highway.telekom.at (qmail-ldap-1.03) with SMTP for ; 16 Jun 2003 10:31:39 -0000 From: Manfred Koizar To: siaco@allegro.pl Cc: pgsql-performance@postgresql.org Subject: Re: 7.3 vs 7.2 - different query plan, bad performance Date: Mon, 16 Jun 2003 12:31:08 +0200 Message-ID: <373rev0fotgpq2osvlldf41b8flambulk9@4ax.com> References: <20030613184506.GE21614@siaco.id.pl> <20030616063850.GA31813@siaco.id.pl> In-Reply-To: <20030616063850.GA31813@siaco.id.pl> X-Mailer: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/85 X-Sequence-Number: 2169 On Mon, 16 Jun 2003 08:38:50 +0200, siaco@allegro.pl wrote: >[After VACUUM ANALYSE ...] I don't see a big difference: > >siaco=# explain analyze select count(*) from v_c; > QUERY PLAN >--------------------------------------------------------------------------------------------------------------------------- > Aggregate (cost=210.83..210.83 rows=1 width=8) (actual time=5418.09..5418.09 rows=1 loops=1) > -> Subquery Scan v_c (cost=28.40..197.63 rows=5281 width=8) (actual time=4.59..5414.13 rows=5281 loops=1) > -> Hash Join (cost=28.40..197.63 rows=5281 width=8) (actual time=4.58..5407.73 rows=5281 loops=1) > Hash Cond: ("outer".id = "inner".id) > -> Seq Scan on b t1 (cost=0.00..76.81 rows=5281 width=4) (actual time=0.01..9.68 rows=5281 loops=1) > -> Hash (cost=24.32..24.32 rows=1632 width=4) (actual time=3.29..3.29 rows=0 loops=1) > -> Seq Scan on a t2 (cost=0.00..24.32 rows=1632 width=4) (actual time=0.01..1.88 rows=1632 loops=1) > SubPlan > -> Aggregate (cost=28.41..28.41 rows=1 width=0) (actual time=1.02..1.02 rows=1 loops=5281) > -> Seq Scan on a t3 (cost=0.00..28.40 rows=3 width=0) (actual time=0.76..1.01 rows=1 loops=5281) > Filter: (parent_id = $0) > Total runtime: 5433.65 msec Ok, now we have something to work on. .) I guess you are not really interested in SELECT count(*) FROM v_c; If you were, you would simply SELECT count(*) from b; Try EXPLAIN ANALYSE SELECT * FROM v_c; and you will see that 7.2 produces a plan that is almost equal to that produced by 7.3. .) Without any index a seq scan is the best you can get. A scan of a takes only 1 ms, but doing it 5000 times gives 5 seconds. Try CREATE INDEX a_parent ON a(parent_id); .) Wouldn't CREATE VIEW v_c AS SELECT t1.id, count(t3.id) AS children_count FROM (b t1 LEFT JOIN a t2 ON (t1.id = t2.id)) LEFT JOIN a t3 ON (t3.parent_id = t2.id) GROUP BY t1.id; give the same results as your view definition with the subselect? And under some assumptions about your data even CREATE VIEW v_c AS SELECT b.id, count(a.id) AS children_count FROM b LEFT JOIN a ON (a.parent_id = b.id) GROUP BY b.id; might work. But I think I don't understand your requirements. Why are you not interested in the children_count for an id that doesn't have a parent itself? .) To answer your original question: The difference seems to be that 7.2 does not evaluate the subselect in the SELECT list, when you are only asking for count(*). Servus Manfred From pgsql-performance-owner@postgresql.org Mon Jun 16 08:42:06 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id CCAA330D6D9 for ; Mon, 16 Jun 2003 11:41:59 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 06700-07 for ; Mon, 16 Jun 2003 08:41:49 -0300 (ADT) Received: from nitrogen.id.pl (smtp.id.pl [193.178.214.4]) by svr1.postgresql.org (Postfix) with SMTP id 46B6730EE7F for ; Mon, 16 Jun 2003 08:41:48 -0300 (ADT) Received: (qmail 23865 invoked by uid 0); 16 Jun 2003 11:41:47 -0000 Received: from siaco.id.pl (213.25.114.8) by smtp.id.pl with SMTP; 16 Jun 2003 11:41:47 -0000 Received: (qmail 28110 invoked by uid 1000); 16 Jun 2003 11:41:47 -0000 Date: Mon, 16 Jun 2003 13:41:47 +0200 From: Ryszard Lach To: pgsql-performance@postgresql.org Subject: Re: 7.3 vs 7.2 - different query plan, bad performance Message-ID: <20030616114147.GJ1734@siaco.id.pl> Reply-To: Ryszard Lach References: <20030613184506.GE21614@siaco.id.pl> <20030616063850.GA31813@siaco.id.pl> <373rev0fotgpq2osvlldf41b8flambulk9@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline In-Reply-To: <373rev0fotgpq2osvlldf41b8flambulk9@4ax.com> X-My-GPG-Key: echo | mail -s "send key pub" siaco@allegro.pl> User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/86 X-Sequence-Number: 2170 On Mon, Jun 16, 2003 at 12:31:08PM +0200, Manfred Koizar wrote: > > Ok, now we have something to work on. > > .) I guess you are not really interested in > > SELECT count(*) FROM v_c; > > If you were, you would simply > > SELECT count(*) from b; > That's right. > Try > > EXPLAIN ANALYSE SELECT * FROM v_c; > > and you will see that 7.2 produces a plan that is almost equal to that > produced by 7.3. That is not. I'm, pasting query plan from 7.2 once again (after vacuum analyze): siaco=# explain analyze select count(*) from v_c; NOTICE: QUERY PLAN: Aggregate (cost=213.83..213.83 rows=1 width=8) (actual time=90.43..90.43 rows=1 loops=1) -> Hash Join (cost=29.40..200.63 rows=5281 width=8) (actual time=11.14..78.48 rows=5281 loops=1) -> Seq Scan on b t1 (cost=0.00..78.81 rows=5281 width=4) (actual time=0.01..26.40 rows=5281 loops=1) -> Hash (cost=25.32..25.32 rows=1632 width=4) (actual time=10.99..10.99 rows=0 loops=1) -> Seq Scan on a t2 (cost=0.00..25.32 rows=1632 width=4) (actual time=0.02..6.30 rows=1632 loops=1) Total runtime: 90.74 msec EXPLAIN > might work. But I think I don't understand your requirements. Why > are you not interested in the children_count for an id that doesn't > have a parent itself? The point is, that my tables (and queries) are a 'little' bit more complicated and I wanted to give as simple example as I could. I think that problem is that subselects are _much_slower_ executed in 7.3 than in 7.2, just as someone already wrote here. > .) To answer your original question: The difference seems to be that > 7.2 does not evaluate the subselect in the SELECT list, when you are > only asking for count(*). That looks reasonably. Thanks for all your help, Richard. -- "First they ignore you. Then they laugh at you. Then they fight you. Then you win." - Mohandas Gandhi. From pgsql-performance-owner@postgresql.org Mon Jun 16 10:25:33 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 610F130EEAE for ; Mon, 16 Jun 2003 13:25:33 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 28322-03 for ; Mon, 16 Jun 2003 10:25:23 -0300 (ADT) Received: from email05.aon.at (WARSL402PIP4.highway.telekom.at [195.3.96.79]) by svr1.postgresql.org (Postfix) with SMTP id 7827730EE92 for ; Mon, 16 Jun 2003 10:25:22 -0300 (ADT) Received: (qmail 426858 invoked from network); 16 Jun 2003 13:25:21 -0000 Received: from m149p004.dipool.highway.telekom.at (HELO cantor) ([62.46.8.132]) (envelope-sender ) by qmail5rs.highway.telekom.at (qmail-ldap-1.03) with SMTP for ; 16 Jun 2003 13:25:21 -0000 From: Manfred Koizar To: Ryszard Lach Cc: pgsql-performance@postgresql.org Subject: Re: 7.3 vs 7.2 - different query plan, bad performance Date: Mon, 16 Jun 2003 15:24:52 +0200 Message-ID: References: <20030613184506.GE21614@siaco.id.pl> <20030616063850.GA31813@siaco.id.pl> <373rev0fotgpq2osvlldf41b8flambulk9@4ax.com> <20030616114147.GJ1734@siaco.id.pl> In-Reply-To: <20030616114147.GJ1734@siaco.id.pl> X-Mailer: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/87 X-Sequence-Number: 2171 On Mon, 16 Jun 2003 13:41:47 +0200, Ryszard Lach wrote: >On Mon, Jun 16, 2003 at 12:31:08PM +0200, Manfred Koizar wrote: >> EXPLAIN ANALYSE SELECT * FROM v_c; >siaco=# explain analyze select count(*) from v_c; ^^^^^^ ^ See the difference? I bet if you EXPLAIN ANALYSE SELECT * FROM v_c; you get a much longer runtime. BTW, did the index on a.parent_id help? In my test it improved runtime from 59449.71 msec to 1203.26 msec (SELECT * with Postgres 7.2). Servus Manfred From pgsql-performance-owner@postgresql.org Mon Jun 16 10:26:31 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id A1C1130EE02 for ; Mon, 16 Jun 2003 13:26:30 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 27949-03 for ; Mon, 16 Jun 2003 10:26:20 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 7BA9B30EE9F for ; Mon, 16 Jun 2003 10:26:19 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5GDQDU6002364; Mon, 16 Jun 2003 09:26:13 -0400 (EDT) To: jim@nasby.net Cc: pgsql-performance@postgresql.org Subject: Re: left join performance problem In-reply-to: <20030616003629.T66185@flake.decibel.org> References: <3EE74C2D.88390062@t1.unisoftbg.com> <26068.1055386671@sss.pgh.pa.us> <3EE8061B.1FAED8AD@t1.unisoftbg.com> <20030616001028.Q66185@flake.decibel.org> <26714.1055741306@sss.pgh.pa.us> <20030616003629.T66185@flake.decibel.org> Comments: In-reply-to "Jim C. Nasby" message dated "Mon, 16 Jun 2003 00:36:29 -0500" Date: Mon, 16 Jun 2003 09:26:13 -0400 Message-ID: <2363.1055769973@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/88 X-Sequence-Number: 2172 "Jim C. Nasby" writes: > On Mon, Jun 16, 2003 at 01:28:26AM -0400, Tom Lane wrote: >> "Jim C. Nasby" writes: > Any chance of getting a TODO added that would provide the option of > having the optimizer pick join order when you're using the ANSI join > syntax? >> >> No ... because it's already DONE. > DOH, I forgot about the subselect trick. Nevermind. No, I wasn't talking about that. See http://developer.postgresql.org/docs/postgres/explicit-joins.html for the way it works in CVS tip. regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jun 16 10:55:43 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id E3E4730EECD for ; Mon, 16 Jun 2003 13:55:38 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 31182-05 for ; Mon, 16 Jun 2003 10:55:28 -0300 (ADT) Received: from nitrogen.id.pl (smtp.id.pl [193.178.214.4]) by svr1.postgresql.org (Postfix) with SMTP id D3D0E30EEC0 for ; Mon, 16 Jun 2003 10:55:21 -0300 (ADT) Received: (qmail 17521 invoked by uid 0); 16 Jun 2003 13:55:21 -0000 Received: from siaco.id.pl (213.25.114.8) by smtp.id.pl with SMTP; 16 Jun 2003 13:55:21 -0000 Received: (qmail 2529 invoked by uid 1000); 16 Jun 2003 13:55:21 -0000 Date: Mon, 16 Jun 2003 15:55:21 +0200 From: Ryszard Lach To: pgsql-performance@postgresql.org Subject: Re: 7.3 vs 7.2 - different query plan, bad performance Message-ID: <20030616135521.GO1734@siaco.id.pl> Reply-To: Ryszard Lach References: <20030613184506.GE21614@siaco.id.pl> <20030616063850.GA31813@siaco.id.pl> <373rev0fotgpq2osvlldf41b8flambulk9@4ax.com> <20030616114147.GJ1734@siaco.id.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline In-Reply-To: X-My-GPG-Key: echo | mail -s "send key pub" siaco@allegro.pl> User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/89 X-Sequence-Number: 2173 On Mon, Jun 16, 2003 at 03:24:52PM +0200, Manfred Koizar wrote: > On Mon, 16 Jun 2003 13:41:47 +0200, Ryszard Lach > wrote: > >On Mon, Jun 16, 2003 at 12:31:08PM +0200, Manfred Koizar wrote: > >> EXPLAIN ANALYSE SELECT * FROM v_c; > > >siaco=# explain analyze select count(*) from v_c; > ^^^^^^ ^ > See the difference? I bet if you > EXPLAIN ANALYSE SELECT * FROM v_c; > you get a much longer runtime. Yes, indeed. > BTW, did the index on a.parent_id help? In my test it improved > runtime from 59449.71 msec to 1203.26 msec (SELECT * with Postgres > 7.2). Oh yeah... Thanks a lot once more. Richard. -- "First they ignore you. Then they laugh at you. Then they fight you. Then you win." - Mohandas Gandhi. From pgsql-performance-owner@postgresql.org Mon Jun 16 11:11:12 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id BAD1F30ED11 for ; Mon, 16 Jun 2003 14:11:11 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 31863-05 for ; Mon, 16 Jun 2003 11:11:01 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 0D27F30EE92 for ; Mon, 16 Jun 2003 11:11:01 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5GEB0U6002620; Mon, 16 Jun 2003 10:11:00 -0400 (EDT) To: jim@nasby.net Cc: pgsql-performance@postgresql.org Subject: Re: Partial index where clause not filtering through In-reply-to: <20030616012456.U66185@flake.decibel.org> References: <20030616003118.S66185@flake.decibel.org> <26793.1055742214@sss.pgh.pa.us> <20030616012456.U66185@flake.decibel.org> Comments: In-reply-to "Jim C. Nasby" message dated "Mon, 16 Jun 2003 01:24:56 -0500" Date: Mon, 16 Jun 2003 10:11:00 -0400 Message-ID: <2619.1055772660@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/90 X-Sequence-Number: 2174 "Jim C. Nasby" writes: > Well, it would only need to make the checks if the table had partial > indexes. Even then, it probably makes sense to only do the check if > other query planning steps decide it would be useful to use the partial > index. You have that backwards. Planning is bottom-up, so we have to determine the relevant indexes *first*. Accordingly, a partial index is a performance drag on every query that uses its table, as we check to see if the partial index qual is satisfied by the query's WHERE clause. That's why I don't want it to be any slower than it is ... regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jun 16 11:18:00 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 77B0530ECCE for ; Mon, 16 Jun 2003 14:17:59 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 33865-05 for ; Mon, 16 Jun 2003 11:17:49 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id B434F30DE85 for ; Mon, 16 Jun 2003 11:17:48 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5GEHiU6002681; Mon, 16 Jun 2003 10:17:44 -0400 (EDT) To: Ryszard Lach Cc: pgsql-performance@postgresql.org Subject: Re: 7.3 vs 7.2 - different query plan, bad performance In-reply-to: <20030616114147.GJ1734@siaco.id.pl> References: <20030613184506.GE21614@siaco.id.pl> <20030616063850.GA31813@siaco.id.pl> <373rev0fotgpq2osvlldf41b8flambulk9@4ax.com> <20030616114147.GJ1734@siaco.id.pl> Comments: In-reply-to Ryszard Lach message dated "Mon, 16 Jun 2003 13:41:47 +0200" Date: Mon, 16 Jun 2003 10:17:43 -0400 Message-ID: <2680.1055773063@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/91 X-Sequence-Number: 2175 Ryszard Lach writes: > The point is, that my tables (and queries) are a 'little' bit more > complicated and I wanted to give as simple example as I could. I think > that problem is that subselects are _much_slower_ executed in 7.3 than > in 7.2, just as someone already wrote here. No, the problem is that 7.3 fails to notice that it doesn't really need to execute the subselect at all. This is the price we paid for being sure that a post-release bug fix wouldn't break anything more serious. There is a better fix in place for 7.4. regards, tom lane From pgsql-advocacy-owner@postgresql.org Mon Jun 16 13:31:09 2003 X-Original-To: pgsql-advocacy-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 732E330ED5F; Mon, 16 Jun 2003 16:31:00 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 36195-01; Mon, 16 Jun 2003 13:30:49 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id 0B37430EC9E; Mon, 16 Jun 2003 13:30:49 -0300 (ADT) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3125012; Mon, 16 Jun 2003 09:30:55 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: , Subject: Re: A bit OT- RE: [PERFORM] Re-ordering .CONF params ... questions for this list Date: Mon, 16 Jun 2003 09:28:07 -0700 User-Agent: KMail/1.4.3 Cc: References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200306160928.07521.josh@agliodbs.com> X-Archive-Number: 200306/117 X-Sequence-Number: 1329 Nick, > I agree... but are we the folks that the conf file needs to be made more > intuitive for? > > If the intent is to make it easier for experienced folks like ourselves who > are working with large or unusual databases to deal with PostgreSQL, then > certainly the resource usage and tuning settings should go to the top. > We'll set the other params once & never touch them again. > > On the other hand, I suspect that the majority of postgresql users play > with the other params a bit during install to get their systems working and > never touch the resource usage or tuning params ever. (And this is as it > should be, given that the defaults are reasonable for most systems.) This is a good argument. Though if you pursue it, surely you're advocating a GUI tool for PostgreSQL.conf, not that that's a bad idea ... How do other people feel about this? What options in PostgreSQL.conf do you tweak most frequently? -- Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Mon Jun 16 14:39:03 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 5DD5A30EDEC for ; Mon, 16 Jun 2003 17:39:02 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 42396-03 for ; Mon, 16 Jun 2003 14:38:52 -0300 (ADT) Received: from game.over.net (unknown [193.189.169.9]) by svr1.postgresql.org (Postfix) with ESMTP id 628D930EC9E for ; Mon, 16 Jun 2003 14:38:51 -0300 (ADT) Received: from localhost.over.net ([127.0.0.1]:14862 "EHLO zvezek.over.net") by mail.over.net with ESMTP id ; Mon, 16 Jun 2003 19:38:50 +0200 Message-Id: <5.2.1.1.0.20030616193558.02a5f0c0@127.0.0.1> X-Sender: tmail@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Mon, 16 Jun 2003 19:38:19 +0200 To: pgsql-performance@postgresql.org From: Tomaz Borstnar Subject: functional indexes instead of regular index on field(s)? Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200306/93 X-Sequence-Number: 2177 Hello! How much does planner take into consideration index size? Can one help planner use indexes by having several functional indexes which should be smaller instead of one bigger index which covers whole range of values per field(s)? Thanks in advance. From pgsql-performance-owner@postgresql.org Mon Jun 16 14:56:04 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 616F830E358 for ; Mon, 16 Jun 2003 17:56:03 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 68674-04 for ; Mon, 16 Jun 2003 14:55:53 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 71E5B30EE02 for ; Mon, 16 Jun 2003 14:55:52 -0300 (ADT) Received: (qmail 3338 invoked by uid 500); 16 Jun 2003 17:58:48 -0000 Date: Mon, 16 Jun 2003 12:58:48 -0500 From: Bruno Wolff III To: Tomaz Borstnar Cc: pgsql-performance@postgresql.org Subject: Re: functional indexes instead of regular index on field(s)? Message-ID: <20030616175848.GA3327@wolff.to> Mail-Followup-To: Tomaz Borstnar , pgsql-performance@postgresql.org References: <5.2.1.1.0.20030616193558.02a5f0c0@127.0.0.1> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5.2.1.1.0.20030616193558.02a5f0c0@127.0.0.1> User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/94 X-Sequence-Number: 2178 On Mon, Jun 16, 2003 at 19:38:19 +0200, Tomaz Borstnar wrote: > Hello! > > How much does planner take into consideration index size? Can one > help planner use indexes by having several functional indexes which should > be smaller instead of one bigger index which covers whole range of values > per field(s)? This sounds more like partial indexes than functional indexes. From pgsql-performance-owner@postgresql.org Mon Jun 16 16:49:35 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 49AD330E35D for ; Mon, 16 Jun 2003 19:49:34 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 91267-01 for ; Mon, 16 Jun 2003 16:49:23 -0300 (ADT) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by svr1.postgresql.org (Postfix) with ESMTP id 879F030D17A for ; Mon, 16 Jun 2003 16:49:23 -0300 (ADT) Received: from klaster.net (tv126.internetdsl.tpnet.pl [80.55.125.126]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 4F3E52B3D0 for ; Mon, 16 Jun 2003 21:49:13 +0200 (CEST) Message-ID: <3EEE1F54.3030507@klaster.net> Date: Mon, 16 Jun 2003 21:49:40 +0200 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: sequential scans on few columns tables Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/95 X-Sequence-Number: 2179 Hi Recently I was wondering about tables difficult to index. Example - queries with "ilike" where clauses. Without additional contrib modules the only way to search such tables is sequential scan (am I right?) The point is too keep these tables as small as possible. We can do this by denormalizing tables. Let's say we have table "users" which we split into 1:1 relation "users_header" and "users_data". We put searchable columns into users_header and rest of them into users_data. users_data have some integer foreign key referencing to users_header. What do you think about it? Does the Postgres use advantages of small table users_header? Sequential scan on memory cached table should speed up queries, the rest columns are in integer-indexed table which shouldn't slow it down. These example above is ony an idea, I don't have currently any example for it. Regards, Tomasz Myrta From pgsql-performance-owner@postgresql.org Mon Jun 16 16:53:07 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id A39E730E32B for ; Mon, 16 Jun 2003 19:53:06 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 83390-03 for ; Mon, 16 Jun 2003 16:52:55 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 05EE330E35D for ; Mon, 16 Jun 2003 16:52:55 -0300 (ADT) Received: (qmail 9263 invoked by uid 500); 16 Jun 2003 19:55:51 -0000 Date: Mon, 16 Jun 2003 14:55:51 -0500 From: Bruno Wolff III To: Tomasz Myrta Cc: pgsql-performance@postgresql.org Subject: Re: sequential scans on few columns tables Message-ID: <20030616195551.GB8871@wolff.to> Mail-Followup-To: Tomasz Myrta , pgsql-performance@postgresql.org References: <3EEE1F54.3030507@klaster.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3EEE1F54.3030507@klaster.net> User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/96 X-Sequence-Number: 2180 On Mon, Jun 16, 2003 at 21:49:40 +0200, Tomasz Myrta wrote: > Hi > Recently I was wondering about tables difficult to index. Example - > queries with "ilike" where clauses. Without additional contrib modules > the only way to search such tables is sequential scan (am I right?) You might be able to use a functional index depending on exactly what your search patterns are like. From pgsql-performance-owner@postgresql.org Mon Jun 16 17:32:38 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id E044530EF7C for ; Mon, 16 Jun 2003 20:32:37 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 19706-05 for ; Mon, 16 Jun 2003 17:32:27 -0300 (ADT) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by svr1.postgresql.org (Postfix) with ESMTP id 33C7530EF0F for ; Mon, 16 Jun 2003 17:32:27 -0300 (ADT) Received: from klaster.net (tv126.internetdsl.tpnet.pl [80.55.125.126]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id D7A5C2B64A; Mon, 16 Jun 2003 22:32:11 +0200 (CEST) Message-ID: <3EEE2960.9080707@klaster.net> Date: Mon, 16 Jun 2003 22:32:32 +0200 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.4b) Gecko/20030507 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: Bruno Wolff III Cc: pgsql-performance@postgresql.org Subject: Re: sequential scans on few columns tables References: <3EEE1F54.3030507@klaster.net> <20030616195551.GB8871@wolff.to> In-Reply-To: <20030616195551.GB8871@wolff.to> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 8bit X-Archive-Number: 200306/97 X-Sequence-Number: 2181 Dnia 2003-06-16 21:55, U�ytkownik Bruno Wolff III napisa�: > On Mon, Jun 16, 2003 at 21:49:40 +0200, > Tomasz Myrta wrote: > >>Hi >>Recently I was wondering about tables difficult to index. Example - >>queries with "ilike" where clauses. Without additional contrib modules >>the only way to search such tables is sequential scan (am I right?) > > > You might be able to use a functional index depending on exactly what your > search patterns are like. Probably functional indexes won't be helpful to find _substrings_. Tomasz From pgsql-performance-owner@postgresql.org Mon Jun 16 17:45:17 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 7BEEF30E35D for ; Mon, 16 Jun 2003 20:45:15 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 85798-05 for ; Mon, 16 Jun 2003 17:45:05 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 8E29930EEF2 for ; Mon, 16 Jun 2003 17:45:04 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5GKj3U6006635; Mon, 16 Jun 2003 16:45:03 -0400 (EDT) To: Dawn Hollingsworth Cc: pgsql-performance@postgresql.org Subject: Re: Postgres Connections Requiring Large Amounts of Memory In-reply-to: <1055752337.2182.49.camel@kaos> References: <1055752337.2182.49.camel@kaos> Comments: In-reply-to Dawn Hollingsworth message dated "16 Jun 2003 08:32:17 -0000" Date: Mon, 16 Jun 2003 16:45:02 -0400 Message-ID: <6634.1055796302@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/99 X-Sequence-Number: 2183 Dawn Hollingsworth writes: > PostgreSQL Version: 7.2.3 > My problem is that the memory used by the connections appears to grow > over time, especially when the amount of data entering the system is > increased. We have fixed memory-leak problems in the past, and I wouldn't be surprised if some remain, but you'll have to give a lot more detail about what you're doing if you want help. A leak that persists across transaction boundaries is fairly surprising --- I think I can safely say that there are none in the normal code paths. I'm guessing you must be using some off-the-beaten-path feature. regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jun 16 18:34:41 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 085C730EE16 for ; Mon, 16 Jun 2003 21:34:41 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 55671-09 for ; Mon, 16 Jun 2003 18:34:30 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 60DC530E363 for ; Mon, 16 Jun 2003 18:34:30 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5GLYTU6006893; Mon, 16 Jun 2003 17:34:29 -0400 (EDT) To: Dawn Hollingsworth Cc: pgsql-performance@postgresql.org Subject: Re: Postgres Connections Requiring Large Amounts of Memory In-reply-to: <1055753856.5467.57.camel@kaos> References: <1055752337.2182.49.camel@kaos> <6634.1055796302@sss.pgh.pa.us> <1055753856.5467.57.camel@kaos> Comments: In-reply-to Dawn Hollingsworth message dated "16 Jun 2003 08:57:35 -0000" Date: Mon, 16 Jun 2003 17:34:29 -0400 Message-ID: <6892.1055799269@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/101 X-Sequence-Number: 2185 Dawn Hollingsworth writes: > There are two things which might be considered off the beaten path > though: > 1. We have tables that have over 500 columns which we continually insert > into and select from. > 2. Our stored procedures take more than 16 parameters so in the file > config.h the value INDEX_MAX_KEYS was increased to 100. Neither of those raises a red flag with me. What would be useful to try to narrow things down is to look at the output of "MemoryContextStats(TopMemoryContext)" in a backend that's grown to a large size. This is a fairly primitive routine unfortunately; there is no built-in way to invoke it other than by calling it manually with a debugger, and it is only bright enough to write to stderr, not syslog. If you have stderr going somewhere useful (not /dev/null) and you built with debugging symbols, then you could attach to a running backend right now with gdb and get some useful info. If you don't have debugging symbols then you'll need to either rebuild with 'em, or create some other way to call the function. (There is a bit of stub code marked #ifdef SHOW_MEMORY_STATS in postgres.c that might be worth enabling, but I think it's only a sketch and won't compile as-is, since I don't see a ShowStats variable anywhere.) regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jun 16 19:32:24 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id C203130EF71 for ; Mon, 16 Jun 2003 22:32:22 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 47778-01 for ; Mon, 16 Jun 2003 19:32:10 -0300 (ADT) Received: from flake.decibel.org (unknown [66.143.173.58]) by svr1.postgresql.org (Postfix) with SMTP id 4842E30EC11 for ; Mon, 16 Jun 2003 19:32:09 -0300 (ADT) Received: (qmail 48006 invoked by uid 1001); 16 Jun 2003 22:32:09 -0000 Date: Mon, 16 Jun 2003 17:32:09 -0500 From: "Jim C. Nasby" To: pgsql-performance@postgresql.org Subject: Re: Partial index where clause not filtering through Message-ID: <20030616223209.GK40542@flake.decibel.org> Reply-To: jim@nasby.net References: <20030616003118.S66185@flake.decibel.org> <26793.1055742214@sss.pgh.pa.us> <20030616012456.U66185@flake.decibel.org> <2619.1055772660@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2619.1055772660@sss.pgh.pa.us> User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 4.8-RELEASE i386 X-Distributed: Join the Effort! http://www.distributed.net X-Archive-Number: 200306/102 X-Sequence-Number: 2186 On Mon, Jun 16, 2003 at 10:11:00AM -0400, Tom Lane wrote: > "Jim C. Nasby" writes: > > Well, it would only need to make the checks if the table had partial > > indexes. Even then, it probably makes sense to only do the check if > > other query planning steps decide it would be useful to use the partial > > index. > > You have that backwards. Planning is bottom-up, so we have to determine > the relevant indexes *first*. Accordingly, a partial index is a > performance drag on every query that uses its table, as we check to > see if the partial index qual is satisfied by the query's WHERE clause. > That's why I don't want it to be any slower than it is ... Well, could it assume the index was valid until we got to the point where we had to decide what index to use? In other words, don't do the test unless the index appears to be the most attractive one. Also, as I mentioned, if query parsing performance is that important, you can explicitly add whatever clause will show the planner that the index is valid. Also, I just read that there's no statement plan caching, which makes me a bit confused by this todo: Flush cached query plans when their underlying catalog data changes Does that only apply to pl/pgsql? Are there plans to add a statement cache? -- Jim C. Nasby (aka Decibel!) jim@nasby.net Member: Triangle Fraternity, Sports Car Club of America Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?" From pgsql-performance-owner@postgresql.org Mon Jun 16 19:40:38 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 88E9730EC11 for ; Mon, 16 Jun 2003 22:39:37 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 10091-08 for ; Mon, 16 Jun 2003 19:39:27 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id AC7A830DE85 for ; Mon, 16 Jun 2003 19:39:26 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5GMdPU6007289; Mon, 16 Jun 2003 18:39:25 -0400 (EDT) To: jim@nasby.net Cc: pgsql-performance@postgresql.org Subject: Re: Partial index where clause not filtering through In-reply-to: <20030616223209.GK40542@flake.decibel.org> References: <20030616003118.S66185@flake.decibel.org> <26793.1055742214@sss.pgh.pa.us> <20030616012456.U66185@flake.decibel.org> <2619.1055772660@sss.pgh.pa.us> <20030616223209.GK40542@flake.decibel.org> Comments: In-reply-to "Jim C. Nasby" message dated "Mon, 16 Jun 2003 17:32:09 -0500" Date: Mon, 16 Jun 2003 18:39:24 -0400 Message-ID: <7288.1055803164@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/103 X-Sequence-Number: 2187 "Jim C. Nasby" writes: > Also, I just read that there's no statement plan caching, which makes me > a bit confused by this todo: > Flush cached query plans when their underlying catalog data changes > Does that only apply to pl/pgsql? That and PREPARE. regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jun 16 19:41:17 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 55B8730EF00 for ; Mon, 16 Jun 2003 22:41:16 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 35045-09 for ; Mon, 16 Jun 2003 19:41:05 -0300 (ADT) Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) by svr1.postgresql.org (Postfix) with SMTP id 5173D30EF8C for ; Mon, 16 Jun 2003 19:41:05 -0300 (ADT) Received: (qmail 48144 invoked by uid 1001); 16 Jun 2003 22:41:05 -0000 Date: Mon, 16 Jun 2003 17:41:05 -0500 From: "Jim C. Nasby" To: pgsql-performance@postgresql.org Subject: Re: left join performance problem Message-ID: <20030616224105.GL40542@flake.decibel.org> Reply-To: jim@nasby.net References: <3EE74C2D.88390062@t1.unisoftbg.com> <26068.1055386671@sss.pgh.pa.us> <3EE8061B.1FAED8AD@t1.unisoftbg.com> <20030616001028.Q66185@flake.decibel.org> <26714.1055741306@sss.pgh.pa.us> <20030616003629.T66185@flake.decibel.org> <2363.1055769973@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2363.1055769973@sss.pgh.pa.us> User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 4.8-RELEASE i386 X-Distributed: Join the Effort! http://www.distributed.net X-Archive-Number: 200306/104 X-Sequence-Number: 2188 On Mon, Jun 16, 2003 at 09:26:13AM -0400, Tom Lane wrote: > "Jim C. Nasby" writes: > > On Mon, Jun 16, 2003 at 01:28:26AM -0400, Tom Lane wrote: > >> "Jim C. Nasby" writes: > > Any chance of getting a TODO added that would provide the option of > > having the optimizer pick join order when you're using the ANSI join > > syntax? > >> > >> No ... because it's already DONE. > > > DOH, I forgot about the subselect trick. Nevermind. > > No, I wasn't talking about that. See > http://developer.postgresql.org/docs/postgres/explicit-joins.html > for the way it works in CVS tip. Ahh, cool. BTW, I think it should be prominently mentioned in http://developer.postgresql.org/docs/postgres/sql-select.html#SQL-FROM that ANSI join syntax can force join order, since most DBA's unfamiliar with pgsql probably won't be expecting that. -- Jim C. Nasby (aka Decibel!) jim@nasby.net Member: Triangle Fraternity, Sports Car Club of America Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?" From pgsql-performance-owner@postgresql.org Mon Jun 16 19:45:40 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 9807030ECCE for ; Mon, 16 Jun 2003 22:45:39 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 72189-03 for ; Mon, 16 Jun 2003 19:45:29 -0300 (ADT) Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) by svr1.postgresql.org (Postfix) with SMTP id ABD2F30EF71 for ; Mon, 16 Jun 2003 19:45:28 -0300 (ADT) Received: (qmail 48205 invoked by uid 1001); 16 Jun 2003 22:45:27 -0000 Date: Mon, 16 Jun 2003 17:45:27 -0500 From: "Jim C. Nasby" To: pgsql-performance@postgresql.org Subject: Re: sequential scans on few columns tables Message-ID: <20030616224527.GM40542@flake.decibel.org> Reply-To: jim@nasby.net References: <3EEE1F54.3030507@klaster.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3EEE1F54.3030507@klaster.net> User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 4.8-RELEASE i386 X-Distributed: Join the Effort! http://www.distributed.net X-Archive-Number: 200306/105 X-Sequence-Number: 2189 On Mon, Jun 16, 2003 at 09:49:40PM +0200, Tomasz Myrta wrote: > by denormalizing tables. Let's say we have table "users" which we split > into 1:1 relation "users_header" and "users_data". We put searchable > columns into users_header and rest of them into users_data. users_data > have some integer foreign key referencing to users_header. > > What do you think about it? Does the Postgres use advantages of small > table users_header? Sequential scan on memory cached table should speed > up queries, the rest columns are in integer-indexed table which > shouldn't slow it down. Keep in mind that pgsql has a pretty heafty per-row overhead of 23 bytes. If your data table has a bunch of big varchars then it might be worth it, otherwise it might not be. -- Jim C. Nasby (aka Decibel!) jim@nasby.net Member: Triangle Fraternity, Sports Car Club of America Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?" From pgsql-general-owner@postgresql.org Mon Jun 16 19:47:14 2003 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 7059230DE85; Mon, 16 Jun 2003 22:47:13 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 65926-10; Mon, 16 Jun 2003 19:47:03 -0300 (ADT) Received: from relay11.austria.eu.net (relay11.Austria.eu.net [193.154.160.115]) by svr1.postgresql.org (Postfix) with ESMTP id 33FA030EF00; Mon, 16 Jun 2003 19:47:02 -0300 (ADT) Received: from sisyphus.vogelsinger.at (vogelsinger.at [193.154.189.26]) by relay11.austria.eu.net (8.12.9/8.12.0.Beta10) with ESMTP id h5GMkxc8031553; Tue, 17 Jun 2003 00:47:00 +0200 Message-Id: <5.1.1.6.2.20030617003809.02deaa78@mail.vogelsinger.at> X-Sender: homebird@mail.vogelsinger.at X-Mailer: QUALCOMM Windows Eudora Version 5.1.1 Date: Tue, 17 Jun 2003 00:46:54 +0200 To: pgsql-performance@postgresql.org, pgsql-general@postgresql.org From: Ernest E Vogelsinger Subject: Interesting incosistent query timing Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200306/960 X-Sequence-Number: 43890 Hi, I am researching some interesting inconsistent query timing and hope some of the gurus hanging out here might help me shed a light on this... The table: Column | Type | Modifiers --------+--------------------------+---------------------------------------- ------------ rid | integer | not null default nextval('rv2_mdata_id_seq'::text) pid | integer | owid | integer | ioid | integer | dcid | character varying | dsid | character varying | drid | integer | usg | integer | idx | character varying | env | integer | nxid | integer | ci | integer | cd | numeric(21,6) | cr | real | cts | timestamp with time zone | cst | character varying | ctx | text | cbl | oid | acl | text | Indexes: id_mdata_dictid, id_mdata_dictid_dec, id_mdata_dictid_int, id_mdata_dictid_real, id_mdata_dictid_string, id_mdata_dictid_text, id_mdata_dictid_timestamp, id_mdata_dowid, id_mdata_ioid, id_mdata_owid Primary key: rv2_mdata_pkey Index "id_mdata_dictid_string" Column | Type --------+------------------- dcid | character varying dsid | character varying drid | integer nxid | integer cst | character varying btree Index predicate: ((usg & 16) = 16) The query: explain analyze verbose select distinct t1.owid from rv2_mdata t1 where t1.dcid='ADDR' and t1.dsid='AUXDICT' and t1.drid=110 and t1.usg & 16 = 16 and t1.nxid = 0 and t1.cst ilike '%redist%' and t1.owid > 10 ; For the first time run it executes in 1.5 - 2 seconds. From the second time, only 10 msec are needed for the same result: Unique (cost=3.84..3.84 rows=1 width=4) (actual time=1569.36..1569.39 rows=11 loops=1) -> Sort (cost=3.84..3.84 rows=1 width=4) (actual time=1569.36..1569.37 rows=11 loops=1) -> Index Scan using id_mdata_dictid_string on rv2_mdata t1 (cost=0.00..3.83 rows=1 width=4) (actual time=17.02..1569.22 rows=11 loops=1) Total runtime: 1569.50 msec Unique (cost=3.84..3.84 rows=1 width=4) (actual time=10.51..10.53 rows=11 loops=1) -> Sort (cost=3.84..3.84 rows=1 width=4) (actual time=10.51..10.51 rows=11 loops=1) -> Index Scan using id_mdata_dictid_string on rv2_mdata t1 (cost=0.00..3.83 rows=1 width=4) (actual time=0.60..10.43 rows=11 loops=1) Total runtime: 10.64 msec If any of the "dcid", "dsid", or "drid" constraint values are altered, the query starts again at 1.5 - 2 secs, then drops to 10.5 msec again. Even after restarting PostgreSQL, the number is lower (~50 msec) than when running for the first time. I really would like to get a consistent timing here (the lower the better of course) since these queries will happen quite often within our application, and I need a consistent and predictable timing (this being a core component). This is postgresql 7.2.1 on RH72. Any clues? Thanks for insights, -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ From pgsql-general-owner@postgresql.org Mon Jun 16 20:46:41 2003 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 09C5130EEFC for ; Mon, 16 Jun 2003 23:46:38 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 67568-07 for ; Mon, 16 Jun 2003 20:46:27 -0300 (ADT) Received: from email03.aon.at (WARSL402PIP6.highway.telekom.at [195.3.96.93]) by svr1.postgresql.org (Postfix) with SMTP id E389530EFBA for ; Mon, 16 Jun 2003 20:46:26 -0300 (ADT) Received: (qmail 393310 invoked from network); 16 Jun 2003 23:46:26 -0000 Received: from m149p004.dipool.highway.telekom.at (HELO cantor) ([62.46.8.132]) (envelope-sender ) by qmail3rs.highway.telekom.at (qmail-ldap-1.03) with SMTP for ; 16 Jun 2003 23:46:26 -0000 From: Manfred Koizar To: Ernest E Vogelsinger Cc: pgsql-performance@postgresql.org, pgsql-general@postgresql.org Subject: Re: Interesting incosistent query timing Date: Tue, 17 Jun 2003 01:45:58 +0200 Message-ID: References: <5.1.1.6.2.20030617003809.02deaa78@mail.vogelsinger.at> In-Reply-To: <5.1.1.6.2.20030617003809.02deaa78@mail.vogelsinger.at> X-Mailer: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/964 X-Sequence-Number: 43894 On Tue, 17 Jun 2003 00:46:54 +0200, Ernest E Vogelsinger wrote: >For the first time run it executes in 1.5 - 2 seconds. From the second >time, only 10 msec are needed for the same result I'd call it inconsistent, if it were the other way round :-) I guess you are seeing the effects of disk caching. Watch the drive LED during the first run ... Servus Manfred From pgsql-general-owner@postgresql.org Wed Jun 18 14:16:12 2003 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 9F43730F035 for ; Tue, 17 Jun 2003 02:21:11 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 10168-09 for ; Mon, 16 Jun 2003 23:21:00 -0300 (ADT) Received: from c001.snv.cp.net (h001.c001.snv.cp.net [209.228.32.115]) by svr1.postgresql.org (Postfix) with SMTP id 68B6C30F008 for ; Mon, 16 Jun 2003 23:20:59 -0300 (ADT) Received: (cpmta 9269 invoked from network); 16 Jun 2003 19:20:59 -0700 Received: from 209.228.32.117 (HELO mail.dilger.cc.criticalpath.net) by smtp.register-admin.com (209.228.32.115) with SMTP; 16 Jun 2003 19:20:59 -0700 X-Sent: 17 Jun 2003 02:20:59 GMT Received: from [216.68.146.219] by mail.dilger.cc with HTTP; Mon, 16 Jun 2003 19:20:57 -0700 (PDT) Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 7bit MIME-Version: 1.0 To: ernest@vogelsinger.at Cc: pgsql-performance@postgresql.org, pgsql-general@postgresql.org From: "Nikolaus Dilger" Subject: Re: [PERFORM] Interesting incosistent query timing X-Sent-From: nikolaus@dilger.cc Date: Mon, 16 Jun 2003 19:20:57 -0700 (PDT) X-Mailer: Web Mail 5.4.0-4_sol28 Message-Id: <20030616192059.23131.h003.c001.wm@mail.dilger.cc.criticalpath.net> X-Archive-Number: 200306/1145 X-Sequence-Number: 44073 Ernest, My guess is that the second execution of the query is shorter since the data blocks are cached in memory. When you modify the data then it needs to be read again from disk which is much slower than from memory. The short execution after restarting PostgreSQL seems to indicate that your data is cached in the Linux buffer cache. The only strange thing seems to be that you have so few rows. Are you getting the data from a remote machine? How many bytes does a single row have? Are they really large??? Regards, Nikolaus On Tue, 17 Jun 2003 00:46:54 +0200, Ernest E Vogelsinger wrote: > > Hi, > > I am researching some interesting inconsistent query > timing and hope some > of the gurus hanging out here might help me shed a > light on this... > > The table: > Column | Type | > Modifiers > > --------+--------------------------+---------------------------------------- > ------------ > rid | integer | not null default > nextval('rv2_mdata_id_seq'::text) > pid | integer | > owid | integer | > ioid | integer | > dcid | character varying | > dsid | character varying | > drid | integer | > usg | integer | > idx | character varying | > env | integer | > nxid | integer | > ci | integer | > cd | numeric(21,6) | > cr | real | > cts | timestamp with time zone | > cst | character varying | > ctx | text | > cbl | oid | > acl | text | > Indexes: id_mdata_dictid, > id_mdata_dictid_dec, > id_mdata_dictid_int, > id_mdata_dictid_real, > id_mdata_dictid_string, > id_mdata_dictid_text, > id_mdata_dictid_timestamp, > id_mdata_dowid, > id_mdata_ioid, > id_mdata_owid > Primary key: rv2_mdata_pkey > > Index "id_mdata_dictid_string" > Column | Type > --------+------------------- > dcid | character varying > dsid | character varying > drid | integer > nxid | integer > cst | character varying > btree > Index predicate: ((usg & 16) = 16) > > > > The query: > explain analyze verbose > select distinct t1.owid > from rv2_mdata t1 > where t1.dcid='ADDR' and t1.dsid='AUXDICT' and > t1.drid=110 and > t1.usg & 16 = 16 > and t1.nxid = 0 > and t1.cst ilike '%redist%' > and t1.owid > 10 > ; > > For the first time run it executes in 1.5 - 2 seconds. > From the second > time, only 10 msec are needed for the same result: > > Unique (cost=3.84..3.84 rows=1 width=4) (actual > time=1569.36..1569.39 > rows=11 loops=1) > -> Sort (cost=3.84..3.84 rows=1 width=4) (actual > time=1569.36..1569.37 > rows=11 loops=1) > -> Index Scan using id_mdata_dictid_string on > rv2_mdata t1 > (cost=0.00..3.83 rows=1 width=4) (actual > time=17.02..1569.22 rows=11 loops=1) > Total runtime: 1569.50 msec > > > Unique (cost=3.84..3.84 rows=1 width=4) (actual > time=10.51..10.53 rows=11 > loops=1) > -> Sort (cost=3.84..3.84 rows=1 width=4) (actual > time=10.51..10.51 > rows=11 loops=1) > -> Index Scan using id_mdata_dictid_string on > rv2_mdata t1 > (cost=0.00..3.83 rows=1 width=4) (actual > time=0.60..10.43 rows=11 loops=1) > Total runtime: 10.64 msec > > If any of the "dcid", "dsid", or "drid" constraint > values are altered, the > query starts again at 1.5 - 2 secs, then drops to 10.5 > msec again. > > Even after restarting PostgreSQL, the number is lower > (~50 msec) than when > running for the first time. > > I really would like to get a consistent timing here > (the lower the better > of course) since these queries will happen quite often > within our > application, and I need a consistent and predictable > timing (this being a > core component). > > This is postgresql 7.2.1 on RH72. > > Any clues? Thanks for insights, > > > -- > >O Ernest E. Vogelsinger > (\) ICQ #13394035 > ^ http://www.vogelsinger.at/ > > > > ---------------------------(end of > broadcast)--------------------------- > TIP 7: don't forget to increase your free space map > settings From pgsql-general-owner@postgresql.org Mon Jun 16 23:55:19 2003 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 826BE30E9E3; Tue, 17 Jun 2003 02:55:16 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 05081-09; Mon, 16 Jun 2003 23:55:06 -0300 (ADT) Received: from relay11.austria.eu.net (relay11.Austria.eu.net [193.154.160.115]) by svr1.postgresql.org (Postfix) with ESMTP id E8ED430EFC2; Mon, 16 Jun 2003 23:55:04 -0300 (ADT) Received: from sisyphus.vogelsinger.at (vogelsinger.at [193.154.189.26]) by relay11.austria.eu.net (8.12.9/8.12.0.Beta10) with ESMTP id h5H2t1c8031687; Tue, 17 Jun 2003 04:55:01 +0200 Message-Id: <5.1.1.6.2.20030617044100.02dd1c70@mail.vogelsinger.at> X-Sender: homebird@mail.vogelsinger.at X-Mailer: QUALCOMM Windows Eudora Version 5.1.1 Date: Tue, 17 Jun 2003 04:54:56 +0200 To: "Nikolaus Dilger" From: Ernest E Vogelsinger Subject: Re: [PERFORM] Interesting incosistent query timing Cc: pgsql-performance@postgresql.org, pgsql-general@postgresql.org In-Reply-To: <20030616192059.23131.h003.c001.wm@mail.dilger.cc.criticalp ath.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Archive-Number: 200306/976 X-Sequence-Number: 43906 At 04:20 17.06.2003, Nikolaus Dilger said: --------------------[snip]-------------------- >My guess is that the second execution of the query is >shorter since the data blocks are cached in memory. >When you modify the data then it needs to be read again >from disk which is much slower than from memory. The >short execution after restarting PostgreSQL seems to >indicate that your data is cached in the Linux buffer >cache. > >The only strange thing seems to be that you have so few >rows. Are you getting the data from a remote machine? >How many bytes does a single row have? Are they really >large??? --------------------[snip]-------------------- What exactly do you mean? This table is quite filled (2.3 million rows), but the query results are correct. -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ From pgsql-performance-owner@postgresql.org Tue Jun 17 15:48:51 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 7B3F730F02D for ; Tue, 17 Jun 2003 18:48:50 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 70612-07 for ; Tue, 17 Jun 2003 15:48:39 -0300 (ADT) Received: from smaug.securitymatrix.com (unknown [64.25.5.177]) by svr1.postgresql.org (Postfix) with ESMTP id 4546830F1DD for ; Tue, 17 Jun 2003 15:48:36 -0300 (ADT) Received: from kaos.securitymatrix.com ([172.16.0.101]) by smaug.securitymatrix.com (8.11.6/8.11.6) with ESMTP id h5HIlsV22659; Tue, 17 Jun 2003 14:47:54 -0400 Subject: Re: Postgres Connections Requiring Large Amounts of Memory From: Dawn Hollingsworth To: Tom Lane Cc: pgsql-performance@postgresql.org, Ben Scherrey In-Reply-To: <6892.1055799269@sss.pgh.pa.us> References: <1055752337.2182.49.camel@kaos> <6634.1055796302@sss.pgh.pa.us> <1055753856.5467.57.camel@kaos> <6892.1055799269@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="=-YMPIbKLigTD4G9ES1SUG" X-Mailer: Ximian Evolution 1.0.8 Date: 17 Jun 2003 06:46:48 +0000 Message-Id: <1055832411.5467.100.camel@kaos> Mime-Version: 1.0 X-Archive-Number: 200306/113 X-Sequence-Number: 2197 --=-YMPIbKLigTD4G9ES1SUG Content-Type: text/plain Content-Transfer-Encoding: 7bit I installed postgres with debug compiled in and ran the same tests. I attached gdb to a connection using just over 400MB( according to top) and ran "MemoryContextStats(TopMemoryContext)" Here's the output: TopMemoryContext: 49176 total in 6 blocks; 16272 free (44 chunks); 32904 used TopTransactionContext: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used TransactionCommandContext: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 3072 total in 2 blocks; 864 free (0 chunks); 2208 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 3072 total in 2 blocks; 720 free (0 chunks); 2352 used SPI Plan: 1024 total in 1 blocks; 184 free (0 chunks); 840 used SPI Plan: 261120 total in 8 blocks; 20416 free (0 chunks); 240704 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 261120 total in 8 blocks; 18456 free (0 chunks); 242664 used SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used SPI Plan: 31744 total in 5 blocks; 15024 free (0 chunks); 16720 used SPI Plan: 1024 total in 1 blocks; 184 free (0 chunks); 840 used SPI Plan: 523264 total in 9 blocks; 80504 free (0 chunks); 442760 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 523264 total in 9 blocks; 79992 free (0 chunks); 443272 used SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used SPI Plan: 7168 total in 3 blocks; 1816 free (0 chunks); 5352 used SPI Plan: 1024 total in 1 blocks; 184 free (0 chunks); 840 used SPI Plan: 261120 total in 8 blocks; 130824 free (3 chunks); 130296 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 261120 total in 8 blocks; 130032 free (0 chunks); 131088 used SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used SPI Plan: 130048 total in 7 blocks; 36512 free (0 chunks); 93536 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used SPI Plan: 1024 total in 1 blocks; 184 free (0 chunks); 840 used SPI Plan: 130048 total in 7 blocks; 37976 free (0 chunks); 92072 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 130048 total in 7 blocks; 34688 free (0 chunks); 95360 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 3072 total in 2 blocks; 864 free (0 chunks); 2208 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 3072 total in 2 blocks; 536 free (0 chunks); 2536 used SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used SPI Plan: 31744 total in 5 blocks; 15024 free (0 chunks); 16720 used SPI Plan: 1024 total in 1 blocks; 184 free (0 chunks); 840 used SPI Plan: 130048 total in 7 blocks; 26120 free (0 chunks); 103928 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 130048 total in 7 blocks; 24232 free (0 chunks); 105816 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 3072 total in 2 blocks; 128 free (0 chunks); 2944 used SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used SPI Plan: 7168 total in 3 blocks; 1816 free (0 chunks); 5352 used SPI Plan: 7168 total in 3 blocks; 1816 free (0 chunks); 5352 used SPI Plan: 7168 total in 3 blocks; 1816 free (0 chunks); 5352 used SPI Plan: 1024 total in 1 blocks; 184 free (0 chunks); 840 used SPI Plan: 64512 total in 6 blocks; 24688 free (0 chunks); 39824 used SPI Plan: 64512 total in 6 blocks; 23792 free (0 chunks); 40720 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 64512 total in 6 blocks; 23464 free (0 chunks); 41048 used SPI Plan: 31744 total in 5 blocks; 10088 free (0 chunks); 21656 used SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used SPI Plan: 31744 total in 5 blocks; 8576 free (0 chunks); 23168 used SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used SPI Plan: 3096 total in 2 blocks; 8 free (0 chunks); 3088 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used SPI Plan: 1024 total in 1 blocks; 184 free (0 chunks); 840 used SPI Plan: 31744 total in 5 blocks; 6672 free (0 chunks); 25072 used SPI Plan: 3072 total in 2 blocks; 1840 free (0 chunks); 1232 used SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used QueryContext: 24576 total in 2 blocks; 15304 free (56 chunks); 9272 used DeferredTriggerSession: 0 total in 0 blocks; 0 free (0 chunks); 0 used PortalMemory: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used CacheMemoryContext: 2108952 total in 10 blocks; 1070136 free (3338 chunks); 1038816 used bss_pkey: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_epoch_sensor_10_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_epoch_sensor_9_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_epoch_sensor_8_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_epoch_sensor_7_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_epoch_sensor_6_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_epoch_sensor_5_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_epoch_sensor_4_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_epoch_sensor_3_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_epoch_sensor_2_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_epoch_sensor_1_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_epoch_bss_id_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used station_epochint_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used station_epoch_pkey: 1024 total in 1 blocks; 392 free (0 chunks); 632 used station_sensor_10_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_sensor_9_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_sensor_8_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_sensor_7_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_sensor_6_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_sensor_5_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_sensor_4_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_sensor_3_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_sensor_2_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_sensor_1_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_lastseenint_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used station_lastseen_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used station_firstseenint_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used station_firstseen_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used station_pkey_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used station_cfg_view_pkey: 1024 total in 1 blocks; 680 free (0 chunks); 344 used bss_cfg_view_pkey: 1024 total in 1 blocks; 680 free (0 chunks); 344 used sensor_cfg_view_pk: 1024 total in 1 blocks; 680 free (0 chunks); 344 used station_epoch_sum_pk_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used pg_index_indrelid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used pg_relcheck_rcrelid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used pg_attrdef_adrelid_adnum_index: 1024 total in 1 blocks; 392 free (0 chunks); 632 used pg_shadow_usesysid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used pg_trigger_tgrelid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used pg_language_oid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used pg_proc_oid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used pg_aggregate_name_type_index: 1024 total in 1 blocks; 392 free (0 chunks); 632 used pg_type_oid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used pg_proc_proname_narg_type_index: 1024 total in 1 blocks; 392 free (0 chunks); 632 used pg_amop_opc_strategy_index: 1024 total in 1 blocks; 392 free (0 chunks); 632 used pg_operator_oid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used pg_amproc_opc_procnum_index: 1024 total in 1 blocks; 392 free (0 chunks); 632 used pg_index_indexrelid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used pg_type_typname_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used pg_class_oid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used pg_class_relname_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used pg_attribute_relid_attnum_index: 1024 total in 1 blocks; 392 free (0 chunks); 632 used MdSmgr: 8192 total in 1 blocks; 4072 free (1 chunks); 4120 used DynaHash: 8192 total in 1 blocks; 6944 free (0 chunks); 1248 used DynaHashTable: 8192 total in 1 blocks; 5080 free (0 chunks); 3112 used DynaHashTable: 42008 total in 2 blocks; 6112 free (0 chunks); 35896 used DynaHashTable: 8192 total in 1 blocks; 6112 free (0 chunks); 2080 used DynaHashTable: 8192 total in 1 blocks; 3000 free (0 chunks); 5192 used DynaHashTable: 8192 total in 1 blocks; 3000 free (0 chunks); 5192 used DynaHashTable: 24576 total in 2 blocks; 13224 free (4 chunks); 11352 used DynaHashTable: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used DynaHashTable: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used DynaHashTable: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used DynaHashTable: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used DynaHashTable: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used ErrorContext: 8192 total in 1 blocks; 8176 free (1 chunks); 16 used Is there any other information I could provide that would be useful? I'm going to try to enable SHOW_MEMORY_STATS next. -Dawn On Mon, 2003-06-16 at 21:34, Tom Lane wrote: > What would be useful to try to narrow things down is to look at the > output of "MemoryContextStats(TopMemoryContext)" in a backend that's > grown to a large size. This is a fairly primitive routine > unfortunately; there is no built-in way to invoke it other than by > calling it manually with a debugger, and it is only bright enough > to write to stderr, not syslog. If you have stderr going somewhere > useful (not /dev/null) and you built with debugging symbols, then you > could attach to a running backend right now with gdb and get some useful > info. If you don't have debugging symbols then you'll need to either > rebuild with 'em, or create some other way to call the function. > (There is a bit of stub code marked #ifdef SHOW_MEMORY_STATS in > postgres.c that might be worth enabling, but I think it's only a sketch > and won't compile as-is, since I don't see a ShowStats variable > anywhere.) > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster --=-YMPIbKLigTD4G9ES1SUG Content-Type: text/html; charset=utf-8
I installed postgres with debug compiled in and ran the same tests.

I attached gdb to a connection using just over 400MB( according to top) and ran "MemoryContextStats(TopMemoryContext)"

Here's the output:

TopMemoryContext: 49176 total in 6 blocks; 16272 free (44 chunks); 32904 used
TopTransactionContext: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used
TransactionCommandContext: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 3072 total in 2 blocks; 864 free (0 chunks); 2208 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 3072 total in 2 blocks; 720 free (0 chunks); 2352 used
SPI Plan: 1024 total in 1 blocks; 184 free (0 chunks); 840 used
SPI Plan: 261120 total in 8 blocks; 20416 free (0 chunks); 240704 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 261120 total in 8 blocks; 18456 free (0 chunks); 242664 used
SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
SPI Plan: 31744 total in 5 blocks; 15024 free (0 chunks); 16720 used
SPI Plan: 1024 total in 1 blocks; 184 free (0 chunks); 840 used
SPI Plan: 523264 total in 9 blocks; 80504 free (0 chunks); 442760 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 523264 total in 9 blocks; 79992 free (0 chunks); 443272 used
SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
SPI Plan: 7168 total in 3 blocks; 1816 free (0 chunks); 5352 used
SPI Plan: 1024 total in 1 blocks; 184 free (0 chunks); 840 used
SPI Plan: 261120 total in 8 blocks; 130824 free (3 chunks); 130296 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 261120 total in 8 blocks; 130032 free (0 chunks); 131088 used
SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
SPI Plan: 130048 total in 7 blocks; 36512 free (0 chunks); 93536 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
SPI Plan: 1024 total in 1 blocks; 184 free (0 chunks); 840 used
SPI Plan: 130048 total in 7 blocks; 37976 free (0 chunks); 92072 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 130048 total in 7 blocks; 34688 free (0 chunks); 95360 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 3072 total in 2 blocks; 864 free (0 chunks); 2208 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 3072 total in 2 blocks; 536 free (0 chunks); 2536 used
SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used
SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used
SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
SPI Plan: 31744 total in 5 blocks; 15024 free (0 chunks); 16720 used
SPI Plan: 1024 total in 1 blocks; 184 free (0 chunks); 840 used
SPI Plan: 130048 total in 7 blocks; 26120 free (0 chunks); 103928 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 130048 total in 7 blocks; 24232 free (0 chunks); 105816 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 3072 total in 2 blocks; 128 free (0 chunks); 2944 used
SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
SPI Plan: 7168 total in 3 blocks; 1816 free (0 chunks); 5352 used
SPI Plan: 7168 total in 3 blocks; 1816 free (0 chunks); 5352 used
SPI Plan: 7168 total in 3 blocks; 1816 free (0 chunks); 5352 used
SPI Plan: 1024 total in 1 blocks; 184 free (0 chunks); 840 used
SPI Plan: 64512 total in 6 blocks; 24688 free (0 chunks); 39824 used
SPI Plan: 64512 total in 6 blocks; 23792 free (0 chunks); 40720 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 64512 total in 6 blocks; 23464 free (0 chunks); 41048 used
SPI Plan: 31744 total in 5 blocks; 10088 free (0 chunks); 21656 used
SPI Plan: 7168 total in 3 blocks; 3904 free (4 chunks); 3264 used
SPI Plan: 31744 total in 5 blocks; 8576 free (0 chunks); 23168 used
SPI Plan: 7168 total in 3 blocks; 4016 free (5 chunks); 3152 used
SPI Plan: 3096 total in 2 blocks; 8 free (0 chunks); 3088 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
SPI Plan: 1024 total in 1 blocks; 184 free (0 chunks); 840 used
SPI Plan: 31744 total in 5 blocks; 6672 free (0 chunks); 25072 used
SPI Plan: 3072 total in 2 blocks; 1840 free (0 chunks); 1232 used
SPI Plan: 1024 total in 1 blocks; 256 free (0 chunks); 768 used
QueryContext: 24576 total in 2 blocks; 15304 free (56 chunks); 9272 used
DeferredTriggerSession: 0 total in 0 blocks; 0 free (0 chunks); 0 used
PortalMemory: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used
CacheMemoryContext: 2108952 total in 10 blocks; 1070136 free (3338 chunks); 1038816 used
bss_pkey: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_epoch_sensor_10_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_epoch_sensor_9_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_epoch_sensor_8_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_epoch_sensor_7_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_epoch_sensor_6_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_epoch_sensor_5_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_epoch_sensor_4_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_epoch_sensor_3_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_epoch_sensor_2_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_epoch_sensor_1_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_epoch_bss_id_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
station_epochint_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
station_epoch_pkey: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
station_sensor_10_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_sensor_9_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_sensor_8_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_sensor_7_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_sensor_6_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_sensor_5_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_sensor_4_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_sensor_3_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_sensor_2_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_sensor_1_idx: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_lastseenint_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
station_lastseen_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
station_firstseenint_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
station_firstseen_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
station_pkey_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
station_cfg_view_pkey: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
bss_cfg_view_pkey: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
sensor_cfg_view_pk: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
station_epoch_sum_pk_idx: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
pg_index_indrelid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
pg_relcheck_rcrelid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
pg_attrdef_adrelid_adnum_index: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
pg_shadow_usesysid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
pg_trigger_tgrelid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
pg_language_oid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
pg_proc_oid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
pg_aggregate_name_type_index: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
pg_type_oid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
pg_proc_proname_narg_type_index: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
pg_amop_opc_strategy_index: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
pg_operator_oid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
pg_amproc_opc_procnum_index: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
pg_index_indexrelid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
pg_type_typname_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
pg_class_oid_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
pg_class_relname_index: 1024 total in 1 blocks; 680 free (0 chunks); 344 used
pg_attribute_relid_attnum_index: 1024 total in 1 blocks; 392 free (0 chunks); 632 used
MdSmgr: 8192 total in 1 blocks; 4072 free (1 chunks); 4120 used
DynaHash: 8192 total in 1 blocks; 6944 free (0 chunks); 1248 used
DynaHashTable: 8192 total in 1 blocks; 5080 free (0 chunks); 3112 used
DynaHashTable: 42008 total in 2 blocks; 6112 free (0 chunks); 35896 used
DynaHashTable: 8192 total in 1 blocks; 6112 free (0 chunks); 2080 used
DynaHashTable: 8192 total in 1 blocks; 3000 free (0 chunks); 5192 used
DynaHashTable: 8192 total in 1 blocks; 3000 free (0 chunks); 5192 used
DynaHashTable: 24576 total in 2 blocks; 13224 free (4 chunks); 11352 used
DynaHashTable: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used
DynaHashTable: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used
DynaHashTable: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used
DynaHashTable: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used
DynaHashTable: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used
ErrorContext: 8192 total in 1 blocks; 8176 free (1 chunks); 16 used

Is there any other information I could provide that would be useful? I'm going to try to enable SHOW_MEMORY_STATS next.

-Dawn

On Mon, 2003-06-16 at 21:34, Tom Lane wrote:
> What would be useful to try to narrow things down is to look at the
> output of "MemoryContextStats(TopMemoryContext)" in a backend that's
> grown to a large size.  This is a fairly primitive routine
> unfortunately; there is no built-in way to invoke it other than by
> calling it manually with a debugger, and it is only bright enough
> to write to stderr, not syslog.  If you have stderr going somewhere
> useful (not /dev/null) and you built with debugging symbols, then you
> could attach to a running backend right now with gdb and get some useful
> info.  If you don't have debugging symbols then you'll need to either
> rebuild with 'em, or create some other way to call the function.
> (There is a bit of stub code marked #ifdef SHOW_MEMORY_STATS in
> postgres.c that might be worth enabling, but I think it's only a sketch
> and won't compile as-is, since I don't see a ShowStats variable
> anywhere.)
> 
> 			regards, tom lane
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

--=-YMPIbKLigTD4G9ES1SUG-- From pgsql-performance-owner@postgresql.org Tue Jun 17 04:41:39 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 48AD230F037; Tue, 17 Jun 2003 07:41:37 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 70579-07; Tue, 17 Jun 2003 04:41:27 -0300 (ADT) Received: from dos.sipec.es (unknown [62.36.228.122]) by svr1.postgresql.org (Postfix) with ESMTP id 711E730F04D; Tue, 17 Jun 2003 04:41:26 -0300 (ADT) Received: from jgimenez81 ([10.1.1.111]) by dos.sipec.es with Microsoft SMTPSVC(5.0.2195.5329); Tue, 17 Jun 2003 09:43:40 +0200 From: =?iso-8859-1?Q?Jordi_Gim=E9nez?= To: Cc: Subject: approve xec5mm unsubscribe pgsql-performance jgimenez@sipec.es Date: Tue, 17 Jun 2003 09:43:39 +0200 Message-ID: <000801c334a4$2b3ee950$6f01010a@sipec.es> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.6604 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Importance: Normal X-OriginalArrivalTime: 17 Jun 2003 07:43:40.0031 (UTC) FILETIME=[2B2F58F0:01C334A4] X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200306/110 X-Sequence-Number: 2194 approve xec5mm unsubscribe pgsql-performance jgimenez@sipec.es From pgsql-performance-owner@postgresql.org Tue Jun 17 18:44:07 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1EA6630F252 for ; Tue, 17 Jun 2003 21:44:05 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 92944-02 for ; Tue, 17 Jun 2003 18:43:53 -0300 (ADT) Received: from smaug.securitymatrix.com (unknown [64.25.5.177]) by svr1.postgresql.org (Postfix) with ESMTP id C371330F241 for ; Tue, 17 Jun 2003 18:43:52 -0300 (ADT) Received: from kaos.securitymatrix.com ([172.16.0.101]) by smaug.securitymatrix.com (8.11.6/8.11.6) with ESMTP id h5HLhEV22868; Tue, 17 Jun 2003 17:43:14 -0400 Subject: Re: Postgres Connections Requiring Large Amounts of Memory From: Dawn Hollingsworth To: Tom Lane Cc: pgsql-performance@postgresql.org, Ben Scherrey In-Reply-To: <14875.1055878682@sss.pgh.pa.us> References: <1055752337.2182.49.camel@kaos> <6634.1055796302@sss.pgh.pa.us> <1055753856.5467.57.camel@kaos> <6892.1055799269@sss.pgh.pa.us> <1055832411.5467.100.camel@kaos> <14875.1055878682@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="=-Lq5FzIe2W5aN0kK/fEWI" X-Mailer: Ximian Evolution 1.0.8 Date: 17 Jun 2003 09:42:07 +0000 Message-Id: <1055842927.2182.227.camel@kaos> Mime-Version: 1.0 X-Archive-Number: 200306/115 X-Sequence-Number: 2199 --=-Lq5FzIe2W5aN0kK/fEWI Content-Type: text/plain Content-Transfer-Encoding: 7bit The database is used to store information for a network management application. Almost all the Primary Keys are MACADDR or MACADDR,TIMSTAMPTZ and the Foreign Keys are almost always on one MACADDR column with "ON UPDATE CASCADE ON DELETE CASCADE". It's not very complicated. I have not written any triggers of my own. The connection I was looking at only does inserts and updates, no deletes. All database access is made through stored procedures using plpgsql. The stored procedures all work like: table1( id MACADDR, ... Primary Key(id) ) table2( id MACADDR, mytime TIMESTAMPTZ, .... Primary Key(id, mytime), FOREIGN KEY(id) REFERENCES table1 ON UPDATE CASCADE ON DELETE CASCADE) Update table1 if update row count = 0 then insert into table1 end if insert into table 2 I'm not starting any of my own transactions and I'm not calling stored procedures from withing stored procedures. The stored procedures do have large parameters lists, up to 100. The tables are from 300 to 500 columns. 90% of the columns are either INT4 or INT8. Some of these tables are inherited. Could that be causing problems? - Dawn > Hmm. This only seems to account for about 5 meg of space, which means > either that lots of space is being used and released, or that the leak > is coming from direct malloc calls rather than palloc. I doubt the > latter though; we don't use too many direct malloc calls. > > On the former theory, could it be something like updating a large > number of tuples in one transaction in a table with foreign keys? > The pending-triggers list could have swelled up and then gone away > again. > > The large number of SPI Plan contexts seems a tad fishy, and even more > so the fact that some of them are rather large. They still only account > for a couple of meg, so they aren't directly the problem, but perhaps > they are related to the problem. I presume these came from either > foreign-key triggers or something you've written in PL functions. Can > you tell us more about what you use in that line? > > regards, tom lane --=-Lq5FzIe2W5aN0kK/fEWI Content-Type: text/html; charset=utf-8
The database is used to store information for a network management application. Almost all the Primary Keys are MACADDR or MACADDR,TIMSTAMPTZ and the Foreign Keys are almost always on one MACADDR column with "ON UPDATE CASCADE ON DELETE CASCADE".   It's not very complicated. I have not written any triggers of my own.

The connection I was looking at only does inserts and updates, no deletes. All database access is made through stored procedures using plpgsql.  The stored procedures all work like:
table1( id MACADDR, ... Primary Key(id) )
table2( id MACADDR, mytime TIMESTAMPTZ, .... Primary Key(id, mytime), FOREIGN KEY(id) REFERENCES table1 ON UPDATE CASCADE ON DELETE CASCADE)

Update table1
if update row count = 0 then
   insert into table1
end if

insert into table 2

I'm not starting any of my own transactions and I'm not calling stored procedures from withing stored procedures. The stored procedures do have large parameters lists, up to 100. The tables are from 300 to 500 columns. 90% of the columns are either INT4 or INT8.  Some of these tables are inherited. Could that be causing problems?


- Dawn
> Hmm.  This only seems to account for about 5 meg of space, which means
> either that lots of space is being used and released, or that the leak
> is coming from direct malloc calls rather than palloc.  I doubt the
> latter though; we don't use too many direct malloc calls.
> 
> On the former theory, could it be something like updating a large
> number of tuples in one transaction in a table with foreign keys?
> The pending-triggers list could have swelled up and then gone away
> again.
> 
> The large number of SPI Plan contexts seems a tad fishy, and even more
> so the fact that some of them are rather large.  They still only account
> for a couple of meg, so they aren't directly the problem, but perhaps
> they are related to the problem.  I presume these came from either
> foreign-key triggers or something you've written in PL functions.  Can
> you tell us more about what you use in that line?
> 
> 			regards, tom lane

--=-Lq5FzIe2W5aN0kK/fEWI-- From pgsql-performance-owner@postgresql.org Tue Jun 17 07:00:43 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 2C28E30F0B2 for ; Tue, 17 Jun 2003 10:00:42 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 89047-05 for ; Tue, 17 Jun 2003 07:00:31 -0300 (ADT) Received: from lewexch.lewis-stores.com (mail.lewis-stores.com [196.31.249.242]) by svr1.postgresql.org (Postfix) with ESMTP id 9474B30F0CA for ; Tue, 17 Jun 2003 07:00:28 -0300 (ADT) Received: by LEWEXCH with Internet Mail Service (5.5.2650.21) id ; Tue, 17 Jun 2003 11:55:04 +0200 Message-ID: From: Howard Oblowitz To: pgsql-performance@postgresql.org Subject: Limiting Postgres memory usage Date: Tue, 17 Jun 2003 11:53:14 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200306/111 X-Sequence-Number: 2195 Is there a way to limit the amount of memory that postgres will use? From pgsql-performance-owner@postgresql.org Tue Jun 17 07:26:29 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 23A2330F03C for ; Tue, 17 Jun 2003 10:26:25 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 95204-06 for ; Tue, 17 Jun 2003 07:26:14 -0300 (ADT) Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id 26CDF30F00F for ; Tue, 17 Jun 2003 07:26:13 -0300 (ADT) Received: (from root@localhost) by www.pspl.co.in (8.11.6/8.11.6) id h5HAQAf03125 for ; Tue, 17 Jun 2003 15:56:10 +0530 Received: from daithan (daithan.intranet.pspl.co.in [192.168.7.161]) by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h5HAQ9903120 for ; Tue, 17 Jun 2003 15:56:10 +0530 From: "Shridhar Daithankar" To: pgsql-performance@postgresql.org Date: Tue, 17 Jun 2003 15:55:22 +0530 MIME-Version: 1.0 Subject: Re: Limiting Postgres memory usage Reply-To: shridhar_daithankar@persistent.co.in Message-ID: <3EEF39EA.20352.D25B51@localhost> In-reply-to: X-mailer: Pegasus Mail for Windows (v4.02) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Archive-Number: 200306/112 X-Sequence-Number: 2196 On 17 Jun 2003 at 11:53, Howard Oblowitz wrote: > Is there a way to limit the amount of memory that postgres > will use? Postgresql will use memory as specified by settings in postgresql.conf. The config file is pretty well documented in itself. Go thr. it.. HTH Bye Shridhar -- Paprika Measure: 2 dashes == 1smidgen 2 smidgens == 1 pinch 3 pinches == 1 soupcon 2 soupcons == 2 much paprika From pgsql-performance-owner@postgresql.org Tue Jun 17 20:05:29 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 90EEE30F298 for ; Tue, 17 Jun 2003 23:05:28 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 04996-02 for ; Tue, 17 Jun 2003 20:05:17 -0300 (ADT) Received: from smaug.securitymatrix.com (unknown [64.25.5.177]) by svr1.postgresql.org (Postfix) with ESMTP id 741F730F24E for ; Tue, 17 Jun 2003 20:05:17 -0300 (ADT) Received: from kaos.securitymatrix.com ([172.16.0.101]) by smaug.securitymatrix.com (8.11.6/8.11.6) with ESMTP id h5HN4YV23068; Tue, 17 Jun 2003 19:04:34 -0400 Subject: Re: Postgres Connections Requiring Large Amounts of Memory From: Dawn Hollingsworth To: Tom Lane Cc: pgsql-performance@postgresql.org, Ben Scherrey In-Reply-To: <15851.1055887425@sss.pgh.pa.us> References: <1055752337.2182.49.camel@kaos> <6634.1055796302@sss.pgh.pa.us> <1055753856.5467.57.camel@kaos> <6892.1055799269@sss.pgh.pa.us> <1055832411.5467.100.camel@kaos> <14875.1055878682@sss.pgh.pa.us> <1055842927.2182.227.camel@kaos> <15851.1055887425@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="=-FByJ//kcAEeLmRItyUAL" X-Mailer: Ximian Evolution 1.0.8 Date: 17 Jun 2003 11:03:28 +0000 Message-Id: <1055847810.2833.260.camel@kaos> Mime-Version: 1.0 X-Archive-Number: 200306/119 X-Sequence-Number: 2203 --=-FByJ//kcAEeLmRItyUAL Content-Type: text/plain Content-Transfer-Encoding: 7bit Each stored procedure only updates one row and inserts one row. I just connected the user interface to the database. It only does selects on startup. It's connection jumped to a memory usage of 256M. It's not getting any larger but it's not getting any smaller either. I'm going to compile postgres with the SHOW_MEMORY_STATS. I'm assuming I can just set ShowStats equal to 1. I'll also pare down the application to only use one of the stored procedures for less noise and maybe I can track where memory might be going. And in the meantime I'll get a test going with Postgres 7.3 to see if I get the same behavior. Any other suggestions? -Dawn On Tue, 2003-06-17 at 22:03, Tom Lane wrote: > The only theory I can come up with is that the deferred trigger list is > getting out of hand. Since you have foreign keys in all the tables, > each insert or update is going to add a trigger event to the list of > stuff to check at commit. The event entries aren't real large but they > could add up if you insert or update a lot of stuff in a single > transaction. How many rows do you process per transaction? > > regards, tom lane --=-FByJ//kcAEeLmRItyUAL Content-Type: text/html; charset=utf-8
Each stored procedure only updates one row and inserts one row.

I just connected the user interface to the database. It only does selects on startup. It's connection jumped to a memory usage of 256M.  It's not getting any larger but it's not getting any smaller either.

I'm going to compile postgres with the SHOW_MEMORY_STATS. I'm assuming I can just set ShowStats equal to 1. I'll also pare down the application to only use one of the stored procedures for less noise and maybe I can track where memory might be going. And in the meantime I'll get a test going with Postgres 7.3 to see if I get the same behavior.

Any other suggestions?

-Dawn

On Tue, 2003-06-17 at 22:03, Tom Lane wrote:
> The only theory I can come up with is that the deferred trigger list is
> getting out of hand.  Since you have foreign keys in all the tables,
> each insert or update is going to add a trigger event to the list of
> stuff to check at commit.  The event entries aren't real large but they
> could add up if you insert or update a lot of stuff in a single
> transaction.  How many rows do you process per transaction?
> 
> 			regards, tom lane

--=-FByJ//kcAEeLmRItyUAL-- From pgsql-performance-owner@postgresql.org Tue Jun 17 16:38:16 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 91DEB30EEAB for ; Tue, 17 Jun 2003 19:38:14 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 75611-04 for ; Tue, 17 Jun 2003 16:38:04 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id E1A7D30E962 for ; Tue, 17 Jun 2003 16:38:03 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5HJc2U6014876; Tue, 17 Jun 2003 15:38:02 -0400 (EDT) To: Dawn Hollingsworth Cc: pgsql-performance@postgresql.org, Ben Scherrey Subject: Re: Postgres Connections Requiring Large Amounts of Memory In-reply-to: <1055832411.5467.100.camel@kaos> References: <1055752337.2182.49.camel@kaos> <6634.1055796302@sss.pgh.pa.us> <1055753856.5467.57.camel@kaos> <6892.1055799269@sss.pgh.pa.us> <1055832411.5467.100.camel@kaos> Comments: In-reply-to Dawn Hollingsworth message dated "17 Jun 2003 06:46:48 -0000" Date: Tue, 17 Jun 2003 15:38:02 -0400 Message-ID: <14875.1055878682@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/114 X-Sequence-Number: 2198 Dawn Hollingsworth writes: > I attached gdb to a connection using just over 400MB( according to top) > and ran "MemoryContextStats(TopMemoryContext)" Hmm. This only seems to account for about 5 meg of space, which means either that lots of space is being used and released, or that the leak is coming from direct malloc calls rather than palloc. I doubt the latter though; we don't use too many direct malloc calls. On the former theory, could it be something like updating a large number of tuples in one transaction in a table with foreign keys? The pending-triggers list could have swelled up and then gone away again. The large number of SPI Plan contexts seems a tad fishy, and even more so the fact that some of them are rather large. They still only account for a couple of meg, so they aren't directly the problem, but perhaps they are related to the problem. I presume these came from either foreign-key triggers or something you've written in PL functions. Can you tell us more about what you use in that line? regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jun 17 19:04:03 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id D835C30EF3E for ; Tue, 17 Jun 2003 22:03:59 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 87352-09 for ; Tue, 17 Jun 2003 19:03:49 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 2A17030EEDB for ; Tue, 17 Jun 2003 19:03:48 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5HM3kU6015852; Tue, 17 Jun 2003 18:03:46 -0400 (EDT) To: Dawn Hollingsworth Cc: pgsql-performance@postgresql.org, Ben Scherrey Subject: Re: Postgres Connections Requiring Large Amounts of Memory In-reply-to: <1055842927.2182.227.camel@kaos> References: <1055752337.2182.49.camel@kaos> <6634.1055796302@sss.pgh.pa.us> <1055753856.5467.57.camel@kaos> <6892.1055799269@sss.pgh.pa.us> <1055832411.5467.100.camel@kaos> <14875.1055878682@sss.pgh.pa.us> <1055842927.2182.227.camel@kaos> Comments: In-reply-to Dawn Hollingsworth message dated "17 Jun 2003 09:42:07 -0000" Date: Tue, 17 Jun 2003 18:03:45 -0400 Message-ID: <15851.1055887425@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/116 X-Sequence-Number: 2200 Dawn Hollingsworth writes: > The database is used to store information for a network management > application. Almost all the Primary Keys are MACADDR or > MACADDR,TIMSTAMPTZ and the Foreign Keys are almost always on one MACADDR > column with "ON UPDATE CASCADE ON DELETE CASCADE". It's not very > complicated. I have not written any triggers of my own. > The connection I was looking at only does inserts and updates, no > deletes. All database access is made through stored procedures using > plpgsql. The stored procedures all work like: > table1( id MACADDR, ... Primary Key(id) ) > table2( id MACADDR, mytime TIMESTAMPTZ, .... Primary Key(id, mytime), > FOREIGN KEY(id) REFERENCES table1 ON UPDATE CASCADE ON DELETE CASCADE) > Update table1 > if update row count = 0 then > insert into table1 > end if > insert into table 2 > I'm not starting any of my own transactions and I'm not calling stored > procedures from withing stored procedures. The stored procedures do have > large parameters lists, up to 100. The tables are from 300 to 500 > columns. 90% of the columns are either INT4 or INT8. Some of these > tables are inherited. Could that be causing problems? The only theory I can come up with is that the deferred trigger list is getting out of hand. Since you have foreign keys in all the tables, each insert or update is going to add a trigger event to the list of stuff to check at commit. The event entries aren't real large but they could add up if you insert or update a lot of stuff in a single transaction. How many rows do you process per transaction? regards, tom lane From pgsql-general-owner@postgresql.org Thu Jun 19 13:30:27 2003 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 3099F30F286 for ; Tue, 17 Jun 2003 22:45:51 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 93892-08 for ; Tue, 17 Jun 2003 19:45:40 -0300 (ADT) Received: from c001.snv.cp.net (h021.c001.snv.cp.net [209.228.32.135]) by svr1.postgresql.org (Postfix) with SMTP id 0B53D30F13E for ; Tue, 17 Jun 2003 19:45:40 -0300 (ADT) Received: (cpmta 17391 invoked from network); 17 Jun 2003 15:45:39 -0700 Received: from 209.228.32.132 (HELO mail.dilger.cc.criticalpath.net) by smtp.register-admin.com (209.228.32.135) with SMTP; 17 Jun 2003 15:45:39 -0700 X-Sent: 17 Jun 2003 22:45:39 GMT Received: from [216.68.146.219] by mail.dilger.cc with HTTP; Tue, 17 Jun 2003 15:45:38 -0700 (PDT) Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 7bit MIME-Version: 1.0 To: ernest@vogelsinger.at Cc: pgsql-performance@postgresql.org, pgsql-general@postgresql.org From: nikolaus@dilger.cc Subject: Re: [PERFORM] Interesting incosistent query timing X-Sent-From: nikolaus@dilger.cc Date: Tue, 17 Jun 2003 15:45:38 -0700 (PDT) X-Mailer: Web Mail 5.4.0-4_sol28 Message-Id: <20030617154539.8987.h018.c001.wm@mail.dilger.cc.criticalpath.net> X-Archive-Number: 200306/1254 X-Sequence-Number: 44182 Ernest, Thanks for providing the additional information that the table has 2.3 million rows. See during the first execution you spend most of the time scanning the index id_mdata_dictid_string. And since that one is quite large it takes 1500 msec to read the index from disk into memory. For the second execution you read the large index from memory. Therfore it takes only 10 msec. Once you change the data you need to read from disk again and the query takes a long time. Regards, Nikolaus > For the first time run it executes in 1.5 - 2 seconds. > From the second > time, only 10 msec are needed for the same result: > > Unique (cost=3.84..3.84 rows=1 width=4) (actual > time=1569.36..1569.39 > rows=11 loops=1) > -> Sort (cost=3.84..3.84 rows=1 width=4) (actual > time=1569.36..1569.37 > rows=11 loops=1) > -> Index Scan using id_mdata_dictid_string on > rv2_mdata t1 > (cost=0.00..3.83 rows=1 width=4) (actual > time=17.02..1569.22 rows=11 loops=1) > Total runtime: 1569.50 msec > > > Unique (cost=3.84..3.84 rows=1 width=4) (actual > time=10.51..10.53 rows=11 > loops=1) > -> Sort (cost=3.84..3.84 rows=1 width=4) (actual > time=10.51..10.51 > rows=11 loops=1) > -> Index Scan using id_mdata_dictid_string on > rv2_mdata t1 > (cost=0.00..3.83 rows=1 width=4) (actual > time=0.60..10.43 rows=11 loops=1) > Total runtime: 10.64 msec On Tue, 17 Jun 2003 04:54:56 +0200, Ernest E Vogelsinger wrote: > > At 04:20 17.06.2003, Nikolaus Dilger said: > --------------------[snip]-------------------- > >My guess is that the second execution of the query is > >shorter since the data blocks are cached in memory. > >When you modify the data then it needs to be read again > >from disk which is much slower than from memory. The > >short execution after restarting PostgreSQL seems to > >indicate that your data is cached in the Linux buffer > >cache. > > > >The only strange thing seems to be that you have so few > >rows. Are you getting the data from a remote machine? > >How many bytes does a single row have? Are they really > >large??? > --------------------[snip]-------------------- > > What exactly do you mean? This table is quite filled > (2.3 million rows), > but the query results are correct. > > > -- > >O Ernest E. Vogelsinger > (\) ICQ #13394035 > ^ http://www.vogelsinger.at/ > > > > ---------------------------(end of > broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > > http://www.postgresql.org/docs/faqs/FAQ.html From pgsql-general-owner@postgresql.org Tue Jun 17 20:01:35 2003 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id D7BF930F108; Tue, 17 Jun 2003 23:01:31 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 04171-02; Tue, 17 Jun 2003 20:01:20 -0300 (ADT) Received: from relay11.austria.eu.net (relay11.Austria.eu.net [193.154.160.115]) by svr1.postgresql.org (Postfix) with ESMTP id F107F30EEC7; Tue, 17 Jun 2003 20:01:19 -0300 (ADT) Received: from sisyphus.vogelsinger.at (vogelsinger.at [193.154.189.26]) by relay11.austria.eu.net (8.12.9/8.12.0.Beta10) with ESMTP id h5HN1Fc8028702; Wed, 18 Jun 2003 01:01:16 +0200 Message-Id: <5.1.1.6.2.20030618005902.02e31a38@mail.vogelsinger.at> X-Sender: homebird@mail.vogelsinger.at X-Mailer: QUALCOMM Windows Eudora Version 5.1.1 Date: Wed, 18 Jun 2003 01:01:09 +0200 To: nikolaus@dilger.cc From: Ernest E Vogelsinger Subject: Re: [PERFORM] Interesting incosistent query timing Cc: pgsql-performance@postgresql.org, pgsql-general@postgresql.org In-Reply-To: <20030617154539.8987.h018.c001.wm@mail.dilger.cc.criticalpa th.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Archive-Number: 200306/1077 X-Sequence-Number: 44007 At 00:45 18.06.2003, nikolaus@dilger.cc said: --------------------[snip]-------------------- >Thanks for providing the additional information that >the table has 2.3 million rows. > >See during the first execution you spend most of the >time scanning the index id_mdata_dictid_string. And >since that one is quite large it takes 1500 msec to >read the index from disk into memory. > >For the second execution you read the large index from >memory. Therfore it takes only 10 msec. > >Once you change the data you need to read from disk >again and the query takes a long time. --------------------[snip]-------------------- I came to the same conclusion - I installed a cron script that performs a select against that index on a regular basis (3 minutes). After that even the most complex queries against this huge table go like whoosssshhh ;-) Would be interesting what one could do to _not_ have to take this basically clumsy approach... -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ From pgsql-performance-owner@postgresql.org Tue Jun 17 20:21:55 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 75EFD30EEC7 for ; Tue, 17 Jun 2003 23:21:53 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 95055-09 for ; Tue, 17 Jun 2003 20:21:43 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id CE94C30DC8A for ; Tue, 17 Jun 2003 20:21:42 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5HNLgU6017570; Tue, 17 Jun 2003 19:21:42 -0400 (EDT) To: Dawn Hollingsworth Cc: pgsql-performance@postgresql.org, Ben Scherrey Subject: Re: Postgres Connections Requiring Large Amounts of Memory In-reply-to: <1055847810.2833.260.camel@kaos> References: <1055752337.2182.49.camel@kaos> <6634.1055796302@sss.pgh.pa.us> <1055753856.5467.57.camel@kaos> <6892.1055799269@sss.pgh.pa.us> <1055832411.5467.100.camel@kaos> <14875.1055878682@sss.pgh.pa.us> <1055842927.2182.227.camel@kaos> <15851.1055887425@sss.pgh.pa.us> <1055847810.2833.260.camel@kaos> Comments: In-reply-to Dawn Hollingsworth message dated "17 Jun 2003 11:03:28 -0000" Date: Tue, 17 Jun 2003 19:21:41 -0400 Message-ID: <17569.1055892101@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/120 X-Sequence-Number: 2204 Dawn Hollingsworth writes: > I just connected the user interface to the database. It only does > selects on startup. It's connection jumped to a memory usage of 256M. > It's not getting any larger but it's not getting any smaller either. Um, are you sure that's actual memory usage? On some platforms "top" seems to count the Postgres shared memory block as part of the address space of each backend. How big is your shared memory block? (ipcs may help here) regards, tom lane From pgsql-general-owner@postgresql.org Tue Jun 17 21:12:54 2003 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 0641030F291 for ; Wed, 18 Jun 2003 00:12:31 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 15096-01 for ; Tue, 17 Jun 2003 21:12:20 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 338BA30F277 for ; Tue, 17 Jun 2003 21:12:20 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5I0CIU6017951; Tue, 17 Jun 2003 20:12:18 -0400 (EDT) To: Ernest E Vogelsinger Cc: nikolaus@dilger.cc, pgsql-performance@postgresql.org, pgsql-general@postgresql.org Subject: Re: [PERFORM] Interesting incosistent query timing In-reply-to: <5.1.1.6.2.20030618005902.02e31a38@mail.vogelsinger.at> References: <5.1.1.6.2.20030618005902.02e31a38@mail.vogelsinger.at> Comments: In-reply-to Ernest E Vogelsinger message dated "Wed, 18 Jun 2003 01:01:09 +0200" Date: Tue, 17 Jun 2003 20:12:18 -0400 Message-ID: <17950.1055895138@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/1083 X-Sequence-Number: 44013 Ernest E Vogelsinger writes: > I came to the same conclusion - I installed a cron script that performs a > select against that index on a regular basis (3 minutes). After that even > the most complex queries against this huge table go like whoosssshhh ;-) > Would be interesting what one could do to _not_ have to take this basically > clumsy approach... Seems like your kernel is falling down on the job: if those files are the most heavily used ones on the machine, it should be keeping them in disk cache without such prompting. If they are not all that heavily used, then you are basically slowing everything else down in order to speed up these queries (because you're starving everything else for disk cache). Which may be a reasonable tradeoff in your situation, but be aware of what you're doing. The best compromise may be to buy more RAM ;-) regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jun 18 04:10:43 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 37FE230F2CE for ; Wed, 18 Jun 2003 07:10:41 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 63994-07 for ; Wed, 18 Jun 2003 04:10:30 -0300 (ADT) Received: from mail.deltav.hu (oldmail.deltav.hu [213.163.0.192]) by svr1.postgresql.org (Postfix) with ESMTP id 3ABC430F2C7 for ; Wed, 18 Jun 2003 04:10:29 -0300 (ADT) Received: from fejleszt4 ([213.163.10.103]) by mail.deltav.hu (Netscape Messaging Server 3.6) with SMTP id AAA6DDA for ; Wed, 18 Jun 2003 09:10:27 +0200 Message-ID: <004a01c33568$d48235c0$0403a8c0@fejleszt4> From: "=?utf-8?B?U1rFsENTIEfDoWJvcg==?=" To: References: <1055752337.2182.49.camel@kaos> <6634.1055796302@sss.pgh.pa.us><1055753856.5467.57.camel@kaos> <6892.1055799269@sss.pgh.pa.us><1055832411.5467.100.camel@kaos> <14875.1055878682@sss.pgh.pa.us> <1055842927.2182.227.camel@kaos> Subject: Re: Postgres Connections Requiring Large Amounts of Memory Date: Wed, 18 Jun 2003 09:11:25 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Archive-Number: 200306/122 X-Sequence-Number: 2206 ----- Original Message ----- From: "Dawn Hollingsworth" Sent: Tuesday, June 17, 2003 11:42 AM > I'm not starting any of my own transactions and I'm not calling stored > procedures from withing stored procedures. The stored procedures do have > large parameters lists, up to 100. The tables are from 300 to 500 Geez! I don't think it'll help you find the memory leak (if any), but couldn't you normalize the tables to smaller ones? That may be a pain when updating (views and rules), but I think it'd worth in resources (time and memory, but maybe not disk space). I wonder what is the maximum number of updated cols and the minimum correlation between their semantics in a single transaction (i.e. one func call), since there are "only" 100 params for a proc. > columns. 90% of the columns are either INT4 or INT8. Some of these > tables are inherited. Could that be causing problems? Huh. It's still 30-50 columns (a size of a fairly large table for me) of other types :) G. ------------------------------- cut here ------------------------------- From pgsql-performance-owner@postgresql.org Wed Jun 18 11:59:22 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 3663030DBF6 for ; Wed, 18 Jun 2003 14:59:21 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 65330-06 for ; Wed, 18 Jun 2003 11:59:10 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 2303730D185 for ; Wed, 18 Jun 2003 11:59:10 -0300 (ADT) Received: (qmail 20661 invoked by uid 500); 18 Jun 2003 15:02:10 -0000 Date: Wed, 18 Jun 2003 10:02:10 -0500 From: Bruno Wolff III To: pgsql-performance@postgresql.org Subject: Recent 7.4 change slowed down a query by a factor of 3 Message-ID: <20030618150210.GA20603@wolff.to> Mail-Followup-To: pgsql-performance@postgresql.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/123 X-Sequence-Number: 2207 The query below was running in a bit under 300ms on a version of 7.4 from less than a week ago until I updated to the version from last night. Now it takes about 800ms using a significantly different plan. The query is: explain analyze select count(1) from (select distinct on (areaid) touched from crate order by areaid desc, touched desc) as current where touched >= localtimestamp + '10 year ago' group by touched >= localtimestamp + '2 year ago' order by touched >= localtimestamp + '2 year ago' desc; I don't have the earlier version of 7.4 around, but I get the better plan in 7.3.3. version ------------------------------------------------------------------------ PostgreSQL 7.4devel on i686-pc-linux-gnu, compiled by GCC egcs-2.91.66 (1 row) QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=1756.33..1756.50 rows=67 width=19) (actual time=795.64..795.65 rows=2 loops=1) Sort Key: (touched >= (('now'::text)::timestamp(6) without time zone + '-2 years'::interval)) -> HashAggregate (cost=1753.46..1754.30 rows=67 width=19) (actual time=795.48..795.48 rows=2 loops=1) -> Subquery Scan current (cost=1624.62..1737.38 rows=3216 width=19) (actual time=631.84..784.75 rows=5339 loops=1) Filter: (touched >= (('now'::text)::timestamp(6) without time zone + '-10 years'::interval)) -> Unique (cost=1624.62..1705.22 rows=3216 width=19) (actual time=631.72..713.66 rows=5364 loops=1) -> Sort (cost=1624.62..1664.92 rows=16119 width=19) (actual time=631.72..639.77 rows=16119 loops=1) Sort Key: areaid, touched -> Seq Scan on crate (cost=0.00..498.19 rows=16119 width=19) (actual time=0.02..48.85 rows=16119 loops=1) Total runtime: 800.88 msec (10 rows) Table "public.crate" Column | Type | Modifiers ---------+-----------------------------+------------------------ areaid | text | not null gameid | text | not null rate | integer | not null default 5000 frq | integer | not null default 0 opp | integer | not null default 0 rmp | integer | not null default 0 trn | integer | not null default 0 rp | text | gm | text | touched | timestamp without time zone | not null default 'now' Indexes: "crate_pkey" PRIMARY KEY btree (areaid, gameid), "crate_game" btree (gameid, areaid), "crate_touched" btree (areaid, touched) Check Constraints: "rate_nonnegative" CHECK (rate >= 0), "rate_other_interested" CHECK ((frq > 0) OR (rate = 5000)), "frq_nonnegative" CHECK (frq >= 0), "opp_nonnegative" CHECK (opp >= 0), "rmp_nonnegative" CHECK (rmp >= 0), "trn_nonnegative" CHECK (trn >= 0) Foreign Key Constraints: "bad_areaid" FOREIGN KEY (areaid) REFERENCES cname(areaid), "bad_gameid" FOREIGN KEY (gameid) REFERENCES games(gameid) version --------------------------------------------------------------------- PostgreSQL 7.3.3 on i686-pc-linux-gnu, compiled by GCC egcs-2.91.66 (1 row) QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=1094.46..1094.87 rows=161 width=19) (actual time=274.17..274.18 rows=2 loops=1) Sort Key: (touched >= (('now'::text)::timestamp(6) without time zone + '-2 years'::interval)) -> Aggregate (cost=1076.46..1088.55 rows=161 width=19) (actual time=263.78..274.09 rows=2 loops=1) -> Group (cost=1076.46..1084.52 rows=1612 width=19) (actual time=255.12..269.69 rows=5339 loops=1) -> Sort (cost=1076.46..1080.49 rows=1612 width=19) (actual time=255.11..258.09 rows=5339 loops=1) Sort Key: (touched >= (('now'::text)::timestamp(6) without time zone + '-2 years'::interval)) -> Subquery Scan current (cost=0.00..990.59 rows=1612 width=19) (actual time=0.12..240.81 rows=5339 loops=1) Filter: (touched >= (('now'::text)::timestamp(6) without time zone + '-10 years'::interval)) -> Unique (cost=0.00..990.59 rows=1612 width=19) (actual time=0.04..159.11 rows=5364 loops=1) -> Index Scan Backward using crate_touched on crate (cost=0.00..950.30 rows=16119 width=19) (actual time=0.04..82.15 rows=16119 loops=1) Total runtime: 275.32 msec (11 rows) Table "public.crate" Column | Type | Modifiers ---------+-----------------------------+------------------------ areaid | text | not null gameid | text | not null rate | integer | not null default 5000 frq | integer | not null default 0 opp | integer | not null default 0 rmp | integer | not null default 0 trn | integer | not null default 0 rp | text | gm | text | touched | timestamp without time zone | not null default 'now' Indexes: crate_pkey primary key btree (areaid, gameid), crate_game btree (gameid, areaid), crate_touched btree (areaid, touched) Check constraints: "trn_nonnegative" (trn >= 0) "rmp_nonnegative" (rmp >= 0) "opp_nonnegative" (opp >= 0) "frq_nonnegative" (frq >= 0) "rate_other_interested" ((frq > 0) OR (rate = 5000)) "rate_nonnegative" (rate >= 0) Foreign Key constraints: bad_gameid FOREIGN KEY (gameid) REFERENCES games(gameid) ON UPDATE NO ACTION ON DELETE NO ACTION, bad_areaid FOREIGN KEY (areaid) REFERENCES cname(areaid) ON UPDATE NO ACTION ON DELETE NO ACTION From pgsql-performance-owner@postgresql.org Wed Jun 18 12:18:52 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 8946B30DD24 for ; Wed, 18 Jun 2003 15:18:51 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 65396-09 for ; Wed, 18 Jun 2003 12:18:41 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id D119930DCE8 for ; Wed, 18 Jun 2003 12:18:40 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5IFIdU6021751; Wed, 18 Jun 2003 11:18:40 -0400 (EDT) To: Bruno Wolff III Cc: pgsql-performance@postgresql.org Subject: Re: Recent 7.4 change slowed down a query by a factor of 3 In-reply-to: <20030618150210.GA20603@wolff.to> References: <20030618150210.GA20603@wolff.to> Comments: In-reply-to Bruno Wolff III message dated "Wed, 18 Jun 2003 10:02:10 -0500" Date: Wed, 18 Jun 2003 11:18:39 -0400 Message-ID: <21750.1055949519@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/124 X-Sequence-Number: 2208 Bruno Wolff III writes: > The query below was running in a bit under 300ms on a version of 7.4 > from less than a week ago until I updated to the version from last night. > Now it takes about 800ms using a significantly different plan. Something fishy here. Will it use the right plan if you set enable_seqscan off? I did bogus=# create table crate(areaid text, touched timestamp); CREATE TABLE bogus=# create index crate_touched on crate(areaid, touched); CREATE INDEX and then explained your query: GroupAggregate (cost=64.14..66.48 rows=67 width=40) -> Sort (cost=64.14..64.64 rows=200 width=40) Sort Key: (touched >= (('now'::text)::timestamp(6) without time zone + '-2 years'::interval)) -> Subquery Scan current (cost=0.00..56.50 rows=200 width=40) Filter: (touched >= (('now'::text)::timestamp(6) without time zone + '-10 years'::interval)) -> Unique (cost=0.00..54.50 rows=200 width=40) -> Index Scan Backward using crate_touched on crate (cost=0.00..52.00 rows=1000 width=40) which looks perfectly reasonable. Obviously, with no data or statistics the estimates are not to be trusted, but it sure looks to me like CVS tip should still be able to generate the right plan. Did you do a full 'make clean' and rebuild when you updated? regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jun 18 12:40:44 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 5980030DD06 for ; Wed, 18 Jun 2003 15:40:43 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 73462-01 for ; Wed, 18 Jun 2003 12:40:32 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 46C5430DCE8 for ; Wed, 18 Jun 2003 12:40:32 -0300 (ADT) Received: (qmail 20948 invoked by uid 500); 18 Jun 2003 15:43:32 -0000 Date: Wed, 18 Jun 2003 10:43:32 -0500 From: Bruno Wolff III To: Tom Lane Cc: pgsql-performance@postgresql.org Subject: Re: Recent 7.4 change slowed down a query by a factor of 3 Message-ID: <20030618154332.GA20906@wolff.to> Mail-Followup-To: Tom Lane , pgsql-performance@postgresql.org References: <20030618150210.GA20603@wolff.to> <21750.1055949519@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <21750.1055949519@sss.pgh.pa.us> User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/125 X-Sequence-Number: 2209 On Wed, Jun 18, 2003 at 11:18:39 -0400, Tom Lane wrote: > Bruno Wolff III writes: > > The query below was running in a bit under 300ms on a version of 7.4 > > from less than a week ago until I updated to the version from last night. > > Now it takes about 800ms using a significantly different plan. > > Something fishy here. Will it use the right plan if you set > enable_seqscan off? > > I did > > bogus=# create table crate(areaid text, touched timestamp); > CREATE TABLE > bogus=# create index crate_touched on crate(areaid, touched); > CREATE INDEX > > and then explained your query: > > GroupAggregate (cost=64.14..66.48 rows=67 width=40) > -> Sort (cost=64.14..64.64 rows=200 width=40) > Sort Key: (touched >= (('now'::text)::timestamp(6) without time zone + '-2 years'::interval)) > -> Subquery Scan current (cost=0.00..56.50 rows=200 width=40) > Filter: (touched >= (('now'::text)::timestamp(6) without time zone + '-10 years'::interval)) > -> Unique (cost=0.00..54.50 rows=200 width=40) > -> Index Scan Backward using crate_touched on crate (cost=0.00..52.00 rows=1000 width=40) > > which looks perfectly reasonable. Obviously, with no data or statistics > the estimates are not to be trusted, but it sure looks to me like CVS > tip should still be able to generate the right plan. Did you do a full > 'make clean' and rebuild when you updated? I did a make distclean. I didn't do an initdb as I was able to restart the database without a problem. I also tried a simpler query just doing the distinct on without a where clause and the backwards index scan still wasn't used. I will try an initdb and then if that doesn't change things I will fetch a new copy of the code from CVS, do another initdb and see what happens. From pgsql-performance-owner@postgresql.org Wed Jun 18 12:42:52 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 901DD30DD0D for ; Wed, 18 Jun 2003 15:42:51 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 71662-06 for ; Wed, 18 Jun 2003 12:42:41 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id A841A30DC91 for ; Wed, 18 Jun 2003 12:42:40 -0300 (ADT) Received: (qmail 20967 invoked by uid 500); 18 Jun 2003 15:45:41 -0000 Date: Wed, 18 Jun 2003 10:45:41 -0500 From: Bruno Wolff III To: Tom Lane Cc: pgsql-performance@postgresql.org Subject: Re: Recent 7.4 change slowed down a query by a factor of 3 Message-ID: <20030618154541.GB20906@wolff.to> Mail-Followup-To: Tom Lane , pgsql-performance@postgresql.org References: <20030618150210.GA20603@wolff.to> <21750.1055949519@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <21750.1055949519@sss.pgh.pa.us> User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/126 X-Sequence-Number: 2210 On Wed, Jun 18, 2003 at 11:18:39 -0400, Tom Lane wrote: > Bruno Wolff III writes: > > The query below was running in a bit under 300ms on a version of 7.4 > > from less than a week ago until I updated to the version from last night. > > Now it takes about 800ms using a significantly different plan. > > Something fishy here. Will it use the right plan if you set > enable_seqscan off? This got it to use the backward index scan. From pgsql-performance-owner@postgresql.org Wed Jun 18 12:50:55 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1CFEC30DC47 for ; Wed, 18 Jun 2003 15:50:51 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 75359-02 for ; Wed, 18 Jun 2003 12:50:40 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 2964030D185 for ; Wed, 18 Jun 2003 12:50:40 -0300 (ADT) Received: (qmail 21258 invoked by uid 500); 18 Jun 2003 15:53:40 -0000 Date: Wed, 18 Jun 2003 10:53:40 -0500 From: Bruno Wolff III To: Tom Lane Cc: pgsql-performance@postgresql.org Subject: Re: Recent 7.4 change slowed down a query by a factor of 3 Message-ID: <20030618155340.GA21222@wolff.to> Mail-Followup-To: Tom Lane , pgsql-performance@postgresql.org References: <20030618150210.GA20603@wolff.to> <21750.1055949519@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <21750.1055949519@sss.pgh.pa.us> User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/127 X-Sequence-Number: 2211 On Wed, Jun 18, 2003 at 11:18:39 -0400, Tom Lane wrote: > Bruno Wolff III writes: > > The query below was running in a bit under 300ms on a version of 7.4 > > from less than a week ago until I updated to the version from last night. > > Now it takes about 800ms using a significantly different plan. > > Something fishy here. Will it use the right plan if you set > enable_seqscan off? After doing an initdb I got the expected plan. This is a static db used for dynamic web pages and the script that loads the db does a vacumm analyze at the end. So the db should have had the information needed to pick the correct plan. Possibly something changed that affected the information needed for planning, but the value used to indicate an initdb was needed wasn't changed. In the future if I see odd stuff I will try doing an initdb before reporting a potential problem. Thanks for your help. From pgsql-performance-owner@postgresql.org Wed Jun 18 13:21:20 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1900230DD20 for ; Wed, 18 Jun 2003 16:21:19 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 74532-06 for ; Wed, 18 Jun 2003 13:21:08 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 4E15930D185 for ; Wed, 18 Jun 2003 13:21:08 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5IGL7U6022167; Wed, 18 Jun 2003 12:21:07 -0400 (EDT) To: Bruno Wolff III Cc: pgsql-performance@postgresql.org Subject: Re: Recent 7.4 change slowed down a query by a factor of 3 In-reply-to: <20030618155340.GA21222@wolff.to> References: <20030618150210.GA20603@wolff.to> <21750.1055949519@sss.pgh.pa.us> <20030618155340.GA21222@wolff.to> Comments: In-reply-to Bruno Wolff III message dated "Wed, 18 Jun 2003 10:53:40 -0500" Date: Wed, 18 Jun 2003 12:21:07 -0400 Message-ID: <22166.1055953267@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/128 X-Sequence-Number: 2212 Bruno Wolff III writes: > After doing an initdb I got the expected plan. Hm. I'm not sure what happened there --- I don't recall that we made any initdb-needing changes in the past week or so. (If we did, we should have forced initdb by incrementing catversion, but sometimes people forget to do that.) The only change I can think of that's related at all is that the outer query's "group by foo order by foo desc" should now only require one sort step not two (which is probably why my test went for the Sort/GroupAggregate plan not the HashAgg/Sort plan you showed). But that shouldn't have affected the plan for the inner SELECT DISTINCT query, AFAICS. Odd. Probably not worth spending time on though. regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jun 20 12:53:46 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id CFE7130E71D for ; Fri, 20 Jun 2003 15:53:44 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 64786-04 for ; Fri, 20 Jun 2003 12:53:32 -0300 (ADT) Received: from imo-d01.mx.aol.com (imo-d01.mx.aol.com [205.188.157.33]) by svr1.postgresql.org (Postfix) with ESMTP id 43CDC30E7C3 for ; Fri, 20 Jun 2003 12:53:32 -0300 (ADT) Received: from yusuf0478@netscape.net by imo-d01.mx.aol.com (mail_out_v36.3.) id k.1b6.66554f1 (16238) for ; Fri, 20 Jun 2003 11:53:29 -0400 (EDT) Received: from netscape.net (66-163-11-108.ip.tor.radiant.net [66.163.11.108]) by air-in03.mx.aol.com (v94.29) with ESMTP id MAILININ32-3f6e3ef32df8216; Fri, 20 Jun 2003 11:53:29 -0400 Message-ID: <3EF32DF8.3060900@netscape.net> Date: Fri, 20 Jun 2003 11:53:28 -0400 From: Yusuf User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance Subject: Deleting one record from a table taking 17s. Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Mailer: Unknown (No Version) X-Archive-Number: 200306/129 X-Sequence-Number: 2213 Why would the following query take soo long to run? What does 28.12 msec represent, since the total running time is 16801.86 ms. The table phoneinfo has a primary key called phoneinfo_id and the table has 400 000 records. mydb=#explain analyze delete from phoneinfo where phoneinfo_id = 85723; QUERY PLAN --------------------------------------------------------------------------------------------------------------------- ----- Index Scan using phoneinfo_pkey on phoneinfo (cost=0.00..3.81 rows=1 width=6) (actual time=27.93..27.94 rows=1 loop s=1) Index Cond: (phoneinfo_id = 85723) Total runtime: 28.12 msec (3 rows) Time: 16801.86 ms BTW, I have \timing on. From pgsql-performance-owner@postgresql.org Fri Jun 20 13:06:03 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 0D95B30E670 for ; Fri, 20 Jun 2003 16:06:01 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 61593-08 for ; Fri, 20 Jun 2003 13:05:50 -0300 (ADT) Received: from mailav.tor1.inquent.com (mail.inquent.com [216.208.117.106]) by svr1.postgresql.org (Postfix) with ESMTP id 3AF9330E64F for ; Fri, 20 Jun 2003 13:05:50 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mailav.tor1.inquent.com (Postfix) with ESMTP id 9317710258; Fri, 20 Jun 2003 11:59:32 -0400 (EDT) Received: from [10.0.2.11] (unknown [10.0.2.11]) by mailav.tor1.inquent.com (Postfix) with ESMTP id 83BF510248; Fri, 20 Jun 2003 11:59:30 -0400 (EDT) Subject: Re: Deleting one record from a table taking 17s. From: Rod Taylor To: Yusuf Cc: pgsql-performance In-Reply-To: <3EF32DF8.3060900@netscape.net> References: <3EF32DF8.3060900@netscape.net> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-OuR3Jl2Wc/42gfZbc0pR" Message-Id: <1056125163.41752.31.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.0 Date: 20 Jun 2003 16:06:03 +0000 X-Virus-Scanned: by AMaViS perl-11 X-Archive-Number: 200306/130 X-Sequence-Number: 2214 --=-OuR3Jl2Wc/42gfZbc0pR Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Fri, 2003-06-20 at 15:53, Yusuf wrote: > Why would the following query take soo long to run? What does 28.12 msec = represent, since the total running time is=20 > 16801.86 ms. I'd hazard to guess that you have a whole slew of foreign keys cascading to delete, update, or check many rows from other tables. Those are not represented in the explains at the moment. --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-OuR3Jl2Wc/42gfZbc0pR Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA+8zDq6DETLow6vwwRAvudAJ94LcnXh/4xlLvrr6F6ZQ0lpeOizQCfbYYO Osy++ZWtod4D4kyWOF4+64s= =yeRL -----END PGP SIGNATURE----- --=-OuR3Jl2Wc/42gfZbc0pR-- From pgsql-performance-owner@postgresql.org Fri Jun 20 13:59:15 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id D974A30EA8D for ; Fri, 20 Jun 2003 16:59:12 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 74924-08 for ; Fri, 20 Jun 2003 13:59:02 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id C564430E871 for ; Fri, 20 Jun 2003 13:59:01 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5KGx0U6018891; Fri, 20 Jun 2003 12:59:00 -0400 (EDT) To: Rod Taylor Cc: Yusuf , pgsql-performance Subject: Re: Deleting one record from a table taking 17s. In-reply-to: <1056125163.41752.31.camel@jester> References: <3EF32DF8.3060900@netscape.net> <1056125163.41752.31.camel@jester> Comments: In-reply-to Rod Taylor message dated "20 Jun 2003 16:06:03 -0000" Date: Fri, 20 Jun 2003 12:59:00 -0400 Message-ID: <18890.1056128340@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/131 X-Sequence-Number: 2215 Rod Taylor writes: > On Fri, 2003-06-20 at 15:53, Yusuf wrote: >> Why would the following query take soo long to run? What does 28.12 msec = > represent, since the total running time is=20 >> 16801.86 ms. > I'd hazard to guess that you have a whole slew of foreign keys cascading > to delete, update, or check many rows from other tables. Either that or some other AFTER trigger(s) that are taking lots of time. Those fire after the end of the statement, so EXPLAIN's measurement of runtime fails to include them. Given that this query appears to have deleted only one row, though, you sure seem to have a mighty slow trigger. If it's an FK, perhaps you are missing an index on the referencing column? The system doesn't force you to have an index on that side of an FK, but it's generally a good idea. regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jun 20 14:07:56 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 6EF0330E68B for ; Fri, 20 Jun 2003 17:06:59 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 79425-05 for ; Fri, 20 Jun 2003 14:06:47 -0300 (ADT) Received: from imo-r01.mx.aol.com (imo-r01.mx.aol.com [152.163.225.97]) by svr1.postgresql.org (Postfix) with ESMTP id 736DC30E689 for ; Fri, 20 Jun 2003 14:06:46 -0300 (ADT) Received: from yusuf0478@netscape.net by imo-r01.mx.aol.com (mail_out_v36.3.) id k.1b0.6683956 (16237) for ; Fri, 20 Jun 2003 13:06:43 -0400 (EDT) Received: from netscape.net (66-163-11-108.ip.tor.radiant.net [66.163.11.108]) by air-in03.mx.aol.com (v94.29) with ESMTP id MAILININ31-3f6d3ef33f222ce; Fri, 20 Jun 2003 13:06:43 -0400 Message-ID: <3EF33F22.4000801@netscape.net> Date: Fri, 20 Jun 2003 13:06:42 -0400 From: Yusuf User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance Subject: Re: Deleting one record from a table taking 17s. References: <3EF32DF8.3060900@netscape.net> <1056125163.41752.31.camel@jester> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Mailer: Unknown (No Version) X-Archive-Number: 200306/132 X-Sequence-Number: 2216 rbt@rbt.ca wrote: > On Fri, 2003-06-20 at 15:53, Yusuf wrote: > >>Why would the following query take soo long to run? What does 28.12 msec represent, since the total running time is >>16801.86 ms. > > > I'd hazard to guess that you have a whole slew of foreign keys cascading > to delete, update, or check many rows from other tables. > > Those are not represented in the explains at the moment. > That's what I thought at first, so I dropped the foreign key constraints. The table is referenced by 2 tables, one of which has around 200 000 records and the other has 0 records. From pgsql-performance-owner@postgresql.org Fri Jun 20 19:04:57 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 46D6C30E590 for ; Fri, 20 Jun 2003 22:04:56 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 12046-03 for ; Fri, 20 Jun 2003 19:04:45 -0300 (ADT) Received: from tomts14-srv.bellnexxia.net (tomts14.bellnexxia.net [209.226.175.35]) by svr1.postgresql.org (Postfix) with ESMTP id 6270330EF10 for ; Fri, 20 Jun 2003 19:04:45 -0300 (ADT) Received: from [192.168.1.200] ([216.209.81.133]) by tomts14-srv.bellnexxia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20030620220440.VHYR4044.tomts14-srv.bellnexxia.net@[192.168.1.200]>; Fri, 20 Jun 2003 18:04:40 -0400 Subject: Re: Deleting one record from a table taking 17s. From: Rod Taylor To: Yusuf Cc: pgsql-performance In-Reply-To: <3EF33F22.4000801@netscape.net> References: <3EF32DF8.3060900@netscape.net> <1056125163.41752.31.camel@jester> <3EF33F22.4000801@netscape.net> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-5tSNl9yBpTZxALZSMo2S" Message-Id: <1056130147.42342.1.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.0 Date: 20 Jun 2003 18:04:56 -0400 X-Archive-Number: 200306/133 X-Sequence-Number: 2217 --=-5tSNl9yBpTZxALZSMo2S Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Fri, 2003-06-20 at 13:06, Yusuf wrote: > rbt@rbt.ca wrote: > > On Fri, 2003-06-20 at 15:53, Yusuf wrote: > >=20 > >>Why would the following query take soo long to run? What does 28.12 mse= c represent, since the total running time is=20 > >>16801.86 ms. > >=20 > >=20 > > I'd hazard to guess that you have a whole slew of foreign keys cascading > > to delete, update, or check many rows from other tables. > >=20 > > Those are not represented in the explains at the moment. > >=20 >=20 > That's what I thought at first, so I dropped the foreign key constraints.= The table is referenced by 2 tables, one of=20 > which has around 200 000 records and the other has 0 records. Hmm... EXPLAIN ANALYZE your select again, but join both of those referenced tables to the appropriate columns. --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-5tSNl9yBpTZxALZSMo2S Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA+80Rj6DETLow6vwwRAp6pAJ0aBrLk/nJt19YpEUKSCqpHLNZcMwCfVJWh Q/7rhkID3nLEj1/u6spRVSc= =svai -----END PGP SIGNATURE----- --=-5tSNl9yBpTZxALZSMo2S-- From pgsql-performance-owner@postgresql.org Mon Jun 23 03:46:52 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id EBA5F30F02D for ; Mon, 23 Jun 2003 06:46:50 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 95253-09 for ; Mon, 23 Jun 2003 03:46:40 -0300 (ADT) Received: from lewexch.lewis-stores.com (mail.lewis-stores.com [196.31.249.242]) by svr1.postgresql.org (Postfix) with ESMTP id AA19A30E64F for ; Mon, 23 Jun 2003 03:46:37 -0300 (ADT) Received: by LEWEXCH with Internet Mail Service (5.5.2653.19) id ; Mon, 23 Jun 2003 08:40:14 +0200 Message-ID: From: Howard Oblowitz To: pgsql-performance@postgresql.org Subject: Unsubscribe Date: Mon, 23 Jun 2003 08:40:09 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain X-Spam-Status: No, hits=2.9 tagged_above=0.0 required=5.0 tests=BAYES_90 X-Spam-Level: *** X-Archive-Number: 200306/134 X-Sequence-Number: 2218 Unsubscribe From pgsql-performance-owner@postgresql.org Tue Jun 24 04:39:49 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 36C2030F8A9 for ; Tue, 24 Jun 2003 07:39:43 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 54773-06 for ; Tue, 24 Jun 2003 04:39:32 -0300 (ADT) Received: from mwinf0304.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.28]) by svr1.postgresql.org (Postfix) with ESMTP id 8B0BF30F88B for ; Tue, 24 Jun 2003 04:39:29 -0300 (ADT) Received: from Paris (ABoulogne-110-1-5-194.w81-51.abo.wanadoo.fr [81.51.87.194]) by mwinf0304.wanadoo.fr (SMTP Server) with ESMTP id BA589A804123 for ; Tue, 24 Jun 2003 09:39:26 +0200 (CEST) Reply-To: From: "Michael Mattox" To: Subject: Performance advice Date: Tue, 24 Jun 2003 09:39:32 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0010_01C33A34.83D26520" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=MSGID_GOOD_EXCHANGE, RCVD_IN_UNCONFIRMED_DSBL X-Spam-Level: X-Archive-Number: 200306/135 X-Sequence-Number: 2219 This is a multi-part message in MIME format. ------=_NextPart_000_0010_01C33A34.83D26520 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit I'd like to get some feedback on my setup to see if I can optimize my database performance. My application has two separate applications: The first application connects to websites and records the statistics in the database. Websites are monitored every 5 or 10 minutes (depends on client), there are 900 monitors which comes out to 7,800 monitorings per hour. The monitor table has columns "nextdate" and "status" which are updated with every monitoring, and also a row is inserted into the status table and the status item table. For my performance testing (we're just about to go live) I've loaded the database with a month of data (we don't plan to keep data longer than 1 month). So my status table has 6 million records and my status item table has 6 million records as well. One key is that the system is multithreaded so up to 32 processes are accessing the database at the same time, updating the "nextdate" before the monitoring and inserting the status and status item records after. There is a serious performance constraint here because unlike a webserver, this application cannot slow down. If it slows down, we won't be able to monitor our sites at 5 minute intervals which will make our customers unhappy. The second application is a web app (tomcat) which lets customers check their status. Both of these applications are deployed on the same server, a 4 CPU (Xeon) with 1.5 gigs of RAM. The OS (RedHat Linux 7.3) and servers are running on 18gig 10,000 RPM SCSI disk that is mirrored to a 2nd disk. The database data directory is on a separate 36 gig 10,000 RPM SCSI disk (we're trying to buy a 2nd disk to mirror it). I'm using Postgres 7.3.2. Issue #1 - Vacuum => Overall the system runs pretty well and seems stable. Last night I did a "vacuum full analyze" and then ran my app overnight and first thing in the morning I did a "vacuum analyze", which took 35 minutes. I'm not sure if this is normal for a database this size (there are 15,000 updates per hour). During the vacuum my application does slow down quite a bit and afterwards is slow speeds back up. I've attached the vacuum output to this mail. I'm using Java Data Objects (JDO) so if table/column names look weird it's because the schema is automatically generated. Issue #2 - postgres.conf => I'd love to get some feedback on these settings. I've read the archives and no one seems to agree I know, but with the above description of my app I hope someone can at least point me in the right direction: max_connections = 200 # # Shared Memory Size # shared_buffers = 3072 # min max_connections*2 or 16, 8KB each #max_fsm_relations = 1000 # min 10, fsm is free space map, ~40 bytes #max_fsm_pages = 10000 # min 1000, fsm is free space map, ~6 bytes #max_locks_per_transaction = 64 # min 10 #wal_buffers = 8 # min 4, typically 8KB each # # Non-shared Memory Sizes # sort_mem = 8192 # min 64, size in KB vacuum_mem = 24576 # min 1024, size in KB The rest are left uncommented (using the defaults). Issue #3 - server hardware => - Is there anything I can do with the hardware to increase performance? - Should I increase the ram to 2 gigs? top shows that it is using the swap a bit (about 100k only). - I have at my disposal one other server which has 2 Xeons, 10,000 RPM SCSI drive. Would it make sense to put Postgres on it and leave my apps running on the more powerful 4 CPU server? - Would a RAID setup make the disk faster? Because top rarely shows the CPUs above 50%, I suspect maybe the disk is the bottleneck. I'm thrilled to be able to use Postgres instead of a commercial database and I'm looking forward to putting this into production. Any help with the above questions would be greatly appreciated. Michael Mattox ------=_NextPart_000_0010_01C33A34.83D26520 Content-Type: text/plain; name="vacuum.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="vacuum.txt" veriguard=3D# vacuum verbose analyze; INFO: --Relation pg_catalog.pg_description-- INFO: Pages 12: Changed 0, Empty 0; Tup 1390: Vac 0, Keep 0, UnUsed 1. Total CPU 0.01s/0.00u sec elapsed 0.00 sec. INFO: --Relation pg_toast.pg_toast_16416-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_description INFO: --Relation pg_catalog.pg_group-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: --Relation pg_toast.pg_toast_1261-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_group INFO: --Relation pg_catalog.pg_proc-- INFO: Pages 58: Changed 0, Empty 0; Tup 1492: Vac 0, Keep 0, UnUsed 165. Total CPU 0.00s/0.00u sec elapsed 0.01 sec. INFO: --Relation pg_toast.pg_toast_1255-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_proc INFO: --Relation pg_catalog.pg_rewrite-- INFO: Pages 4: Changed 0, Empty 0; Tup 29: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: --Relation pg_toast.pg_toast_16410-- INFO: Pages 4: Changed 0, Empty 0; Tup 16: Vac 0, Keep 0, UnUsed 1. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_rewrite INFO: --Relation pg_catalog.pg_type-- INFO: Pages 4: Changed 0, Empty 0; Tup 195: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_type INFO: --Relation pg_catalog.pg_attribute-- INFO: Pages 19: Changed 0, Empty 0; Tup 1131: Vac 0, Keep 0, UnUsed 2. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_attribute INFO: --Relation pg_catalog.pg_class-- INFO: Pages 4: Changed 0, Empty 0; Tup 181: Vac 0, Keep 0, UnUsed 31. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_class INFO: --Relation pg_catalog.pg_inherits-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_inherits INFO: --Relation pg_catalog.pg_index-- INFO: Pages 3: Changed 0, Empty 0; Tup 95: Vac 0, Keep 0, UnUsed 2. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_index INFO: --Relation pg_catalog.pg_operator-- INFO: Pages 13: Changed 0, Empty 0; Tup 643: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_operator INFO: --Relation pg_catalog.pg_opclass-- INFO: Pages 1: Changed 0, Empty 0; Tup 51: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_opclass INFO: --Relation pg_catalog.pg_am-- INFO: Pages 1: Changed 0, Empty 0; Tup 4: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_am INFO: --Relation pg_catalog.pg_amop-- INFO: Pages 1: Changed 0, Empty 0; Tup 180: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_amop INFO: --Relation pg_catalog.pg_amproc-- INFO: Pages 1: Changed 0, Empty 0; Tup 57: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_amproc INFO: --Relation pg_catalog.pg_language-- INFO: Pages 1: Changed 0, Empty 0; Tup 3: Vac 0, Keep 0, UnUsed 3. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_language INFO: --Relation pg_catalog.pg_largeobject-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_largeobject INFO: --Relation pg_catalog.pg_aggregate-- INFO: Pages 1: Changed 0, Empty 0; Tup 60: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_aggregate INFO: --Relation pg_catalog.pg_trigger-- INFO: Pages 1: Changed 0, Empty 0; Tup 2: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_trigger INFO: --Relation pg_catalog.pg_listener-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_listener INFO: --Relation pg_catalog.pg_cast-- INFO: Pages 2: Changed 0, Empty 0; Tup 174: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_cast INFO: --Relation pg_catalog.pg_namespace-- INFO: Pages 1: Changed 0, Empty 0; Tup 4: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_namespace INFO: --Relation pg_catalog.pg_shadow-- INFO: Pages 1: Changed 0, Empty 0; Tup 1: Vac 0, Keep 0, UnUsed 1. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: --Relation pg_toast.pg_toast_1260-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_shadow INFO: --Relation pg_catalog.pg_conversion-- INFO: Pages 2: Changed 0, Empty 0; Tup 114: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_conversion INFO: --Relation pg_catalog.pg_depend-- INFO: Pages 21: Changed 0, Empty 0; Tup 2905: Vac 0, Keep 0, UnUsed 2. Total CPU 0.00s/0.00u sec elapsed 0.01 sec. INFO: Analyzing pg_catalog.pg_depend INFO: --Relation pg_catalog.pg_attrdef-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: --Relation pg_toast.pg_toast_16384-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_attrdef INFO: --Relation pg_catalog.pg_constraint-- INFO: Pages 1: Changed 0, Empty 0; Tup 10: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: --Relation pg_toast.pg_toast_16386-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_constraint INFO: --Relation pg_catalog.pg_database-- INFO: Pages 1: Changed 0, Empty 0; Tup 3: Vac 0, Keep 0, UnUsed 4. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: --Relation pg_toast.pg_toast_1262-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing pg_catalog.pg_database INFO: --Relation public.companycontactx-- INFO: Pages 14: Changed 0, Empty 0; Tup 586: Vac 0, Keep 0, UnUsed 1. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: --Relation pg_toast.pg_toast_17030-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing public.companycontactx INFO: --Relation public.jdo_sequencex-- INFO: Index jdo_sequencex_pkey: Pages 1027; Tuples 1: Deleted 5124. CPU 0.01s/0.03u sec elapsed 0.04 sec. INFO: Removed 5124 tuples in 28 pages. CPU 0.00s/0.01u sec elapsed 0.00 sec. INFO: Pages 28: Changed 1, Empty 0; Tup 1: Vac 5124, Keep 0, UnUsed 0. Total CPU 0.01s/0.04u sec elapsed 0.04 sec. INFO: Analyzing public.jdo_sequencex INFO: --Relation public.monitorstatusx-- INFO: Index monitorstatusx_pkey: Pages 24449; Tuples 6398745: Deleted 148. CPU 1.75s/1.92u sec elapsed 98.39 sec. INFO: Index monitorstatusxmonitori: Pages 22378; Tuples 6399034: Deleted = 148. CPU 3.63s/3.09u sec elapsed 206.76 sec. INFO: Removed 148 tuples in 109 pages. CPU 0.02s/0.02u sec elapsed 1.39 sec. INFO: Pages 136706: Changed 151, Empty 0; Tup 6398610: Vac 148, Keep 0, Un= Used 6. Total CPU 12.60s/6.74u sec elapsed 382.70 sec. INFO: --Relation pg_toast.pg_toast_16995-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing public.monitorstatusx INFO: --Relation public.monitorgroup_monitorsx-- INFO: Pages 10: Changed 0, Empty 0; Tup 1489: Vac 0, Keep 0, UnUsed 61. Total CPU 0.01s/0.00u sec elapsed 0.03 sec. INFO: Analyzing public.monitorgroup_monitorsx INFO: --Relation pg_catalog.pg_statistic-- INFO: Index pg_statistic_relid_att_index: Pages 4; Tuples 254: Deleted 395. CPU 0.01s/0.01u sec elapsed 0.12 sec. INFO: Removed 395 tuples in 15 pages. CPU 0.00s/0.00u sec elapsed 0.15 sec. INFO: Pages 22: Changed 20, Empty 0; Tup 254: Vac 395, Keep 13, UnUsed 107. Total CPU 0.01s/0.01u sec elapsed 0.37 sec. INFO: --Relation pg_toast.pg_toast_16408-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: --Relation public.monitorx-- INFO: Index monitorx_pkey: Pages 1194; Tuples 2213: Deleted 170055. CPU 1.16s/2.86u sec elapsed 58.16 sec. INFO: Index monitorxstatusi: Pages 3845; Tuples 2862: Deleted 170055. CPU 1.53s/3.49u sec elapsed 78.64 sec. INFO: Index monitorx_id_index: Pages 4187; Tuples 3070: Deleted 170055. CPU 1.59s/3.11u sec elapsed 72.21 sec. INFO: Index monitorx_nextdate_enabled_index: Pages 1070; Tuples 3720: Dele= ted 170055. CPU 1.27s/2.79u sec elapsed 68.05 sec. INFO: Removed 170055 tuples in 6036 pages. CPU 0.52s/0.81u sec elapsed 206.26 sec. INFO: Pages 6076: Changed 0, Empty 0; Tup 2057: Vac 170055, Keep 568, UnUs= ed 356. Total CPU 6.28s/13.23u sec elapsed 486.07 sec. INFO: --Relation pg_toast.pg_toast_17006-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing public.monitorx INFO: --Relation public.monitor_monitorlocationsx-- INFO: Pages 14: Changed 0, Empty 0; Tup 2073: Vac 0, Keep 0, UnUsed 2. Total CPU 0.00s/0.01u sec elapsed 0.00 sec. INFO: Analyzing public.monitor_monitorlocationsx INFO: --Relation public.monitorgroupx-- INFO: Pages 14: Changed 0, Empty 0; Tup 586: Vac 0, Keep 0, UnUsed 21. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing public.monitorgroupx INFO: --Relation public.customeraccountx-- INFO: Pages 14: Changed 0, Empty 0; Tup 586: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: --Relation pg_toast.pg_toast_17044-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing public.customeraccountx INFO: --Relation public.monitorstatusitemx-- INFO: Index monitorstatusitemx_pkey: Pages 24459; Tuples 6401221: Deleted = 165. CPU 1.69s/1.97u sec elapsed 63.83 sec. INFO: Removed 165 tuples in 125 pages. CPU 0.05s/0.05u sec elapsed 1.34 sec. INFO: Pages 145514: Changed 2021, Empty 0; Tup 6401160: Vac 165, Keep 0, U= nUsed 6. Total CPU 7.98s/3.23u sec elapsed 153.89 sec. INFO: --Relation pg_toast.pg_toast_17037-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing public.monitorstatusitemx INFO: --Relation public.addressx-- INFO: Pages 10: Changed 0, Empty 0; Tup 586: Vac 0, Keep 0, UnUsed 0. Total CPU 0.01s/0.00u sec elapsed 0.09 sec. INFO: --Relation pg_toast.pg_toast_17014-- INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing public.addressx INFO: --Relation public.monitorstatusitemlistx-- INFO: Index monitorstatusitemlistx_pkey: Pages 24464; Tuples 6402415: Del= eted 181. CPU 1.62s/2.11u sec elapsed 93.29 sec. INFO: Removed 181 tuples in 129 pages. CPU 0.01s/0.03u sec elapsed 1.86 sec. INFO: Pages 101654: Changed 1442, Empty 0; Tup 6402153: Vac 181, Keep 0, U= nUsed 5. Total CPU 9.87s/4.87u sec elapsed 291.93 sec. INFO: Analyzing public.monitorstatusitemlistx INFO: --Relation public.companyx-- INFO: Pages 10: Changed 0, Empty 0; Tup 586: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Analyzing public.companyx INFO: --Relation public.monitorstatusitemlistd8ea58a5x-- INFO: Index monitorstatusitejdoid7db0befci: Pages 24470; Tuples 6403200: D= eleted 175. CPU 1.96s/2.07u sec elapsed 97.15 sec. INFO: Index monitorstatusitemlist6fe47957i: Pages 24470; Tuples 6403333: = Deleted 175. CPU 1.51s/1.77u sec elapsed 92.20 sec. INFO: Removed 175 tuples in 100 pages. CPU 0.04s/0.04u sec elapsed 2.25 sec. INFO: Pages 37703: Changed 570, Empty 0; Tup 6403027: Vac 175, Keep 0, UnU= sed 8. Total CPU 6.58s/5.15u sec elapsed 262.83 sec. INFO: Analyzing public.monitorstatusitemlistd8ea58a5x INFO: --Relation public.monitorstatus_statusitemsx-- INFO: Index monitorstatus_stjdoidb742c9b3i: Pages 24475; Tuples 6403913: = Deleted 175. CPU 1.80s/2.12u sec elapsed 109.54 sec. INFO: Index monitorstatus_stitemsa2bb7ff1i: Pages 24475; Tuples 6404057: D= eleted 175. CPU 1.72s/1.95u sec elapsed 107.31 sec. INFO: Removed 175 tuples in 107 pages. CPU 0.01s/0.02u sec elapsed 1.82 sec. INFO: Pages 47124: Changed 701, Empty 0; Tup 6403754: Vac 175, Keep 0, UnU= sed 6. Total CPU 6.85s/5.14u sec elapsed 298.35 sec. INFO: Analyzing public.monitorstatus_statusitemsx INFO: --Relation public.companycontact_rncies9688bceax-- INFO: Pages 1: Changed 0, Empty 0; Tup 4: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.04 sec. INFO: Analyzing public.companycontact_rncies9688bceax VACUUM veriguard=3D#=20=20=20=20=20=20=20=20=20=20 ------=_NextPart_000_0010_01C33A34.83D26520-- From pgsql-performance-owner@postgresql.org Tue Jun 24 05:00:09 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 38D8830F801 for ; Tue, 24 Jun 2003 08:00:07 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 58005-06 for ; Tue, 24 Jun 2003 04:59:56 -0300 (ADT) Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id D03DA30F7A0 for ; Tue, 24 Jun 2003 04:59:54 -0300 (ADT) Received: (from root@localhost) by www.pspl.co.in (8.11.6/8.11.6) id h5O7xsn18434 for ; Tue, 24 Jun 2003 13:29:54 +0530 Received: from daithan (daithan.intranet.pspl.co.in [192.168.7.161]) by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h5O7xrH18423 for ; Tue, 24 Jun 2003 13:29:54 +0530 From: "Shridhar Daithankar" To: Date: Tue, 24 Jun 2003 13:29:08 +0530 MIME-Version: 1.0 Subject: Re: Performance advice Reply-To: shridhar_daithankar@persistent.co.in Message-ID: <3EF85224.1633.3939548@localhost> In-reply-to: X-mailer: Pegasus Mail for Windows (v4.02) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Archive-Number: 200306/136 X-Sequence-Number: 2220 On 24 Jun 2003 at 9:39, Michael Mattox wrote: > I'd like to get some feedback on my setup to see if I can optimize my > database performance. My application has two separate applications: > > The first application connects to websites and records the statistics in the > database. Websites are monitored every 5 or 10 minutes (depends on client), > there are 900 monitors which comes out to 7,800 monitorings per hour. The > monitor table has columns "nextdate" and "status" which are updated with > every monitoring, and also a row is inserted into the status table and the > status item table. For my performance testing (we're just about to go live) > I've loaded the database with a month of data (we don't plan to keep data > longer than 1 month). So my status table has 6 million records and my > status item table has 6 million records as well. One key is that the system > is multithreaded so up to 32 processes are accessing the database at the > same time, updating the "nextdate" before the monitoring and inserting the > status and status item records after. There is a serious performance > constraint here because unlike a webserver, this application cannot slow > down. If it slows down, we won't be able to monitor our sites at 5 minute > intervals which will make our customers unhappy. > > The second application is a web app (tomcat) which lets customers check > their status. Both of these applications are deployed on the same server, a > 4 CPU (Xeon) with 1.5 gigs of RAM. The OS (RedHat Linux 7.3) and servers > are running on 18gig 10,000 RPM SCSI disk that is mirrored to a 2nd disk. > The database data directory is on a separate 36 gig 10,000 RPM SCSI disk > (we're trying to buy a 2nd disk to mirror it). I'm using Postgres 7.3.2. I recommend that you use a latest kernel with, pre-empt+low latency + O(1) patches. First two are said to affect desktop only, but I believe a loaded server need it as well. I suggest you get latest kernel from kernel.org and apply con kolivas's patches from http://members.optusnet.com.au/ckolivas/kernel/. That is the easiest way around. Furthermore if I/O throghput is an issue and you aer ready to experiment at this stage, try freeBSD. Many out here believe that it has superior IO scheduling and of course VM. If you move off your database server to another machine, you might get a chance to play with it. > Issue #1 - Vacuum => Overall the system runs pretty well and seems stable. > Last night I did a "vacuum full analyze" and then ran my app overnight and > first thing in the morning I did a "vacuum analyze", which took 35 minutes. > I'm not sure if this is normal for a database this size (there are 15,000 > updates per hour). During the vacuum my application does slow down quite a > bit and afterwards is slow speeds back up. I've attached the vacuum output > to this mail. I'm using Java Data Objects (JDO) so if table/column names > look weird it's because the schema is automatically generated. That is expected given how much data you have inserted overnight. The changes in status and status item table would need some time to come back. Vacuum is IO intensive process. In case of freeBSD, if you lower the nice priority, IO priority is also lowered. That mean a vacuum process with lower priority will not hog disk bandwidth on freeBSD. Unfortunately not so on linux. So the slowdown you are seeing is probably due to disk bandwidth congestion. Clearly with a load like this, you can not rely upon scheduled vacuums. I recommend you use pgavd in contrib directory in postgresql CVS tree. That would vacuum the database whenever needed. It's much better than scheduled vacuum. If you can not use it immediately, do a hourly vacuum analyze, may be even more frequent. Nightly vacuum would simply not do. > > Issue #2 - postgres.conf => I'd love to get some feedback on these settings. > I've read the archives and no one seems to agree I know, but with the above > description of my app I hope someone can at least point me in the right > direction: > > max_connections = 200 > > # > # Shared Memory Size > # > shared_buffers = 3072 # min max_connections*2 or 16, 8KB each I would say of the order of 10K would be good. You need to experiment a bit to find out what works best for you. > #max_fsm_relations = 1000 # min 10, fsm is free space map, ~40 bytes > #max_fsm_pages = 10000 # min 1000, fsm is free space map, ~6 bytes You may bump these two as well. See past discussions for reference. Doubling them would be a good start. > #max_locks_per_transaction = 64 # min 10 > #wal_buffers = 8 # min 4, typically 8KB each > > # > # Non-shared Memory Sizes > # > sort_mem = 8192 # min 64, size in KB > vacuum_mem = 24576 # min 1024, size in KB > > The rest are left uncommented (using the defaults). Not good. You need to tune effective_cache_size so that postgresql accounts for 1.5GB RAM your machine has. I would say set it up around 800MB. Secondly with SCSI in place, lower random_tuple_cost. Default is 4. 1 might be too agrressive. 2 might be OK. Experiment and decide. > > Issue #3 - server hardware => > > - Is there anything I can do with the hardware to increase performance? > > - Should I increase the ram to 2 gigs? top shows that it is using the swap > a bit (about 100k only). Means it does not need swap almost at all. Linux has habit to touch swap just for no reason. So memory is not the bottleneck. > - I have at my disposal one other server which has 2 Xeons, 10,000 RPM SCSI > drive. Would it make sense to put Postgres on it and leave my apps running > on the more powerful 4 CPU server? > > - Would a RAID setup make the disk faster? Because top rarely shows the > CPUs above 50%, I suspect maybe the disk is the bottleneck. Yes it is. You need to move WAL to a different disk. Even if it is IDE. (OK that was over exaggeration but you got the point). If your data directories and WAL logs are on physically different disks, that should bump up performance plenty. HTH Bye Shridhar -- Ambidextrous, adj.: Able to pick with equal skill a right-hand pocket or a left. -- Ambrose Bierce, "The Devil's Dictionary" From pgsql-performance-owner@postgresql.org Tue Jun 24 05:20:53 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1FC5730F89A for ; Tue, 24 Jun 2003 08:20:52 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 59944-05 for ; Tue, 24 Jun 2003 05:20:41 -0300 (ADT) Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id 0DF1830F7A0 for ; Tue, 24 Jun 2003 05:20:40 -0300 (ADT) Received: (from root@localhost) by www.pspl.co.in (8.11.6/8.11.6) id h5O8Kdt22612 for ; Tue, 24 Jun 2003 13:50:39 +0530 Received: from daithan (daithan.intranet.pspl.co.in [192.168.7.161]) by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h5O8KdH22607 for ; Tue, 24 Jun 2003 13:50:39 +0530 From: "Shridhar Daithankar" To: Date: Tue, 24 Jun 2003 13:49:54 +0530 MIME-Version: 1.0 Subject: Re: Performance advice Reply-To: shridhar_daithankar@persistent.co.in Message-ID: <3EF85702.30194.3A69859@localhost> In-reply-to: <3EF85224.1633.3939548@localhost> References: X-mailer: Pegasus Mail for Windows (v4.02) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Archive-Number: 200306/137 X-Sequence-Number: 2221 On 24 Jun 2003 at 13:29, Shridhar Daithankar wrote: > > - I have at my disposal one other server which has 2 Xeons, 10,000 RPM SCSI > > drive. Would it make sense to put Postgres on it and leave my apps running > > on the more powerful 4 CPU server? Argh.. Forgot it first time. With java runnning on same machine, I would not trust that machine for having free RAM all the time, no matter how much RAM you have put into it. Secondly you are running linux which is known to have weird behaviour problems when it runs low on memory. For both these reasons, I suggest you put your database on another machine. A dual CPU machine is more than enough. Put good deal RAM, around a GB and two SCSI disks, one for data and another for WAL. If you get RAID for data, great. But that should suffice otherwise as well. > > > > - Would a RAID setup make the disk faster? Because top rarely shows the > > CPUs above 50%, I suspect maybe the disk is the bottleneck. > > Yes it is. You need to move WAL to a different disk. Even if it is IDE. (OK > that was over exaggeration but you got the point). If your data directories and > WAL logs are on physically different disks, that should bump up performance > plenty. In addition to that, on linux, it matters a lot as in what filesystem you use. IMO ext3 is strict no-no. Go for either reiserfs or XFS. There is no agreement as in which file system is best on linux. so you need to experiment if you need every ounce of performance. And for that you got to try freeBSD. That would gave you plenty of idea about performance differences. ( Especially I love man hier and man tuning on freeBSD. Nothing on linux comes anywhere near to that) Bye Shridhar -- "Who is General Failure and why is he reading my hard disk ?"Microsoft spel chekar vor sail, worgs grate !!(By leitner@inf.fu-berlin.de, Felix von Leitner) From pgsql-performance-owner@postgresql.org Tue Jun 24 06:03:47 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id AC20D30F89A for ; Tue, 24 Jun 2003 09:03:44 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 58020-10 for ; Tue, 24 Jun 2003 06:03:34 -0300 (ADT) Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id 6593330F7A0 for ; Tue, 24 Jun 2003 06:03:32 -0300 (ADT) Received: (from root@localhost) by www.pspl.co.in (8.11.6/8.11.6) id h5O93WN31571 for ; Tue, 24 Jun 2003 14:33:32 +0530 Received: from daithan (daithan.intranet.pspl.co.in [192.168.7.161]) by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h5O93VH31566 for ; Tue, 24 Jun 2003 14:33:32 +0530 From: "Shridhar Daithankar" To: pgsql-performance@postgresql.org Date: Tue, 24 Jun 2003 14:32:46 +0530 MIME-Version: 1.0 Subject: Re: Performance advice Reply-To: shridhar_daithankar@persistent.co.in Message-ID: <3EF8610E.14606.3CDD813@localhost> References: <3EF85702.30194.3A69859@localhost> In-reply-to: X-mailer: Pegasus Mail for Windows (v4.02) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Archive-Number: 200306/139 X-Sequence-Number: 2223 On 24 Jun 2003 at 12:10, Achilleus Mantzios wrote: > On Tue, 24 Jun 2003, Shridhar Daithankar wrote: > > With java runnning on same machine, I would not trust that machine for having > > free RAM all the time, no matter how much RAM you have put into it. > > There are always the -Xmx, -Xss, -Xms jvm switches, > to control stack (per thread) and heap sizes. OK. I am not familiar with any of them. Are they related to java? Have never worked on java myself. I was talking about OOM killer behaviour, which was beaten to death for last few days.. > > For both these reasons, I suggest you put your database on another machine. A > > dual CPU machine is more than enough. Put good deal RAM, around a GB and two > > SCSI disks, one for data and another for WAL. If you get RAID for data, great. > > But that should suffice otherwise as well. > > > > I think the DB on another machine could be from something helpfull, > to an overkill, to a leg self shooting. > Depending on the type of the majority of queries and the network speed > someone should give an extra time to think about it. I agree. but with the input provided, I think that remains as viable option. > > And for that you got to try freeBSD. That would gave you plenty of idea about > > performance differences. ( Especially I love man hier and man tuning on > > freeBSD. Nothing on linux comes anywhere near to that) > > > > Its like comparing Mazda with VVT-i. What are they? My guess is they are cars., Anyway, I drive a tiny utility bike in far country like India..:-) > Whould you expect to find the furniture fabric > specs in the main engine manual? Well, I agree they are different but not that much..:-) And besides man tuning is much more helpful w.r.t. tuning a box. I still think it is relevant. and that was just one example why freeBSD is better server OS, out of the box, compared to linux. No flame wars.. Peace.. Bye Shridhar -- Lieberman's Law: Everybody lies, but it doesn't matter since nobody listens. From pgsql-performance-owner@postgresql.org Tue Jun 24 08:33:58 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 6763730F8F7 for ; Tue, 24 Jun 2003 11:33:57 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 02144-07 for ; Tue, 24 Jun 2003 08:33:46 -0300 (ADT) Received: from anchor-post-31.mail.demon.net (anchor-post-31.mail.demon.net [194.217.242.89]) by svr1.postgresql.org (Postfix) with ESMTP id 503D530F722 for ; Tue, 24 Jun 2003 08:33:46 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-31.mail.demon.net with esmtp (Exim 3.35 #1) id 19Um3V-00026i-0V; Tue, 24 Jun 2003 12:33:46 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 3E27217464; Tue, 24 Jun 2003 12:33:45 +0100 (BST) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 9534717454; Tue, 24 Jun 2003 12:33:44 +0100 (BST) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: , Subject: Re: Performance advice Date: Tue, 24 Jun 2003 12:33:42 +0100 User-Agent: KMail/1.4.3 References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200306241233.42361.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Archive-Number: 200306/140 X-Sequence-Number: 2224 On Tuesday 24 Jun 2003 8:39 am, Michael Mattox wrote: > I'd like to get some feedback on my setup to see if I can optimize my > database performance. My application has two separate applications: > > The first application connects to websites and records the statistics in > the database. Websites are monitored every 5 or 10 minutes (depends on > client), there are 900 monitors which comes out to 7,800 monitorings per > hour.=20=20 [snip] > There is a serious > performance constraint here because unlike a webserver, this application > cannot slow down. If it slows down, we won't be able to monitor our sites > at 5 minute intervals which will make our customers unhappy. Others are discussing the performance/tuning stuff, but can I make one=20 suggestion? Don't log your monitoring info directly into the database, log straight to = one=20 or more text-files and sync them every few seconds. Rotate the files once a= =20 minute (or whatever seems suitable). Then have a separate process that read= s=20 "old" files and processes them into the database. The big advantage - you can take the database down for a short period and t= he=20 monitoring goes on. Useful for those small maintenance tasks. --=20 Richard Huxton From pgsql-performance-owner@postgresql.org Tue Jun 24 09:16:18 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1B31E30F644 for ; Tue, 24 Jun 2003 12:16:17 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 99173-08 for ; Tue, 24 Jun 2003 09:16:06 -0300 (ADT) Received: from mwinf0302.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.28]) by svr1.postgresql.org (Postfix) with ESMTP id 2E92A30F684 for ; Tue, 24 Jun 2003 09:16:06 -0300 (ADT) Received: from Paris (unknown [81.49.7.47]) by mwinf0302.wanadoo.fr (SMTP Server) with ESMTP id 30CD5C0002C1; Tue, 24 Jun 2003 14:16:03 +0200 (CEST) Reply-To: From: "Michael Mattox" To: "Richard Huxton" , Subject: Re: Performance advice Date: Tue, 24 Jun 2003 14:16:09 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) In-Reply-To: <200306241233.42361.dev@archonet.com> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal X-Archive-Number: 200306/141 X-Sequence-Number: 2225 > Don't log your monitoring info directly into the database, log > straight to one > or more text-files and sync them every few seconds. Rotate the > files once a > minute (or whatever seems suitable). Then have a separate process > that reads > "old" files and processes them into the database. > > The big advantage - you can take the database down for a short > period and the > monitoring goes on. Useful for those small maintenance tasks. This is a good idea but it'd take a bit of redesign to make it work. here's my algorithm now: - Every 10 seconds I get a list of monitors who have nextdate >= current time - I put the id numbers of the monitors into a queue - A thread from a thread pool (32 active threads) retrieves the monitor from the database from its id, updates the nextdate timestamp, executes the monitor, and stores the status in the database So I have two transactions, one to update the monitor's nextdate and another to update its status. Now that I wrote that I see a possibility to steamline the last step. I can wait until I update the status to update the nextdate. That would cut the number of transactions in two. Only problem is I have to be sure not to add a monitor to the queue when it's currently executing. This shouldn't be hard, I have a hashtable containing all the active monitors. Thanks for the suggestion, I'm definitely going to give this some more thought. Michael From pgsql-performance-owner@postgresql.org Tue Jun 24 05:54:50 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 84D6A30F8C5 for ; Tue, 24 Jun 2003 08:54:47 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 59380-09 for ; Tue, 24 Jun 2003 05:54:37 -0300 (ADT) Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) by svr1.postgresql.org (Postfix) with ESMTP id C7BF830F8BF for ; Tue, 24 Jun 2003 05:54:35 -0300 (ADT) Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h5OEAnEP010809; Tue, 24 Jun 2003 12:10:54 -0200 Received: from localhost (achill@localhost) by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id h5OEAmsP010805; Tue, 24 Jun 2003 12:10:48 -0200 Date: Tue, 24 Jun 2003 12:10:48 -0200 (GMT+2) From: Achilleus Mantzios To: Shridhar Daithankar Cc: pgsql-performance@postgresql.org Subject: Re: Performance advice In-Reply-To: <3EF85702.30194.3A69859@localhost> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200306/138 X-Sequence-Number: 2222 On Tue, 24 Jun 2003, Shridhar Daithankar wrote: > On 24 Jun 2003 at 13:29, Shridhar Daithankar wrote: > > > - I have at my disposal one other server which has 2 Xeons, 10,000 RPM SCSI > > > drive. Would it make sense to put Postgres on it and leave my apps running > > > on the more powerful 4 CPU server? > > Argh.. Forgot it first time. > > With java runnning on same machine, I would not trust that machine for having > free RAM all the time, no matter how much RAM you have put into it. There are always the -Xmx, -Xss, -Xms jvm switches, to control stack (per thread) and heap sizes. > > Secondly you are running linux which is known to have weird behaviour problems > when it runs low on memory. > > For both these reasons, I suggest you put your database on another machine. A > dual CPU machine is more than enough. Put good deal RAM, around a GB and two > SCSI disks, one for data and another for WAL. If you get RAID for data, great. > But that should suffice otherwise as well. > I think the DB on another machine could be from something helpfull, to an overkill, to a leg self shooting. Depending on the type of the majority of queries and the network speed someone should give an extra time to think about it. > > > > > > - Would a RAID setup make the disk faster? Because top rarely shows the > > > CPUs above 50%, I suspect maybe the disk is the bottleneck. > > > > Yes it is. You need to move WAL to a different disk. Even if it is IDE. (OK > > that was over exaggeration but you got the point). If your data directories and > > WAL logs are on physically different disks, that should bump up performance > > plenty. > > In addition to that, on linux, it matters a lot as in what filesystem you use. > IMO ext3 is strict no-no. Go for either reiserfs or XFS. > > There is no agreement as in which file system is best on linux. so you need to > experiment if you need every ounce of performance. > > And for that you got to try freeBSD. That would gave you plenty of idea about > performance differences. ( Especially I love man hier and man tuning on > freeBSD. Nothing on linux comes anywhere near to that) > Its like comparing Mazda with VVT-i. Whould you expect to find the furniture fabric specs in the main engine manual? Besides all that, i must note that jdk1.4.1 runs pretty nice on FreeBSD, and some efforts to run java over the KSE libs have been done with success. > Bye > Shridhar > > -- > "Who is General Failure and why is he reading my hard disk ?"Microsoft spel > chekar vor sail, worgs grate !!(By leitner@inf.fu-berlin.de, Felix von Leitner) > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html > -- ================================================================== Achilleus Mantzios S/W Engineer IT dept Dynacom Tankers Mngmt Nikis 4, Glyfada Athens 16610 Greece tel: +30-210-8981112 fax: +30-210-8981877 email: achill at matrix dot gatewaynet dot com mantzios at softlab dot ece dot ntua dot gr From pgsql-performance-owner@postgresql.org Tue Jun 24 11:19:18 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id AB21730F74D for ; Tue, 24 Jun 2003 14:19:17 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 18683-10 for ; Tue, 24 Jun 2003 11:19:07 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id E634430F949 for ; Tue, 24 Jun 2003 11:19:06 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5OEIvQQ019142; Tue, 24 Jun 2003 10:18:57 -0400 (EDT) To: shridhar_daithankar@persistent.co.in Cc: pgsql-performance@postgresql.org Subject: Re: Performance advice In-reply-to: <3EF85224.1633.3939548@localhost> References: <3EF85224.1633.3939548@localhost> Comments: In-reply-to "Shridhar Daithankar" message dated "Tue, 24 Jun 2003 13:29:08 +0530" Date: Tue, 24 Jun 2003 10:18:57 -0400 Message-ID: <19141.1056464337@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/142 X-Sequence-Number: 2226 "Shridhar Daithankar" writes: >> - Would a RAID setup make the disk faster? Because top rarely shows the >> CPUs above 50%, I suspect maybe the disk is the bottleneck. > Yes it is. You need to move WAL to a different disk. For an update-intensive setup, putting WAL on its own disk is definitely your biggest win. You might then find it rewarding to fool with the wal_sync_method and perhaps to bump up wal_buffers a little. A small number of people have had luck with putting a nonzero commit_delay but I have little faith in that. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jun 24 12:47:51 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id D53CD30F95E for ; Tue, 24 Jun 2003 15:47:49 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 34583-03 for ; Tue, 24 Jun 2003 12:47:39 -0300 (ADT) Received: from mwinf0301.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.28]) by svr1.postgresql.org (Postfix) with ESMTP id 8B13F30F799 for ; Tue, 24 Jun 2003 12:47:38 -0300 (ADT) Received: from Paris (unknown [81.49.7.47]) by mwinf0301.wanadoo.fr (SMTP Server) with ESMTP id D7409400883 for ; Tue, 24 Jun 2003 17:47:31 +0200 (CEST) Reply-To: From: "Michael Mattox" To: Subject: Re: Performance advice Date: Tue, 24 Jun 2003 17:47:38 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0031_01C33A78.B41C5CB0" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal X-Archive-Number: 200306/143 X-Sequence-Number: 2227 This is a multi-part message in MIME format. ------=_NextPart_000_0031_01C33A78.B41C5CB0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit I want to thank everyone for their help and post a status update. I've made quite a bit of improvements. Here's what all I did: I refactored my algorithm, instead of updating the timestamp, monitoring the website, and then updating the status (two transactions), I wait and update the timestamp and status at the same time (one transaction). This required using a hashtable to contain active monitors so that I don't add a monitor to the queue while it's executing (I check to make sure it's not in the queue and not executing before adding it to the queue). This cut down my transactions by a factor of 2. I changed the postgres.conf settings as suggested by several people. I've attached it to this email, please let me know if you see anything else I can tweak. top still says I have plenty of ram, so should I increase the buffers and/or effective_cache even more? Mem: 1547572K av, 1537212K used, 10360K free, 0K shrd, 107028K buff Swap: 1044216K av, 14552K used, 1029664K free 1192280K cached I moved the WAL (pg_xlog directory) to another drive. There are two drives in the system, so one has the OS, servers, all files, and the WAL and the other has nothing but the data. I think it'd be best to put the WAL on a separate drive from the OS but I don't know if I can get another drive added just for that due to our limited budget. I learned that I only need to vacuum tables that are changed frequently. My app doesn't do any deletes, and only one table changes, the monitor table. several times a second. So I only need to vacuum that table. Vacuuming the entire database is slow and unecessary. If I only do the monitor table, it takes only a few seconds. Much better than the 35 minutes for the entire database that it was taking this morning. Result of all this? Before a monitor operation (update timestamp, download webpage, update status) was taking 5-6 seconds each, and up to a minute during a vacuum. Now it takes less than 1 second. Part of this is because I can run 8 threads instead of 32 due to the other optimizations. I want to thank everyone for their input. I've heard Postgres is slow and doesn't scale, but now I do it's really just a matter of learning to configure it properly and trial & error. I do think the documentation could be enhanced a bit here, but I'm sure there are some users who don't make this effort and end up switching to another database, which is bad for Postgres' image. Anyway, I hope my summary can help others who may find this email in the archives. Regards, Michael > -----Original Message----- > From: pgsql-performance-owner@postgresql.org > [mailto:pgsql-performance-owner@postgresql.org]On Behalf Of Michael > Mattox > Sent: Tuesday, June 24, 2003 9:40 AM > To: pgsql-performance@postgresql.org > Subject: [PERFORM] Performance advice > > > I'd like to get some feedback on my setup to see if I can optimize my > database performance. My application has two separate applications: > > The first application connects to websites and records the > statistics in the > database. Websites are monitored every 5 or 10 minutes (depends > on client), > there are 900 monitors which comes out to 7,800 monitorings per hour. The > monitor table has columns "nextdate" and "status" which are updated with > every monitoring, and also a row is inserted into the status table and the > status item table. For my performance testing (we're just about > to go live) > I've loaded the database with a month of data (we don't plan to keep data > longer than 1 month). So my status table has 6 million records and my > status item table has 6 million records as well. One key is that > the system > is multithreaded so up to 32 processes are accessing the database at the > same time, updating the "nextdate" before the monitoring and inserting the > status and status item records after. There is a serious performance > constraint here because unlike a webserver, this application cannot slow > down. If it slows down, we won't be able to monitor our sites at 5 minute > intervals which will make our customers unhappy. > > The second application is a web app (tomcat) which lets customers check > their status. Both of these applications are deployed on the > same server, a > 4 CPU (Xeon) with 1.5 gigs of RAM. The OS (RedHat Linux 7.3) and servers > are running on 18gig 10,000 RPM SCSI disk that is mirrored to a 2nd disk. > The database data directory is on a separate 36 gig 10,000 RPM SCSI disk > (we're trying to buy a 2nd disk to mirror it). I'm using Postgres 7.3.2. > > Issue #1 - Vacuum => Overall the system runs pretty well and seems stable. > Last night I did a "vacuum full analyze" and then ran my app overnight and > first thing in the morning I did a "vacuum analyze", which took > 35 minutes. > I'm not sure if this is normal for a database this size (there are 15,000 > updates per hour). During the vacuum my application does slow > down quite a > bit and afterwards is slow speeds back up. I've attached the > vacuum output > to this mail. I'm using Java Data Objects (JDO) so if table/column names > look weird it's because the schema is automatically generated. > > Issue #2 - postgres.conf => I'd love to get some feedback on > these settings. > I've read the archives and no one seems to agree I know, but with > the above > description of my app I hope someone can at least point me in the right > direction: > > max_connections = 200 > > # > # Shared Memory Size > # > shared_buffers = 3072 # min max_connections*2 or 16, 8KB each > #max_fsm_relations = 1000 # min 10, fsm is free space map, ~40 bytes > #max_fsm_pages = 10000 # min 1000, fsm is free space > map, ~6 bytes > #max_locks_per_transaction = 64 # min 10 > #wal_buffers = 8 # min 4, typically 8KB each > > # > # Non-shared Memory Sizes > # > sort_mem = 8192 # min 64, size in KB > vacuum_mem = 24576 # min 1024, size in KB > > The rest are left uncommented (using the defaults). > > Issue #3 - server hardware => > > - Is there anything I can do with the hardware to increase performance? > > - Should I increase the ram to 2 gigs? top shows that it is > using the swap > a bit (about 100k only). > > - I have at my disposal one other server which has 2 Xeons, > 10,000 RPM SCSI > drive. Would it make sense to put Postgres on it and leave my > apps running > on the more powerful 4 CPU server? > > - Would a RAID setup make the disk faster? Because top rarely shows the > CPUs above 50%, I suspect maybe the disk is the bottleneck. > > I'm thrilled to be able to use Postgres instead of a commercial > database and > I'm looking forward to putting this into production. Any help with the > above questions would be greatly appreciated. > > Michael Mattox > > ------=_NextPart_000_0031_01C33A78.B41C5CB0 Content-Type: application/octet-stream; name="postgresql.conf" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="postgresql.conf" # # PostgreSQL configuration file # ----------------------------- # # This file consists of lines of the form: # # name =3D value # # (The '=3D' is optional.) White space may be used. Comments are introduced # with '#' anywhere on a line. The complete list of option names and # allowed values can be found in the PostgreSQL documentation. The # commented-out settings shown in this file represent the default values. # # Any option can also be given as a command line switch to the # postmaster, e.g. 'postmaster -c log_connections=3Don'. Some options # can be changed at run-time with the 'SET' SQL command. # # This file is read on postmaster startup and when the postmaster # receives a SIGHUP. If you edit the file on a running system, you have=20 # to SIGHUP the postmaster for the changes to take effect, or use=20 # "pg_ctl reload". #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # # Connection Parameters # tcpip_socket =3D true #ssl =3D false max_connections =3D 200 #superuser_reserved_connections =3D 2 port =3D 5432=20 #hostname_lookup =3D false #show_source_port =3D false #unix_socket_directory =3D '' #unix_socket_group =3D '' #unix_socket_permissions =3D 0777 # octal #virtual_host =3D '' #krb_server_keyfile =3D '' # # Shared Memory Size # shared_buffers =3D 8192 # min max_connections*2 or 16, 8KB each max_fsm_relations =3D 2000 # min 10, fsm is free space map, ~40 bytes max_fsm_pages =3D 20000 # min 1000, fsm is free space map, ~6 bytes #max_locks_per_transaction =3D 64 # min 10 wal_buffers =3D 16 # min 4, typically 8KB each # # Non-shared Memory Sizes # sort_mem =3D 8192 # min 64, size in KB vacuum_mem =3D 24576 # min 1024, size in KB # # Write-ahead log (WAL) # #checkpoint_segments =3D 3 # in logfile segments, min 1, 16MB each #checkpoint_timeout =3D 300 # range 30-3600, in seconds # #commit_delay =3D 0 # range 0-100000, in microseconds #commit_siblings =3D 5 # range 1-1000 # #fsync =3D true #wal_sync_method =3D fsync # the default varies across platforms: # # fsync, fdatasync, open_sync, or open_datasync #wal_debug =3D 0 # range 0-16 # # Optimizer Parameters # #enable_seqscan =3D true #enable_indexscan =3D true #enable_tidscan =3D true #enable_sort =3D true #enable_nestloop =3D true #enable_mergejoin =3D true #enable_hashjoin =3D true effective_cache_size =3D 102400 # typically 8KB each random_page_cost =3D 2 # units are one sequential page fetch cost #cpu_tuple_cost =3D 0.01 # (same) #cpu_index_tuple_cost =3D 0.001 # (same) #cpu_operator_cost =3D 0.0025 # (same) #default_statistics_target =3D 10 # range 1-1000 # # GEQO Optimizer Parameters # #geqo =3D true #geqo_selection_bias =3D 2.0 # range 1.5-2.0 #geqo_threshold =3D 11 #geqo_pool_size =3D 0 # default based on tables in statement,=20 # range 128-1024 #geqo_effort =3D 1 #geqo_generations =3D 0 #geqo_random_seed =3D -1 # auto-compute seed # # Message display # server_min_messages =3D error # Values, in order of decreasing detail: # debug5, debug4, debug3, debug2, debug1, # info, notice, warning, error, log, fatal, # panic client_min_messages =3D error # Values, in order of decreasing detail: # debug5, debug4, debug3, debug2, debug1, # log, info, notice, warning, error #silent_mode =3D false #log_connections =3D false #log_pid =3D false #log_statement =3D false #log_duration =3D false log_timestamp =3D true #log_min_error_statement =3D error # Values in order of increasing severity: # debug5, debug4, debug3, debug2, debug1, # info, notice, warning, error, panic(off) #debug_print_parse =3D false #debug_print_rewritten =3D false #debug_print_plan =3D false #debug_pretty_print =3D false #explain_pretty_print =3D true # requires USE_ASSERT_CHECKING #debug_assertions =3D true # # Syslog # #syslog =3D 0 # range 0-2 #syslog_facility =3D 'LOCAL0' #syslog_ident =3D 'postgres' # # Statistics # #show_parser_stats =3D false #show_planner_stats =3D false #show_executor_stats =3D false #show_statement_stats =3D false # requires BTREE_BUILD_STATS #show_btree_build_stats =3D false # # Access statistics collection # #stats_start_collector =3D true #stats_reset_on_server_start =3D true #stats_command_string =3D false #stats_row_level =3D false #stats_block_level =3D false # # Lock Tracing # #trace_notify =3D false # requires LOCK_DEBUG #trace_locks =3D false #trace_userlocks =3D false #trace_lwlocks =3D false #debug_deadlocks =3D false #trace_lock_oidmin =3D 16384 #trace_lock_table =3D 0 # # Misc # #autocommit =3D true #dynamic_library_path =3D '$libdir' #search_path =3D '$user,public' #datestyle =3D 'iso, us' #timezone =3D unknown # actually, defaults to TZ environment setting #australian_timezones =3D false #client_encoding =3D sql_ascii # actually, defaults to database encoding #authentication_timeout =3D 60 # 1-600, in seconds #deadlock_timeout =3D 1000 # in milliseconds #default_transaction_isolation =3D 'read committed' #max_expr_depth =3D 10000 # min 10 #max_files_per_process =3D 1000 # min 25 #password_encryption =3D true #sql_inheritance =3D true #transform_null_equals =3D false #statement_timeout =3D 0 # 0 is disabled, in milliseconds #db_user_namespace =3D false =20 # # Locale settings # # (initialized by initdb -- may be changed) LC_MESSAGES =3D 'en_GB.UTF-8' LC_MONETARY =3D 'en_GB.UTF-8' LC_NUMERIC =3D 'en_GB.UTF-8' LC_TIME =3D 'en_GB.UTF-8' ------=_NextPart_000_0031_01C33A78.B41C5CB0-- From pgsql-performance-owner@postgresql.org Tue Jun 24 13:05:35 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 8F26B30F71F for ; Tue, 24 Jun 2003 16:05:34 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 33766-09 for ; Tue, 24 Jun 2003 13:05:24 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id 9292430F980 for ; Tue, 24 Jun 2003 13:05:23 -0300 (ADT) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3149548; Tue, 24 Jun 2003 09:05:32 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: , Subject: Re: Performance advice Date: Tue, 24 Jun 2003 09:04:35 -0700 User-Agent: KMail/1.4.3 References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200306240904.35923.josh@agliodbs.com> X-Archive-Number: 200306/144 X-Sequence-Number: 2228 Micheal, > I changed the postgres.conf settings as suggested by several people. I've > attached it to this email, please let me know if you see anything else I > can tweak. top still says I have plenty of ram, so should I increase the > buffers and/or effective_cache even more? Effective cache, yes. Buffers, no. Even if you have RAM available, increasing buffers beyond an optimal but hard to locate point decreases performance. I'd advise you to start playing with buffers only after you are done playing with other memory-eating params. I would suggest, though, increasing FSM_relations even more, until your daily VACUUM FULL does almost no work. This will improve index usage and speed queries. > I moved the WAL (pg_xlog directory) to another drive. There are two drives > in the system, so one has the OS, servers, all files, and the WAL and the > other has nothing but the data. I think it'd be best to put the WAL on a > separate drive from the OS but I don't know if I can get another drive > added just for that due to our limited budget. A high-speed IDE drive might be adequate for WAL, except that Linux has booting issues with a mix of IDE & SCSI and many motherboards. > I learned that I only need to vacuum tables that are changed frequently. > My app doesn't do any deletes, and only one table changes, the monitor > table. several times a second. So I only need to vacuum that table. > Vacuuming the entire database is slow and unecessary. If I only do the > monitor table, it takes only a few seconds. Much better than the 35 > minutes for the entire database that it was taking this morning. Increasing FSM_relations will also make vacuums more efficient. > I want to thank everyone for their input. I've heard Postgres is slow and > doesn't scale, but now I do it's really just a matter of learning to > configure it properly and trial & error. I do think the documentation > could be enhanced a bit here, but I'm sure there are some users who don't Absolutely. I'm working on it. Look to Techdocs next week. -- Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Tue Jun 24 14:00:11 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 723AE30FA17 for ; Tue, 24 Jun 2003 17:00:07 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 50826-01 for ; Tue, 24 Jun 2003 13:59:56 -0300 (ADT) Received: from mailav.tor1.inquent.com (mail.inquent.com [216.208.117.106]) by svr1.postgresql.org (Postfix) with ESMTP id 864FC30F9CE for ; Tue, 24 Jun 2003 13:59:56 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mailav.tor1.inquent.com (Postfix) with ESMTP id 28F891024D; Tue, 24 Jun 2003 12:53:32 -0400 (EDT) Received: from [10.0.2.10] (unknown [10.0.2.10]) by mailav.tor1.inquent.com (Postfix) with ESMTP id 2E00510248; Tue, 24 Jun 2003 12:53:30 -0400 (EDT) Subject: Re: Performance advice From: Rod Taylor To: michael.mattox@verideon.com Cc: Postgresql Performance In-Reply-To: References: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-4WadJ+tOhC9s2CSokyub" Message-Id: <1056474010.67077.47.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.0 Date: 24 Jun 2003 13:00:11 -0400 X-Virus-Scanned: by AMaViS perl-11 X-Archive-Number: 200306/145 X-Sequence-Number: 2229 --=-4WadJ+tOhC9s2CSokyub Content-Type: text/plain Content-Transfer-Encoding: quoted-printable > configure it properly and trial & error. I do think the documentation co= uld > be enhanced a bit here, but I'm sure there are some users who don't make Do you have any specific thoughts about documentation? Areas of confusion? Was it difficult to find the information in question, or was it simply unavailable? --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-4WadJ+tOhC9s2CSokyub Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA++IOa6DETLow6vwwRAtgdAJ93gTsfh3ZS+/ORF9VMsUIrUFkzgQCbBm0t /vK7eqDjlPcuecTJ/izStJM= =dPo5 -----END PGP SIGNATURE----- --=-4WadJ+tOhC9s2CSokyub-- From pgsql-performance-owner@postgresql.org Wed Jun 25 03:48:25 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id CA0AD30DD20 for ; Wed, 25 Jun 2003 06:48:22 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 58595-08 for ; Wed, 25 Jun 2003 03:48:12 -0300 (ADT) Received: from mwinf0302.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.28]) by svr1.postgresql.org (Postfix) with ESMTP id 1569D30FA17 for ; Wed, 25 Jun 2003 03:48:12 -0300 (ADT) Received: from Paris (unknown [80.15.41.168]) by mwinf0302.wanadoo.fr (SMTP Server) with ESMTP id 0A327C0001C3; Wed, 25 Jun 2003 08:48:11 +0200 (CEST) Reply-To: From: "Michael Mattox" To: "Rod Taylor" Cc: "Postgresql Performance" Subject: Re: Performance advice Date: Wed, 25 Jun 2003 08:48:13 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal In-Reply-To: <1056474010.67077.47.camel@jester> X-Archive-Number: 200306/146 X-Sequence-Number: 2230 > > configure it properly and trial & error. I do think the > documentation could > > be enhanced a bit here, but I'm sure there are some users who don't make > > Do you have any specific thoughts about documentation? Areas of > confusion? Was it difficult to find the information in question, or was > it simply unavailable? I think the biggest area of confusion for me was that the various parameters are very briefly described and no context is given for their parameters. For example, from: http://www.postgresql.org/docs/view.php?version=7.3&idoc=1&file=runtime-conf ig.html MAX_FSM_RELATIONS (integer) Sets the maximum number of relations (tables) for which free space will be tracked in the shared free-space map. The default is 100. This option can only be set at server start. There's not enough information there to properly tune postgres. A few people suggested increasing this so I set mine to 4000. I don't have much idea if that's too high, too low, just right. What would be nice if these were put into context. Maybe come up with a matrix, with the settings and various server configs. We could come up with the 5-10 most common server configurations. So a user with 256k of ram and a single IDE disk will have different range from a user with 2 gigs of ram and a SCSI RAID. The next thing that really needs improving is the optimization section of the FAQ (http://www.postgresql.org/docs/faqs/FAQ.html#3.6). This is a very important section of the documentation and it's pretty empty. One thing that was suggested to me is to move the WAL directory to another drive. That could be in this FAQ section. effective_cache isn't mentioned either. It'd be great to talk about server hardware as well, such as memory, whether to put postgres on a dedicated server or keep it on the same server as the apps/webapps. Please don't misunderstand, the Postgres documentation is excellent. Some improvements to the performance sections of the documentation would make a huge difference. Regards, Michael From pgsql-performance-owner@postgresql.org Wed Jun 25 03:51:39 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id E7F8D30FA17 for ; Wed, 25 Jun 2003 06:51:38 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 60118-09 for ; Wed, 25 Jun 2003 03:51:28 -0300 (ADT) Received: from email02.aon.at (WARSL402PIP7.highway.telekom.at [195.3.96.94]) by svr1.postgresql.org (Postfix) with SMTP id DA0D130DD20 for ; Wed, 25 Jun 2003 03:51:27 -0300 (ADT) Received: (qmail 603236 invoked from network); 25 Jun 2003 06:51:21 -0000 Received: from m154p005.dipool.highway.telekom.at (HELO cantor) ([62.46.9.37]) (envelope-sender ) by qmail2rs.highway.telekom.at (qmail-ldap-1.03) with SMTP for ; 25 Jun 2003 06:51:21 -0000 From: Manfred Koizar To: Cc: Subject: Re: Performance advice Date: Wed, 25 Jun 2003 08:51:08 +0200 Message-ID: References: In-Reply-To: X-Mailer: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/147 X-Sequence-Number: 2231 [ This has been written offline yesterday. Now I see that most of it has already been covered. I send it anyway ... ] On Tue, 24 Jun 2003 09:39:32 +0200, "Michael Mattox" wrote: >Websites are monitored every 5 or 10 minutes (depends on client), >there are 900 monitors which comes out to 7,800 monitorings per hour. So your server load - at least INSERT, UPDATE, DELETE - is absolutely predictable. This is good. It enables you to design a cron-driven VACUUM strategy. |INFO: --Relation public.jdo_sequencex-- |INFO: Pages 28: Changed 1, Empty 0; Tup 1: Vac 5124, Keep 0, UnUsed 0. ^ ^^^^ This table could stand more frequent VACUUMs, every 15 minutes or so. BTW, from the name of this table and from the fact that there is only one live tuple I guess that you are using it to keep track of a sequence number. By using a real sequence you could get what you need with less contention; and you don't have to VACUUM a sequence. |INFO: --Relation public.monitorx-- |INFO: Removed 170055 tuples in 6036 pages. | CPU 0.52s/0.81u sec elapsed 206.26 sec. |INFO: Pages 6076: Changed 0, Empty 0; Tup 2057: Vac 170055, Keep 568, UnUsed 356. | Total CPU 6.28s/13.23u sec elapsed 486.07 sec. The Vac : Tup ratio for this table is more than 80. You have to VACUUM this table more often. How long is "overnight"? Divide this by 80 and use the result as the interval between VACUUM [VERBOSE] [ANALYSE] public.monitorx; Thus you'd have approximately as many dead tuples as live tuples and the table size should not grow far beyond 150 pages (after an initial VACUUM FULL, of course). Then VACUUM of this table should take no more than 20 seconds. Caveat: Frequent ANALYSEs might trigger the need to VACUUM pg_catalog.pg_statistic. > The >monitor table has columns "nextdate" and "status" which are updated with >every monitoring, [...] > updating the "nextdate" before the monitoring and inserting the >status and status item records after. Do you mean updating monitor.nextdate before the monitoring and monitor.status after the monitoring? Can you combine these two UPDATEs into one? > During the vacuum my application does slow down quite a bit Yes, because VACUUM does lots of I/O. > and afterwards is slow speeds back up. ... because the working set is slowly fetched into the cache after having been flushed out by VACUUM. Your five largest relations are monitorstatus_statusitemsx, monitorstatusitemlistd8ea58a5x, monitorstatusitemlistx, monitorstatusitemx, and monitorstatusx. The heap relations alone (without indexes) account for 468701 pages, almost 4GB. VACUUMing these five relations takes 23 minutes for freeing less than 200 out of 6 million tuples for each relation. This isn't worth it. Unless always the same tuples are updated over and over, scheduling a VACUUM for half a million deletions/updates should be sufficient. >shared_buffers = 3072 # min max_connections*2 or 16, 8KB each >sort_mem = 8192 # min 64, size in KB >vacuum_mem = 24576 # min 1024, size in KB > >The rest are left uncommented (using the defaults). As has already been said, don't forget effective_cache_size. I'm not so sure about random_page_cost. Try to find out which queries are too slow. EXPLAIN ANALYSE is your friend. One more thing: I see 2 or 3 UPDATEs and 5 INSERTs per monitoring. Are these changes wrapped into a single transaction? Servus Manfred From pgsql-performance-owner@postgresql.org Wed Jun 25 05:12:28 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id DC4DA30FB5B for ; Wed, 25 Jun 2003 08:12:26 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 80359-05 for ; Wed, 25 Jun 2003 05:12:15 -0300 (ADT) Received: from lorraine.ipl.co.uk (lorraine.ipl.co.uk [195.112.52.123]) by svr1.postgresql.org (Postfix) with ESMTP id D371030FBAA for ; Wed, 25 Jun 2003 05:12:13 -0300 (ADT) Received: from HFPORT.dmr.co.uk (pennsoft.gotadsl.co.uk [81.6.232.68]) by lorraine.ipl.co.uk (8.12.9/8.12.9) with ESMTP id h5P8BuB9006450; Wed, 25 Jun 2003 09:11:56 +0100 Message-Id: <5.1.0.14.0.20030625091002.02c2d008@mailserver.ipl.co.uk> X-Sender: hf1@mailserver.ipl.co.uk X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Wed, 25 Jun 2003 09:12:24 +0100 To: Rod Taylor From: Hilary Forbes Subject: Re: Performance advice Cc: pgsql-performance@postgresql.org In-Reply-To: <1056474010.67077.47.camel@jester> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Archive-Number: 200306/148 X-Sequence-Number: 2232 PM4JI but from my point of view this has been a most useful thread. I too have found it difficult to find the right bit of documentation on performance. I *think* what is needed is some sort of a route map, Poor Performance - start here. Then some questions with sections of the documentation you should go to. Hilary At 13:00 24/06/2003 -0400, you wrote: >> configure it properly and trial & error. I do think the documentation could >> be enhanced a bit here, but I'm sure there are some users who don't make > >Do you have any specific thoughts about documentation? Areas of >confusion? Was it difficult to find the information in question, or was >it simply unavailable? > >-- >Rod Taylor > >PGP Key: http://www.rbt.ca/rbtpub.asc Hilary Forbes ------------- DMR Computer Limited: http://www.dmr.co.uk/ Direct line: 01689 889950 Switchboard: (44) 1689 860000 Fax: (44) 1689 860330 E-mail: hforbes@dmr.co.uk ********************************************************** From pgsql-performance-owner@postgresql.org Wed Jun 25 06:06:50 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 2EAD530FBB6 for ; Wed, 25 Jun 2003 09:05:14 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 07784-01 for ; Wed, 25 Jun 2003 06:05:03 -0300 (ADT) Received: from lewexch.lewis-stores.com (mail.lewis-stores.com [196.31.249.242]) by svr1.postgresql.org (Postfix) with ESMTP id 3F6E830DD20 for ; Wed, 25 Jun 2003 06:04:56 -0300 (ADT) Received: by LEWEXCH with Internet Mail Service (5.5.2653.19) id ; Wed, 25 Jun 2003 10:58:33 +0200 Message-ID: From: Howard Oblowitz To: Hilary Forbes Cc: pgsql-performance@postgresql.org Subject: Re: Performance advice Date: Wed, 25 Jun 2003 10:58:18 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain X-Archive-Number: 200306/149 X-Sequence-Number: 2233 I agree a route map would really help. > -----Original Message----- > From: Hilary Forbes [SMTP:hforbes@dmr.co.uk] > Sent: 25 June 2003 10:12 > To: Rod Taylor > Cc: pgsql-performance@postgresql.org > Subject: Re: [PERFORM] Performance advice > > PM4JI but from my point of view this has been a most useful thread. I too > have found it difficult to find the right bit of documentation on > performance. I *think* what is needed is some sort of a route map, Poor > Performance - start here. Then some questions with sections of the > documentation you should go to. > > Hilary > > At 13:00 24/06/2003 -0400, you wrote: > >> configure it properly and trial & error. I do think the documentation > could > >> be enhanced a bit here, but I'm sure there are some users who don't > make > > > >Do you have any specific thoughts about documentation? Areas of > >confusion? Was it difficult to find the information in question, or was > >it simply unavailable? > > > >-- > >Rod Taylor > > > >PGP Key: http://www.rbt.ca/rbtpub.asc > > > Hilary Forbes > ------------- > DMR Computer Limited: http://www.dmr.co.uk/ > Direct line: 01689 889950 > Switchboard: (44) 1689 860000 Fax: (44) 1689 860330 > E-mail: hforbes@dmr.co.uk > > ********************************************************** > > > ---------------------------(end of broadcast)--------------------------- > TIP 9: the planner will ignore your desire to choose an index scan if your > joining column's datatypes do not match From pgsql-performance-owner@postgresql.org Wed Jun 25 06:47:59 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 20B7A30E645 for ; Wed, 25 Jun 2003 09:47:57 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 09877-04 for ; Wed, 25 Jun 2003 06:47:46 -0300 (ADT) Received: from mwinf0301.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.28]) by svr1.postgresql.org (Postfix) with ESMTP id 3DA2830FBB6 for ; Wed, 25 Jun 2003 06:47:46 -0300 (ADT) Received: from Paris (ABoulogne-110-1-3-168.w80-15.abo.wanadoo.fr [80.15.41.168]) by mwinf0301.wanadoo.fr (SMTP Server) with ESMTP id 238124008B9; Wed, 25 Jun 2003 11:47:45 +0200 (CEST) Reply-To: From: "Michael Mattox" To: "Manfred Koizar" Cc: Subject: Re: Performance advice Date: Wed, 25 Jun 2003 11:47:48 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal In-Reply-To: X-Archive-Number: 200306/150 X-Sequence-Number: 2234 > [ This has been written offline yesterday. Now I see that most of it > has already been covered. I send it anyway ... ] Still great advice with slightly different explanations, very useful. > |INFO: --Relation public.jdo_sequencex-- > |INFO: Pages 28: Changed 1, Empty 0; Tup 1: Vac 5124, Keep 0, UnUsed 0. > ^ ^^^^ > This table could stand more frequent VACUUMs, every 15 minutes or so. Can you explain what the "Vac" is and how you knew that it should be vacuumed more often? I'd like to understand how to interpret my vacuum log. I looked in the vacuum section of the docs and there's nothing about the vacuum output . > BTW, from the name of this table and from the fact that there is only > one live tuple I guess that you are using it to keep track of a > sequence number. By using a real sequence you could get what you need > with less contention; and you don't have to VACUUM a sequence. I'm using Java Data Objects (JDO) which is an O/R mapper. It generated the schema from my object model by default it used a table for a sequence. I just got finished configuring it to use a real postgres sequence. With the way they have it designed, it opens and closes a connection each time it retrieves a sequence. Would I get a performance increase if I modify their code to retrieve multiple sequence numbers in one connection? For example I could have it grab 50 at a time, which would replace 50 connections with 1. > > The > >monitor table has columns "nextdate" and "status" which are updated with > >every monitoring, [...] > > updating the "nextdate" before the monitoring and inserting the > >status and status item records after. > > Do you mean updating monitor.nextdate before the monitoring and > monitor.status after the monitoring? Can you combine these two > UPDATEs into one? I was doing this to prevent the monitor from being added to the queue while it was executing. But I fixed this, effectively reducing my transactions by 1/2. > >shared_buffers = 3072 # min max_connections*2 or 16, 8KB each > >sort_mem = 8192 # min 64, size in KB > >vacuum_mem = 24576 # min 1024, size in KB > > > >The rest are left uncommented (using the defaults). > > As has already been said, don't forget effective_cache_size. I'm not > so sure about random_page_cost. Try to find out which queries are too > slow. EXPLAIN ANALYSE is your friend. > > One more thing: I see 2 or 3 UPDATEs and 5 INSERTs per monitoring. > Are these changes wrapped into a single transaction? These were in 2 transactions but now I have it into a single transaction. Thanks, Michael From pgsql-performance-owner@postgresql.org Wed Jun 25 06:59:55 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id C17AD30FBD1 for ; Wed, 25 Jun 2003 09:59:53 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 09877-07 for ; Wed, 25 Jun 2003 06:59:43 -0300 (ADT) Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id 1C52730FB73 for ; Wed, 25 Jun 2003 06:59:41 -0300 (ADT) Received: (from root@localhost) by www.pspl.co.in (8.11.6/8.11.6) id h5P9xf908514 for ; Wed, 25 Jun 2003 15:29:41 +0530 Received: from daithan (daithan.intranet.pspl.co.in [192.168.7.161]) by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h5P9xeG08509 for ; Wed, 25 Jun 2003 15:29:40 +0530 From: "Shridhar Daithankar" To: Date: Wed, 25 Jun 2003 15:28:58 +0530 MIME-Version: 1.0 Subject: Re: Performance advice Reply-To: shridhar_daithankar@persistent.co.in Message-ID: <3EF9BFBA.17789.3CF4A70@localhost> In-reply-to: References: X-mailer: Pegasus Mail for Windows (v4.02) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Archive-Number: 200306/151 X-Sequence-Number: 2235 On 25 Jun 2003 at 11:47, Michael Mattox wrote: > I'm using Java Data Objects (JDO) which is an O/R mapper. It generated the > schema from my object model by default it used a table for a sequence. I > just got finished configuring it to use a real postgres sequence. With the > way they have it designed, it opens and closes a connection each time it > retrieves a sequence. Would I get a performance increase if I modify their > code to retrieve multiple sequence numbers in one connection? For example I > could have it grab 50 at a time, which would replace 50 connections with 1. You need to use sequence functions like setval, curval, nextval. May be you can write your own wrapper function to "grab" as many sequence values as you want but it would be good if you design/maintain locking around it as appropriate. See http://developer.postgresql.org/docs/postgres/sql-createsequence.html http://developer.postgresql.org/docs/postgres/functions-sequence.html HTH Bye Shridhar -- Velilind's Laws of Experimentation: (1) If reproducibility may be a problem, conduct the test only once. (2) If a straight line fit is required, obtain only two data points. From pgsql-performance-owner@postgresql.org Wed Jun 25 08:06:17 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 4476630FBF9 for ; Wed, 25 Jun 2003 11:06:15 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 09770-10 for ; Wed, 25 Jun 2003 08:06:04 -0300 (ADT) Received: from tomts17-srv.bellnexxia.net (tomts17.bellnexxia.net [209.226.175.71]) by svr1.postgresql.org (Postfix) with ESMTP id 05C9230FBDA for ; Wed, 25 Jun 2003 08:06:04 -0300 (ADT) Received: from [192.168.1.200] ([216.209.81.133]) by tomts17-srv.bellnexxia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20030625110602.EQJI1990.tomts17-srv.bellnexxia.net@[192.168.1.200]>; Wed, 25 Jun 2003 07:06:02 -0400 Subject: Re: Performance advice From: Rod Taylor To: Hilary Forbes Cc: Postgresql Performance In-Reply-To: <5.1.0.14.0.20030625091002.02c2d008@mailserver.ipl.co.uk> References: <5.1.0.14.0.20030625091002.02c2d008@mailserver.ipl.co.uk> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-vg9hIyjLIKvHA5UjUFYa" Message-Id: <1056539181.69651.52.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.0 Date: 25 Jun 2003 07:06:22 -0400 X-Archive-Number: 200306/152 X-Sequence-Number: 2236 --=-vg9hIyjLIKvHA5UjUFYa Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Wed, 2003-06-25 at 04:12, Hilary Forbes wrote: > PM4JI but from my point of view this has been a most useful thread. I to= o have found it difficult to find the right bit of documentation on perform= ance. I *think* what is needed is some sort of a route map, Poor Performa= nce - start here. Then some questions with sections of the documentation yo= u should go to. Do you have any examples where this has worked well (for reference)? The only real example I have is MS's help which never gave me the right answer. --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-vg9hIyjLIKvHA5UjUFYa Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA++YIt6DETLow6vwwRAg8wAJ9Ywa3gN0ScIqnfPEEMMrjiOzfsDwCcCCoi vh20rxXMj+WM305Q0/z4lF4= =v1AK -----END PGP SIGNATURE----- --=-vg9hIyjLIKvHA5UjUFYa-- From pgsql-performance-owner@postgresql.org Wed Jun 25 08:09:48 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 0633130FC0B for ; Wed, 25 Jun 2003 11:09:33 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 28767-01 for ; Wed, 25 Jun 2003 08:09:16 -0300 (ADT) Received: from tomts7-srv.bellnexxia.net (tomts7.bellnexxia.net [209.226.175.40]) by svr1.postgresql.org (Postfix) with ESMTP id B3C3E30FC04 for ; Wed, 25 Jun 2003 08:09:08 -0300 (ADT) Received: from [192.168.1.200] ([216.209.81.133]) by tomts7-srv.bellnexxia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20030625110907.HIMQ8834.tomts7-srv.bellnexxia.net@[192.168.1.200]>; Wed, 25 Jun 2003 07:09:07 -0400 Subject: Re: Performance advice From: Rod Taylor To: michael.mattox@verideon.com Cc: Postgresql Performance In-Reply-To: References: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-lgmUb0JAZi2q1ZBVNiBo" Message-Id: <1056539367.69651.60.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.0 Date: 25 Jun 2003 07:09:27 -0400 X-Archive-Number: 200306/153 X-Sequence-Number: 2237 --=-lgmUb0JAZi2q1ZBVNiBo Content-Type: text/plain Content-Transfer-Encoding: quoted-printable > I think the biggest area of confusion for me was that the various paramet= ers > are very briefly described and no context is given for their parameters. > improvements to the performance sections of the documentation would make a > huge difference. Agreed.. Josh has done some work recently re-arranging things to make them easier to find, but the content hasn't changed much. Thanks for your thoughts! --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-lgmUb0JAZi2q1ZBVNiBo Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA++YLm6DETLow6vwwRAtQ7AJ9jlbL3d8xiTWuB6TpJuPLC3bpFZwCeJXi0 YztLXHw1aasUxZpvFlgqBRg= =JSIN -----END PGP SIGNATURE----- --=-lgmUb0JAZi2q1ZBVNiBo-- From pgsql-performance-owner@postgresql.org Wed Jun 25 08:46:56 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 5678B30FB82 for ; Wed, 25 Jun 2003 11:46:55 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 28533-08 for ; Wed, 25 Jun 2003 08:46:44 -0300 (ADT) Received: from mwinf0301.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.28]) by svr1.postgresql.org (Postfix) with ESMTP id 8629230FAD4 for ; Wed, 25 Jun 2003 08:46:44 -0300 (ADT) Received: from Paris (ABoulogne-110-1-3-168.w80-15.abo.wanadoo.fr [80.15.41.168]) by mwinf0301.wanadoo.fr (SMTP Server) with ESMTP id 135E840082D for ; Wed, 25 Jun 2003 13:46:44 +0200 (CEST) Reply-To: From: "Michael Mattox" To: "Postgresql Performance" Subject: How to optimize monstrous query, sorts instead of using index Date: Wed, 25 Jun 2003 13:46:48 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal X-Archive-Number: 200306/155 X-Sequence-Number: 2239 I've used indexes to speed up my queries but this query escapes me. I'm curious if someone can suggest an index or a way to modify the query to use the index. The query is: select ms.averageconnecttimex as ms_averageconnecttime, ms.averagedurationx as ms_averageduration, ms.datex as ms_date, ms.idx as ms_id, ms.statusstringx as ms_statusstring, ms.statusx as ms_status, msi.actualcontentx as msi_actualcontent, msi.connecttimex as msi_connecttime, msi.correctcontentx as msi_correctcontent, msi.datex as msi_date, msi.descriptionx as msi_description, msi.durationx as msi_duration, msi.errorcontentx as msi_errorcontent, msi.idx as msi_id, msi.monitorlocationx as msi_monitorlocation, msi.statusstringx as msi_statusstring, msi.statusx as msi_status from monitorstatusx ms, monitorstatusitemx msi where monitorx.idx = 'M-TEST_1444-TEST_00_10560561260561463219352' AND monitorx.jdoidx = ms.monitorx AND ms.datex >= '2003-06-20 08:57:21.36' AND ms.datex <= '2003-06-29 08:57:21.36' AND ms.jdoidx = monitorstatus_statusitemsx.jdoidx AND monitorstatus_statusitemsx.statusitemsx = monitorstatusitemlistd8ea58a5x.jdoidx AND monitorstatusitemlistd8ea58a5x.statusitemlistx = msi.jdoidx ORDER BY ms_date DESC; Here is the result of explain: Sort (cost=9498.85..9500.16 rows=525 width=788) Sort Key: ms.datex -> Nested Loop (cost=0.00..9475.15 rows=525 width=788) -> Nested Loop (cost=0.00..7887.59 rows=525 width=123) -> Nested Loop (cost=0.00..6300.03 rows=525 width=107) -> Nested Loop (cost=0.00..4712.02 rows=525 width=91) -> Index Scan using monitorx_id_index on monitorx (cost=0.00..5.37 rows=1 width=8) Index Cond: (idx = 'M-TEST_1444-TEST_00_10560561260561463219352'::character varying) -> Index Scan using monitorstatusxmonitori on monitorstatusx ms (cost=0.00..4695.65 rows=880 width=83) Index Cond: ("outer".jdoidx = ms.monitorx) Filter: ((datex >= '2003-06-20 08:57:21.36'::timestamp without time zone) AND (datex <= '2003-06-29 08:57:21.36'::timestamp without time zone)) -> Index Scan using monitorstatus_stjdoidb742c9b3i on monitorstatus_statusitemsx (cost=0.00..3.01 rows=1 width=16) Index Cond: ("outer".jdoidx = monitorstatus_statusitemsx.jdoidx) -> Index Scan using monitorstatusitejdoid7db0befci on monitorstatusitemlistd8ea58a5x (cost=0.00..3.01 rows=1 width=16) Index Cond: ("outer".statusitemsx = monitorstatusitemlistd8ea58a5x.jdoidx) -> Index Scan using monitorstatusitemx_pkey on monitorstatusitemx msi (cost=0.00..3.01 rows=1 width=665) Index Cond: ("outer".statusitemlistx = msi.jdoidx) (17 rows) As you can see, it's doing a sort on ms.datex. I created an index on the monitorstatusx (ms) table for the datex, but it doesn't use it. Is it possible to create an index to prevent this sort? Thanks, Michael Michael Mattox cunparis@yahoo.fr / http://www.advweb.com/michael From pgsql-performance-owner@postgresql.org Wed Jun 25 08:52:38 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 14A7130FC2B for ; Wed, 25 Jun 2003 11:52:37 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 33972-02 for ; Wed, 25 Jun 2003 08:52:26 -0300 (ADT) Received: from curry.tmsl.demon.co.uk (tmsl-adsl.demon.co.uk [80.177.114.181]) by svr1.postgresql.org (Postfix) with ESMTP id 8A39D30FBFB for ; Wed, 25 Jun 2003 08:52:25 -0300 (ADT) Received: from bacon.tmsl.demon.co.uk (bacon.tmsl.demon.co.uk [192.168.7.102]) by curry.tmsl.demon.co.uk (8.11.6/8.11.6) with ESMTP id h5PBqOl14869 for ; Wed, 25 Jun 2003 12:52:25 +0100 Date: Wed, 25 Jun 2003 12:52:21 +0100 From: Paul Thomas To: "pgsql-performance @ postgresql . org" Subject: Re: Performance advice Message-ID: <20030625125221.A11482@bacon> References: Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=ISO-8859-1 In-Reply-To: ; from michael.mattox@verideon.com on Wed, Jun 25, 2003 at 10:47:48 +0100 X-Mailer: Balsa 1.2.3 Lines: 26 X-Archive-Number: 200306/156 X-Sequence-Number: 2240 On 25/06/2003 10:47 Michael Mattox wrote: > I'm using Java Data Objects (JDO) which is an O/R mapper. It generated > the > schema from my object model by default it used a table for a sequence. I > just got finished configuring it to use a real postgres sequence. With > the > way they have it designed, it opens and closes a connection each time it > retrieves a sequence. Would I get a performance increase if I modify > their > code to retrieve multiple sequence numbers in one connection? For > example I > could have it grab 50 at a time, which would replace 50 connections with > 1. For best performance, you really should consider using a connection pool as it removes the overhead of creating and closing connections. -- Paul Thomas +------------------------------+---------------------------------------------+ | Thomas Micro Systems Limited | Software Solutions for the Smaller Business | | Computer Consultants | http://www.thomas-micro-systems-ltd.co.uk | +------------------------------+---------------------------------------------+ From pgsql-performance-owner@postgresql.org Wed Jun 25 08:54:14 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 0AB0C30FBEC for ; Wed, 25 Jun 2003 11:54:13 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 31683-06 for ; Wed, 25 Jun 2003 08:54:02 -0300 (ADT) Received: from tomts5-srv.bellnexxia.net (tomts5.bellnexxia.net [209.226.175.25]) by svr1.postgresql.org (Postfix) with ESMTP id 046B530FB82 for ; Wed, 25 Jun 2003 08:54:02 -0300 (ADT) Received: from [192.168.1.200] ([216.209.81.133]) by tomts5-srv.bellnexxia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20030625115401.JLRC23206.tomts5-srv.bellnexxia.net@[192.168.1.200]>; Wed, 25 Jun 2003 07:54:01 -0400 Subject: Re: How to optimize monstrous query, sorts instead of using index From: Rod Taylor To: michael.mattox@verideon.com Cc: Postgresql Performance In-Reply-To: References: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-/QG6TYDtMAHPfbV+e0Sb" Message-Id: <1056542059.69651.73.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.0 Date: 25 Jun 2003 07:54:20 -0400 X-Archive-Number: 200306/157 X-Sequence-Number: 2241 --=-/QG6TYDtMAHPfbV+e0Sb Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Is this 7.3.x? Can we see explain analyze output for the query? On Wed, 2003-06-25 at 07:46, Michael Mattox wrote: > I've used indexes to speed up my queries but this query escapes me. I'm > curious if someone can suggest an index or a way to modify the query to u= se > the index. The query is: >=20 > select ms.averageconnecttimex as ms_averageconnecttime, ms.averageduratio= nx > as ms_averageduration, ms.datex as ms_date, ms.idx as ms_id, > ms.statusstringx as ms_statusstring, ms.statusx as ms_status, > msi.actualcontentx as msi_actualcontent, msi.connecttimex as > msi_connecttime, msi.correctcontentx as msi_correctcontent, msi.datex as > msi_date, msi.descriptionx as msi_description, msi.durationx as > msi_duration, msi.errorcontentx as msi_errorcontent, msi.idx as msi_id, > msi.monitorlocationx as msi_monitorlocation, msi.statusstringx as > msi_statusstring, msi.statusx as msi_status from monitorstatusx ms, > monitorstatusitemx msi where monitorx.idx =3D > 'M-TEST_1444-TEST_00_10560561260561463219352' AND monitorx.jdoidx =3D > ms.monitorx AND ms.datex >=3D '2003-06-20 08:57:21.36' AND ms.datex <=3D > '2003-06-29 08:57:21.36' AND ms.jdoidx =3D monitorstatus_statusitemsx.jdo= idx > AND monitorstatus_statusitemsx.statusitemsx =3D > monitorstatusitemlistd8ea58a5x.jdoidx AND > monitorstatusitemlistd8ea58a5x.statusitemlistx =3D msi.jdoidx ORDER BY ms= _date > DESC; >=20 > Here is the result of explain: >=20 > Sort (cost=3D9498.85..9500.16 rows=3D525 width=3D788) > Sort Key: ms.datex > -> Nested Loop (cost=3D0.00..9475.15 rows=3D525 width=3D788) > -> Nested Loop (cost=3D0.00..7887.59 rows=3D525 width=3D123) > -> Nested Loop (cost=3D0.00..6300.03 rows=3D525 width=3D= 107) > -> Nested Loop (cost=3D0.00..4712.02 rows=3D525 wi= dth=3D91) > -> Index Scan using monitorx_id_index on > monitorx (cost=3D0.00..5.37 rows=3D1 width=3D8) > Index Cond: (idx =3D > 'M-TEST_1444-TEST_00_10560561260561463219352'::character varying) > -> Index Scan using monitorstatusxmonitori on > monitorstatusx ms (cost=3D0.00..4695.65 rows=3D880 width=3D83) > Index Cond: ("outer".jdoidx =3D ms.monit= orx) > Filter: ((datex >=3D '2003-06-20 > 08:57:21.36'::timestamp without time zone) AND (datex <=3D '2003-06-29 > 08:57:21.36'::timestamp without time zone)) > -> Index Scan using monitorstatus_stjdoidb742c9b3i = on > monitorstatus_statusitemsx (cost=3D0.00..3.01 rows=3D1 width=3D16) > Index Cond: ("outer".jdoidx =3D > monitorstatus_statusitemsx.jdoidx) > -> Index Scan using monitorstatusitejdoid7db0befci on > monitorstatusitemlistd8ea58a5x (cost=3D0.00..3.01 rows=3D1 width=3D16) > Index Cond: ("outer".statusitemsx =3D > monitorstatusitemlistd8ea58a5x.jdoidx) > -> Index Scan using monitorstatusitemx_pkey on monitorstatusite= mx > msi (cost=3D0.00..3.01 rows=3D1 width=3D665) > Index Cond: ("outer".statusitemlistx =3D msi.jdoidx) > (17 rows) >=20 > As you can see, it's doing a sort on ms.datex. I created an index on the > monitorstatusx (ms) table for the datex, but it doesn't use it. Is it > possible to create an index to prevent this sort? >=20 > Thanks, > Michael >=20 >=20 > Michael Mattox > cunparis@yahoo.fr / http://www.advweb.com/michael >=20 >=20 >=20 >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-/QG6TYDtMAHPfbV+e0Sb Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD4DBQA++Y1r6DETLow6vwwRAridAJY201Vf1kqnJch5pRMVlr+A9nn8AJ0Ydjnl RThYtKm5JZJu5kdjgcddMg== =yRh/ -----END PGP SIGNATURE----- --=-/QG6TYDtMAHPfbV+e0Sb-- From pgsql-performance-owner@postgresql.org Wed Jun 25 09:00:49 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1BA7F30FB82 for ; Wed, 25 Jun 2003 12:00:48 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 22193-10 for ; Wed, 25 Jun 2003 09:00:37 -0300 (ADT) Received: from mwinf0304.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.28]) by svr1.postgresql.org (Postfix) with ESMTP id 1A59A30FAD4 for ; Wed, 25 Jun 2003 09:00:36 -0300 (ADT) Received: from Paris (unknown [80.15.41.168]) by mwinf0304.wanadoo.fr (SMTP Server) with ESMTP id 69DB3A80411A; Wed, 25 Jun 2003 14:00:35 +0200 (CEST) Reply-To: From: "Michael Mattox" To: "Rod Taylor" Cc: "Postgresql Performance" Subject: Re: How to optimize monstrous query, sorts instead of using index Date: Wed, 25 Jun 2003 14:00:39 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal In-Reply-To: <1056542059.69651.73.camel@jester> X-Archive-Number: 200306/158 X-Sequence-Number: 2242 Sorry, I neglected to say the version, yes I'm using Postgres 7.3.2 on Linux. Here's the output of explain analyze. The query typically takes 0-4 seconds depending on the time frame. It's run very frequently especially to process the nightly reports. veriguard=# explain analyze select ms.averageconnecttimex as ms_averageconnecttime, ms.averagedurationx as ms_averageduration, ms.datex as ms_date, ms.idx as ms_id, ms.statusstringx as ms_statusstring, ms.statusx as ms_status, msi.actualcontentx as msi_actualcontent, msi.connecttimex as msi_connecttime, msi.correctcontentx as msi_correctcontent, msi.datex as msi_date, msi.descriptionx as msi_description, msi.durationx as msi_duration, msi.errorcontentx as msi_errorcontent, msi.idx as msi_id, msi.monitorlocationx as msi_monitorlocation, msi.statusstringx as msi_statusstring, msi.statusx as msi_status from monitorstatusx ms, monitorstatusitemx msi where monitorx.idx = 'M-TEST_1444-TEST_00_10560561260561463219352' AND monitorx.jdoidx = ms.monitorx AND ms.datex >= '2003-06-20 08:57:21.36' AND ms.datex <= '2003-06-29 08:57:21.36' AND ms.jdoidx = monitorstatus_statusitemsx.jdoidx AND monitorstatus_statusitemsx.statusitemsx = monitorstatusitemlistd8ea58a5x.jdoidx AND monitorstatusitemlistd8ea58a5x.statusitemlistx = msi.jdoidx ORDER BY ms_date DESC; QUERY PLAN ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ---------------------------- Sort (cost=9498.96..9500.27 rows=525 width=788) (actual time=6720.91..6721.44 rows=623 loops=1) Sort Key: ms.datex -> Nested Loop (cost=0.00..9475.26 rows=525 width=788) (actual time=145.16..6718.65 rows=623 loops=1) -> Nested Loop (cost=0.00..7887.69 rows=525 width=123) (actual time=126.84..4528.85 rows=623 loops=1) -> Nested Loop (cost=0.00..6300.13 rows=525 width=107) (actual time=95.37..3470.55 rows=623 loops=1) -> Nested Loop (cost=0.00..4712.13 rows=525 width=91) (actual time=40.44..1892.06 rows=625 loops=1) -> Index Scan using monitorx_id_index on monitorx (cost=0.00..5.48 rows=1 width=8) (actual time=0.25..19.90 rows=1 loops=1) Index Cond: (idx = 'M-TEST_1444-TEST_00_10560561260561463219352'::character varying) -> Index Scan using monitorstatusxmonitori on monitorstatusx ms (cost=0.00..4695.65 rows=880 width=83) (actual time=40.17..1868.12 rows=625 loops=1) Index Cond: ("outer".jdoidx = ms.monitorx) Filter: ((datex >= '2003-06-20 08:57:21.36'::timestamp without time zone) AND (datex <= '2003-06-29 08:57:21.36'::timestamp without time zone)) -> Index Scan using monitorstatus_stjdoidb742c9b3i on monitorstatus_statusitemsx (cost=0.00..3.01 rows=1 width=16) (actual time=2.51..2.51 rows=1 loops=625) Index Cond: ("outer".jdoidx = monitorstatus_statusitemsx.jdoidx) -> Index Scan using monitorstatusitejdoid7db0befci on monitorstatusitemlistd8ea58a5x (cost=0.00..3.01 rows=1 width=16) (actual time=1.68..1.69 rows=1 loops=623) Index Cond: ("outer".statusitemsx = monitorstatusitemlistd8ea58a5x.jdoidx) -> Index Scan using monitorstatusitemx_pkey on monitorstatusitemx msi (cost=0.00..3.01 rows=1 width=665) (actual time=3.50..3.50 rows=1 loops=623) Index Cond: ("outer".statusitemlistx = msi.jdoidx) Total runtime: 6722.43 msec (18 rows) From pgsql-performance-owner@postgresql.org Wed Jun 25 09:12:13 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 3F8B330FB6F for ; Wed, 25 Jun 2003 12:12:08 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 26187-09 for ; Wed, 25 Jun 2003 09:11:57 -0300 (ADT) Received: from tomts11-srv.bellnexxia.net (tomts11.bellnexxia.net [209.226.175.55]) by svr1.postgresql.org (Postfix) with ESMTP id 90CC230ECF0 for ; Wed, 25 Jun 2003 09:11:52 -0300 (ADT) Received: from [192.168.1.200] ([216.209.81.133]) by tomts11-srv.bellnexxia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20030625121150.IHIF11106.tomts11-srv.bellnexxia.net@[192.168.1.200]>; Wed, 25 Jun 2003 08:11:50 -0400 Subject: Re: How to optimize monstrous query, sorts instead of From: Rod Taylor To: michael.mattox@verideon.com Cc: Postgresql Performance In-Reply-To: References: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-P3a7PTZtrI2Y3WlL8mjs" Message-Id: <1056543129.69651.82.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.0 Date: 25 Jun 2003 08:12:09 -0400 X-Archive-Number: 200306/159 X-Sequence-Number: 2243 --=-P3a7PTZtrI2Y3WlL8mjs Content-Type: text/plain Content-Transfer-Encoding: quoted-printable > Here's the output of explain analyze. The query typically takes 0-4 seco= nds > depending on the time frame. It's run very frequently especially to proc= ess > the nightly reports. The plan picked seems reasonable (estimated costs / tuples is close to actual). I think the biggest hit is this index scan. Thats a substantial cost to pull out less than a thousand lines: -> Index Scan using monitorstatusxmonitori on monitorstatusx ms (cost=3D0.00..4695.65 rows=3D880 width=3D83) (actual time=3D40.17..1868.12 rows=3D625 loops=3D1) Index Cond: ("outer".jdoidx =3D ms.monitorx) Filter: ((datex >=3D '2003-06-20 08:57:21.36'::timestamp without time zone) AND (datex <=3D '2003-06-29 08:57:21.36'::timestamp without time zone)) Are jdoidx and monitorx integers? You might try a multi-column index on (ms.monitorx, ms.datex). Are monitorx assigned roughly ordered by date? It must be, otherwise the sort step would not be so cheap (hardly any impact on the query -- see actual cost number). The multi-column index above should give you a bit of a boost. Depending on the data in the table, the index (ms.datex, monitorx) may give better results along with a single index on (ms.monitorx) as you currently have. It's not very likely though. --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-P3a7PTZtrI2Y3WlL8mjs Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA++ZGY6DETLow6vwwRAgkkAJ4+eIEVghwMdvycwKFiMMY9L6c+agCeKKL0 M5M19SZ7urYrmgJptI4Msbg= =Lvsm -----END PGP SIGNATURE----- --=-P3a7PTZtrI2Y3WlL8mjs-- From pgsql-performance-owner@postgresql.org Wed Jun 25 09:48:24 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 8007B30FB66 for ; Wed, 25 Jun 2003 12:48:23 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 31487-09 for ; Wed, 25 Jun 2003 09:48:13 -0300 (ADT) Received: from mwinf0303.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.28]) by svr1.postgresql.org (Postfix) with ESMTP id 8E60D30EA95 for ; Wed, 25 Jun 2003 09:48:12 -0300 (ADT) Received: from Paris (unknown [80.15.41.168]) by mwinf0303.wanadoo.fr (SMTP Server) with ESMTP id 101A650008E2; Wed, 25 Jun 2003 14:48:12 +0200 (CEST) Reply-To: From: "Michael Mattox" To: "Rod Taylor" Cc: "Postgresql Performance" Subject: Re: How to optimize monstrous query, sorts instead of Date: Wed, 25 Jun 2003 14:48:15 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal In-Reply-To: <1056543129.69651.82.camel@jester> X-Archive-Number: 200306/160 X-Sequence-Number: 2244 > Are jdoidx and monitorx integers? Yes both are integers: -- Table: public.monitorstatusx CREATE TABLE public.monitorstatusx ( averageconnecttimex numeric(65535, 65532), averagedurationx numeric(65535, 65532), datex timestamp, idx varchar(255), jdoclassx varchar(255), jdoidx int8 NOT NULL, jdolockx int4, monitorx int8, statusstringx varchar(255), statusx varchar(255), CONSTRAINT monitorstatusx_pkey PRIMARY KEY (jdoidx) ) WITH OIDS; > You might try a multi-column index on (ms.monitorx, ms.datex). Just tried it, it didn't prevent the sort. But it sounds like the sort isn't the problem, correct? -- Index: public.monitorstatusx_datex_monitorx_index CREATE INDEX monitorstatusx_datex_monitorx_index ON monitorstatusx USING btree (monitorx, datex); veriguard=# explain analyze select ms.averageconnecttimex as ms_averageconnecttime, ms.averagedurationx as ms_averageduration, ms.datex as ms_date, ms.idx as ms_id, ms.statusstringx as ms_statusstring, ms.statusx as ms_status, msi.actualcontentx as msi_actualcontent, msi.connecttimex as msi_connecttime, msi.correctcontentx as msi_correctcontent, msi.datex as msi_date, msi.descriptionx as msi_description, msi.durationx as msi_duration, msi.errorcontentx as msi_errorcontent, msi.idx as msi_id, msi.monitorlocationx as msi_monitorlocation, msi.statusstringx as msi_statusstring, msi.statusx as msi_status from monitorstatusx ms, monitorstatusitemx msi where monitorx.idx = 'M-TEST_1444-TEST_00_10560561260561463219352' AND monitorx.jdoidx = ms.monitorx AND ms.datex >= '2003-06-20 08:57:21.36' AND ms.datex <= '2003-06-29 08:57:21.36' AND ms.jdoidx = monitorstatus_statusitemsx.jdoidx AND monitorstatus_statusitemsx.statusitemsx = monitorstatusitemlistd8ea58a5x.jdoidx AND monitorstatusitemlistd8ea58a5x.statusitemlistx = msi.jdoidx ORDER BY ms_date DESC; QUERY PLAN ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ---------------------------------------------------------------------- Sort (cost=6014.53..6015.86 rows=529 width=788) (actual time=4286.35..4286.88 rows=626 loops=1) Sort Key: ms.datex -> Nested Loop (cost=0.00..5990.59 rows=529 width=788) (actual time=131.57..4283.76 rows=626 loops=1) -> Nested Loop (cost=0.00..4388.44 rows=529 width=123) (actual time=106.23..3398.54 rows=626 loops=1) -> Nested Loop (cost=0.00..2786.29 rows=529 width=107) (actual time=90.29..2518.20 rows=626 loops=1) -> Nested Loop (cost=0.00..1175.81 rows=532 width=91) (actual time=55.15..1345.88 rows=628 loops=1) -> Index Scan using monitorx_id_index on monitorx (cost=0.00..5.36 rows=1 width=8) (actual time=54.94..55.03 rows=1 loops=1) Index Cond: (idx = 'M-TEST_1444-TEST_00_10560561260561463219352'::character varying) -> Index Scan using monitorstatusx_datex_monitorx_index on monitorstatusx ms (cost=0.00..1159.33 rows=890 width=83) (actual time=0.19..1287.02 rows=628 loops=1) Index Cond: (("outer".jdoidx = ms.monitorx) AND (ms.datex >= '2003-06-20 08:57:21.36'::timestamp without time zone) AND (ms.datex <= '2003-06-29 08:57:21.36'::timestamp without time zone)) -> Index Scan using monitorstatus_stjdoidb742c9b3i on monitorstatus_statusitemsx (cost=0.00..3.01 rows=1 width=16) (actual time=1.85..1.86 rows=1 loops=628) Index Cond: ("outer".jdoidx = monitorstatus_statusitemsx.jdoidx) -> Index Scan using monitorstatusitejdoid7db0befci on monitorstatusitemlistd8ea58a5x (cost=0.00..3.01 rows=1 width=16) (actual time=1.39..1.39 rows=1 loops=626) Index Cond: ("outer".statusitemsx = monitorstatusitemlistd8ea58a5x.jdoidx) -> Index Scan using monitorstatusitemx_pkey on monitorstatusitemx msi (cost=0.00..3.01 rows=1 width=665) (actual time=1.40..1.40 rows=1 loops=626) Index Cond: ("outer".statusitemlistx = msi.jdoidx) Total runtime: 4288.71 msec (17 rows) veriguard=# > Are monitorx assigned roughly ordered by date? It must be, otherwise > the sort step would not be so cheap (hardly any impact on the query -- > see actual cost number). The multi-column index above should give you a > bit of a boost. monitorx is a foreign key to the monitorx table. If the query can't be optimized it's OK, I can live it the speed. I just couldn't figure out why it'd sort on datex if I had an index on datex. Thanks, Michael From pgsql-performance-owner@postgresql.org Wed Jun 25 10:03:09 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id AD10830FB6A for ; Wed, 25 Jun 2003 13:03:06 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 37388-05 for ; Wed, 25 Jun 2003 10:02:56 -0300 (ADT) Received: from server1.techplant.com (unknown [209.61.173.33]) by svr1.postgresql.org (Postfix) with ESMTP id E02A830FB77 for ; Wed, 25 Jun 2003 10:02:55 -0300 (ADT) Received: from localhost (michael@localhost) by server1.techplant.com (8.11.6/8.11.6) with ESMTP id h5PD4Va22016 for ; Wed, 25 Jun 2003 09:04:32 -0400 Date: Wed, 25 Jun 2003 09:04:31 -0400 (EDT) From: pgsql@newtopia.com X-X-Sender: michael@server1.techplant.com To: Postgresql Performance Subject: Re: Performance advice In-Reply-To: Message-ID: X-Mailkey: j9dfjk23j4dkq MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200306/161 X-Sequence-Number: 2245 On Wed, 25 Jun 2003, Achilleus Mantzios wrote: > What i think would be ideal (helpful/feasible) > is some kind of documentation of the algorithms involved > in the planner/optimizer, along with some pointers > to postgresql.conf parameters where applicable. > > This way we will know > - Why something is happening > - If it is the best plan > - What tuning is possible I agree. In combination with this, I would find case studies very useful. Have the documentation team solicit a few volunteers with different setups (w/r/t db size, db traffic, and hardware). Perhaps these folks are running with the default postgresql.conf or have done little tuning. Via the performance list, work through the tuning process with each volunteer: 1. Gathering information about your setup that affects tuning. 2. Measuring initial performance as a baseline. 3. Making initial adjustments based on your setup. 4. Identifying poorly-written SQL. 5. Identifying poorly-indexed tables. 6. Measuring effects of each adjustment, and tuning accordingly. (Note: I am certainly no performance expert -- these steps are meant to be examples only.) Solicit a list member to monitor the discussion and document each case study in a consistent fashion. Run completed case studies by the performance and docs lists for review. I would be happy to join the docs team to work on such a project. michael p.s. Should this discussion be moved to psgql-docs? From pgsql-performance-owner@postgresql.org Wed Jun 25 10:35:54 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 17CCD30DD20 for ; Wed, 25 Jun 2003 13:35:53 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 37388-10 for ; Wed, 25 Jun 2003 10:35:42 -0300 (ADT) Received: from tomts5-srv.bellnexxia.net (tomts5.bellnexxia.net [209.226.175.25]) by svr1.postgresql.org (Postfix) with ESMTP id 4FBA530FB81 for ; Wed, 25 Jun 2003 10:35:42 -0300 (ADT) Received: from [10.0.2.10] ([216.208.117.7]) by tomts5-srv.bellnexxia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20030625133542.NPEC23206.tomts5-srv.bellnexxia.net@[10.0.2.10]>; Wed, 25 Jun 2003 09:35:42 -0400 Subject: Re: How to optimize monstrous query, sorts instead of From: Rod Taylor To: michael.mattox@verideon.com Cc: Postgresql Performance In-Reply-To: References: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-jpw/uoCwjEmenDtiuz7j" Message-Id: <1056548165.25587.23.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.0 Date: 25 Jun 2003 09:36:06 -0400 X-Archive-Number: 200306/162 X-Sequence-Number: 2246 --=-jpw/uoCwjEmenDtiuz7j Content-Type: text/plain Content-Transfer-Encoding: quoted-printable > > You might try a multi-column index on (ms.monitorx, ms.datex). >=20 > Just tried it, it didn't prevent the sort. But it sounds like the sort > isn't the problem, correct? The sort isn't actually doing any sorting, so it's virtually free. The sort is taking less than 3ms as the data is already 99% sorted due to the correlation between datex and monitorx. For similar reasons, the datex index will not be used, as it has no advantage to being used. > -> Index Scan using > monitorstatusx_datex_monitorx_index on monitorstatusx ms > (cost=3D0.00..1159.33 rows=3D890 width=3D83) (actual time=3D0.19..1287.02= rows=3D628 > loops=3D1) > Index Cond: (("outer".jdoidx =3D ms.moni= torx) > AND (ms.datex >=3D '2003-06-20 08:57:21.36'::timestamp without time zone)= AND > (ms.datex <=3D '2003-06-29 08:57:21.36'::timestamp without time zone)) You can see that it used the new multi-key index for both items, rather than finding for monitorx, then filtering out unwanted results by datex. It doesn't appear to have made much difference (looks like data was partially cached for this new run), but it changed a bit for the better. I'm afraid thats the best I can do on the query itself I think. Oh, and using tables in your where clause that aren't in the from clause is non-portable and often hides bugs: from monitorstatusx ms , monitorstatusitemx msi where monitorx.idx =3D 'M-TEST_1444-TEST_00_10560561260561463219352' Are you sure you sure you don't have any duplicated constraints by pulling information in from other tables that you don't need to?=20 Removing some of those nested loops would make a significant impact to the results. --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-jpw/uoCwjEmenDtiuz7j Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA++aVF6DETLow6vwwRAlDkAJ4wxNIxrf+J6rqefK3Xi1hTfWN2pQCfShR+ dHGdJ8TUvcgZc4/4u8LY2bg= =SUnl -----END PGP SIGNATURE----- --=-jpw/uoCwjEmenDtiuz7j-- From pgsql-performance-owner@postgresql.org Wed Jun 25 11:10:35 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 6A89930FC4B for ; Wed, 25 Jun 2003 14:10:27 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 45901-04 for ; Wed, 25 Jun 2003 11:09:56 -0300 (ADT) Received: from mwinf0301.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.28]) by svr1.postgresql.org (Postfix) with ESMTP id 104A630FB70 for ; Wed, 25 Jun 2003 11:09:55 -0300 (ADT) Received: from Paris (ABoulogne-110-1-3-168.w80-15.abo.wanadoo.fr [80.15.41.168]) by mwinf0301.wanadoo.fr (SMTP Server) with ESMTP id 795744007BA; Wed, 25 Jun 2003 16:09:54 +0200 (CEST) Reply-To: From: "Michael Mattox" To: "Rod Taylor" Cc: "Postgresql Performance" Subject: Re: How to optimize monstrous query, sorts instead of Date: Wed, 25 Jun 2003 16:09:59 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal In-Reply-To: <1056548165.25587.23.camel@jester> X-Archive-Number: 200306/163 X-Sequence-Number: 2247 > Oh, and using tables in your where clause that aren't in the from clause > is non-portable and often hides bugs: > > from monitorstatusx ms > , monitorstatusitemx msi > where monitorx.idx = 'M-TEST_1444-TEST_00_10560561260561463219352' > > Are you sure you sure you don't have any duplicated constraints by > pulling information in from other tables that you don't need to? > Removing some of those nested loops would make a significant impact to > the results. I didn't notice that before, thanks for pointing that out. I just tried adding monitorx.idx to the select and it ended up making my query take several minutes long. Any ideas how I can fix this and keep my performance? new query: veriguard=# explain select m.idx, ms.averageconnecttimex as ms_averageconnecttime, ms.averagedurationx as ms_averageduration, ms.datex as ms_date, ms.idx as ms_id, ms.statusstringx as ms_statusstring, ms.statusx as ms_status, msi.actualcontentx as msi_actualcontent, msi.connecttimex as msi_connecttime, msi.correctcontentx as msi_correctcontent, msi.datex as msi_date, msi.descriptionx as msi_description, msi.durationx as msi_duration, msi.errorcontentx as msi_errorcontent, msi.idx as msi_id, msi.monitorlocationx as msi_monitorlocation, msi.statusstringx as msi_statusstring, msi.statusx as msi_status from monitorx m, monitorstatusx ms, monitorstatusitemx msi where m.idx = 'M-TEST_1444-TEST_00_10560561260561463219352' AND monitorx.jdoidx = ms.monitorx AND ms.datex >= '2003-06-20 08:57:21.36' AND ms.datex <= '2003-06-29 08:57:21.36' AND ms.jdoidx = monitorstatus_statusitemsx.jdoidx AND monitorstatus_statusitemsx.statusitemsx = monitorstatusitemlistd8ea58a5x.jdoidx AND monitorstatusitemlistd8ea58a5x.statusitemlistx = msi.jdoidx ORDER BY ms_date DESC; QUERY PLAN ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ------------------------------------- Sort (cost=1653384.42..1655402.97 rows=807418 width=826) Sort Key: ms.datex -> Hash Join (cost=820308.66..1112670.42 rows=807418 width=826) Hash Cond: ("outer".monitorx = "inner".jdoidx) -> Merge Join (cost=820132.71..1098364.65 rows=807418 width=780) Merge Cond: ("outer".jdoidx = "inner".statusitemlistx) -> Index Scan using monitorstatusitemx_pkey on monitorstatusitemx msi (cost=0.00..247616.27 rows=6596084 width=665) -> Sort (cost=820132.71..822151.59 rows=807554 width=115) Sort Key: monitorstatusitemlistd8ea58a5x.statusitemlistx -> Hash Join (cost=461310.87..685820.13 rows=807554 width=115) Hash Cond: ("outer".jdoidx = "inner".statusitemsx) -> Seq Scan on monitorstatusitemlistd8ea58a5x (cost=0.00..104778.90 rows=6597190 width=16) -> Hash (cost=447067.98..447067.98 rows=807554 width=99) -> Merge Join (cost=0.00..447067.98 rows=807554 width=99) Merge Cond: ("outer".jdoidx = "inner".jdoidx) -> Index Scan using monitorstatusx_pkey on monitorstatusx ms (cost=0.00..272308.56 rows=811754 width=83) Filter: ((datex >= '2003-06-20 08:57:21.36'::timestamp without time zone) AND (datex <= '2003-06-29 08:57:21.36'::timestamp without time zone)) -> Index Scan using monitorstatus_stjdoidb742c9b3i on monitorstatus_statusitemsx (cost=0.00..146215.58 rows=6596680 width=16) -> Hash (cost=172.22..172.22 rows=1493 width=46) -> Nested Loop (cost=0.00..172.22 rows=1493 width=46) -> Index Scan using monitorx_id_index on monitorx m (cost=0.00..5.36 rows=1 width=38) Index Cond: (idx = 'M-TEST_1444-TEST_00_10560561260561463219352'::character varying) -> Seq Scan on monitorx (cost=0.00..151.93 rows=1493 width=8) (23 rows) old query: veriguard=# explain select ms.averageconnecttimex as ms_averageconnecttime, ms.averagedurationx as ms_averageduration, ms.datex as ms_date, ms.idx as ms_id, ms.statusstringx as ms_statusstring, ms.statusx as ms_status, msi.actualcontentx as msi_actualcontent, msi.connecttimex as msi_connecttime, msi.correctcontentx as msi_correctcontent, msi.datex as msi_date, msi.descriptionx as msi_description, msi.durationx as msi_duration, msi.errorcontentx as msi_errorcontent, msi.idx as msi_id, msi.monitorlocationx as msi_monitorlocation, msi.statusstringx as msi_statusstring, msi.statusx as msi_status from monitorstatusx ms, monitorstatusitemx msi where monitorx.idx = 'M-TEST_1444-TEST_00_10560561260561463219352' AND monitorx.jdoidx = ms.monitorx AND ms.datex >= '2003-06-20 08:57:21.36' AND ms.datex <= '2003-06-29 08:57:21.36' AND ms.jdoidx = monitorstatus_statusitemsx.jdoidx AND monitorstatus_statusitemsx.statusitemsx = monitorstatusitemlistd8ea58a5x.jdoidx AND monitorstatusitemlistd8ea58a5x.statusitemlistx = msi.jdoidx ORDER BY ms_date DESC; QUERY PLAN ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ------------------------- Sort (cost=9590.52..9591.87 rows=541 width=788) Sort Key: ms.datex -> Nested Loop (cost=0.00..9565.97 rows=541 width=788) -> Nested Loop (cost=0.00..7929.22 rows=541 width=123) -> Nested Loop (cost=0.00..6292.48 rows=541 width=107) -> Nested Loop (cost=0.00..4647.22 rows=544 width=91) -> Index Scan using monitorx_id_index on monitorx (cost=0.00..5.36 rows=1 width=8) Index Cond: (idx = 'M-TEST_1444-TEST_00_10560561260561463219352'::character varying) -> Index Scan using monitorstatusxmonitori on monitorstatusx ms (cost=0.00..4630.29 rows=926 width=83) Index Cond: ("outer".jdoidx = ms.monitorx) Filter: ((datex >= '2003-06-20 08:57:21.36'::timestamp without time zone) AND (datex <= '2003-06-29 08:57:21.36'::timestamp without time zone)) -> Index Scan using monitorstatus_stjdoidb742c9b3i on monitorstatus_statusitemsx (cost=0.00..3.01 rows=1 width=16) Index Cond: ("outer".jdoidx = monitorstatus_statusitemsx.jdoidx) -> Index Scan using monitorstatusitejdoid7db0befci on monitorstatusitemlistd8ea58a5x (cost=0.00..3.01 rows=1 width=16) Index Cond: ("outer".statusitemsx = monitorstatusitemlistd8ea58a5x.jdoidx) -> Index Scan using monitorstatusitemx_pkey on monitorstatusitemx msi (cost=0.00..3.01 rows=1 width=665) Index Cond: ("outer".statusitemlistx = msi.jdoidx) (17 rows) veriguard=# From pgsql-performance-owner@postgresql.org Wed Jun 25 11:22:40 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id A8FC030DD20 for ; Wed, 25 Jun 2003 14:22:39 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 47870-07 for ; Wed, 25 Jun 2003 11:22:29 -0300 (ADT) Received: from mail.deltav.hu (oldmail.deltav.hu [213.163.0.192]) by svr1.postgresql.org (Postfix) with ESMTP id B8B5C30FC2E for ; Wed, 25 Jun 2003 11:22:28 -0300 (ADT) Received: from fejleszt4 ([213.163.10.103]) by mail.deltav.hu (Netscape Messaging Server 3.6) with SMTP id AAA6B89 for ; Wed, 25 Jun 2003 16:15:09 +0200 Message-ID: <008e01c33b24$49f091b0$0403a8c0@fejleszt4> From: =?ISO-8859-1?Q?SZUCS_G=E1bor?= To: References: Subject: Re: How to optimize monstrous query, sorts instead of using index Date: Wed, 25 Jun 2003 16:15:53 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Archive-Number: 200306/164 X-Sequence-Number: 2248 Michael, This whole query looks like a mess to me. Since I don't know the exact model and the table stats, I don't even try to rewrite your query, however, here are the weak points I can think of: * as Rod pointed out, there are more tables in WHERE that aren't in FROM. This can be a bug, but the very least, it makes the query far less readable. These are: monitorx monitorstatus_statusitemsx.jdoidx monitorstatusitemlistd8ea58a5x.jdoidx * there are 3 index scans that basically steal your time. They are 1.6..3.5 ms x 625 ~ 1..2 sec each (or I'm reading exp ana wrong, I'm not an expert indeed): - Index Scan using monitorstatus_stjdoidb742c9b3i on monitorstatus_statusitemsx (cost=0.00..3.01 rows=1 width=16) (actual time=2.51..2.51 rows=1 loops=625) Index Cond: ("outer".jdoidx = monitorstatus_statusitemsx.jdoidx) - Index Scan using monitorstatusitejdoid7db0befci on monitorstatusitemlistd8ea58a5x (cost=0.00..3.01 rows=1 width=16) (actual time=1.68..1.69 rows=1 loops=623) Index Cond: ("outer".statusitemsx = monitorstatusitemlistd8ea58a5x.jdoidx) - Index Scan using monitorstatusitemx_pkey on monitorstatusitemx msi (cost=0.00..3.01 rows=1 width=665) (actual time=3.50..3.50 rows=1 loops=623) Index Cond: ("outer".statusitemlistx = msi.jdoidx) * another killer index: I think this one takes about the rest of the time (i.e. 3-4 secs): -> Index Scan using monitorstatusxmonitori on monitorstatusx ms (cost=0.00..4695.65 rows=880 width=83) (actual time=40.17..1868.12 rows=625 loops=1) Index Cond: ("outer".jdoidx = ms.monitorx) Filter: ((datex >= '2003-06-20 08:57:21.36'::timestamp without time zone) AND (datex <= '2003-06-29 08:57:21.36'::timestamp without time zone)) Since the number of rows probably can't be reduced (as I read it, the query actually returned that many rows), I'd think about clever joins in the FROM part and fewer tables, to use fewer index scans. Finally, decided to do an ad-hoc adjustment. Try this, or (wild guess) try to completely eliminate the WHERE part by subselects on ms and monitorx. This may be faster, slower, or even give different results, based on whether I guessed the 1:N relationships right or not. G. ------------------------------- cut here ------------------------------- select ms.averageconnecttimex as ms_averageconnecttime, ms.averagedurationx as ms_averageduration, ms.datex as ms_date, ms.idx as ms_id, ms.statusstringx as ms_statusstring, ms.statusx as ms_status, msi.actualcontentx as msi_actualcontent, msi.connecttimex as msi_connecttime, msi.correctcontentx as msi_correctcontent, msi.datex as msi_date, msi.descriptionx as msi_description, msi.durationx as msi_duration, msi.errorcontentx as msi_errorcontent, msi.idx as msi_id, msi.monitorlocationx as msi_monitorlocation, msi.statusstringx as msi_statusstring, msi.statusx as msi_status from monitorstatusx ms LEFT JOIN monitorx ON (monitorx.jdoidx = ms.monitorx) LEFT JOIN monitorstatus_statusitemsx ms_si ON (ms.jdoidx = ms_si.jdoidx) LEFT JOIN monitorstatusitemlistd8ea58a5x msil ON (ms_si.statusitemsx = msil.jdoidx) LEFT JOIN monitorstatusitemx msi ON (msil.statusitemlistx = msi.jdoidx) where monitorx.idx = 'M-TEST_1444-TEST_00_10560561260561463219352' ms.datex >= '2003-06-20 08:57:21.36' AND ms.datex <= '2003-06-29 08:57:21.36' ------------------------------- cut here ------------------------------- From pgsql-performance-owner@postgresql.org Wed Jun 25 11:30:56 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 4B75330FC19 for ; Wed, 25 Jun 2003 14:30:56 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 48936-04 for ; Wed, 25 Jun 2003 11:30:45 -0300 (ADT) Received: from mail.deltav.hu (oldmail.deltav.hu [213.163.0.192]) by svr1.postgresql.org (Postfix) with ESMTP id 8293230FC07 for ; Wed, 25 Jun 2003 11:30:43 -0300 (ADT) Received: from fejleszt4 ([213.163.10.103]) by mail.deltav.hu (Netscape Messaging Server 3.6) with SMTP id AAAB51 for ; Wed, 25 Jun 2003 16:20:28 +0200 Message-ID: <009401c33b25$08520e90$0403a8c0@fejleszt4> From: =?ISO-8859-1?Q?SZUCS_G=E1bor?= To: References: Subject: Re: How to optimize monstrous query, sorts instead of Date: Wed, 25 Jun 2003 16:20:32 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Archive-Number: 200306/166 X-Sequence-Number: 2250 Michael, Actually, you missed an alias :) the select now returned 800k rows! (according to explain) pointed it out below. See my prev mail for more. If it's possible, try your query on a backend and look for notices like "Adding missing FROM clause for table ..." G. ------------------------------- cut here ------------------------------- ----- Original Message ----- From: "Michael Mattox" Cc: "Postgresql Performance" Sent: Wednesday, June 25, 2003 4:09 PM > from monitorx m, monitorstatusx ms, monitorstatusitemx msi > where m.idx = 'M-TEST_1444-TEST_00_10560561260561463219352' AND > monitorx.jdoidx = ms.monitorx AND ^^^^^^^^ substitute the same alias "m" here. From pgsql-performance-owner@postgresql.org Wed Jun 25 11:30:35 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 0CD6330EB94 for ; Wed, 25 Jun 2003 14:28:37 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 46480-07 for ; Wed, 25 Jun 2003 11:28:26 -0300 (ADT) Received: from mailav.tor1.inquent.com (mail.inquent.com [216.208.117.106]) by svr1.postgresql.org (Postfix) with ESMTP id 6D63B30DD20 for ; Wed, 25 Jun 2003 11:28:26 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mailav.tor1.inquent.com (Postfix) with ESMTP id 28AAF10257; Wed, 25 Jun 2003 10:21:42 -0400 (EDT) Received: from [10.0.2.10] (unknown [10.0.2.10]) by mailav.tor1.inquent.com (Postfix) with ESMTP id 3959A1024D; Wed, 25 Jun 2003 10:21:40 -0400 (EDT) Subject: Re: How to optimize monstrous query, sorts instead of From: Rod Taylor To: michael.mattox@verideon.com Cc: Postgresql Performance In-Reply-To: References: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-LHvEiE/xCZxS6sxjzJM5" Message-Id: <1056551304.25587.52.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.0 Date: 25 Jun 2003 10:28:25 -0400 X-Virus-Scanned: by AMaViS perl-11 X-Archive-Number: 200306/165 X-Sequence-Number: 2249 --=-LHvEiE/xCZxS6sxjzJM5 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable > I didn't notice that before, thanks for pointing that out. I just tried > adding monitorx.idx to the select and it ended up making my query take > several minutes long. Any ideas how I can fix this and keep my performan= ce? By using it aliased and non-aliased (2 different references to the same table) you've caused it to join itself. Try this: SELECT m.idx , ms.averageconnecttimex AS ms_averageconnecttime , ms.averagedurationx AS ms_averageduration , ms.datex AS ms_date , ms.idx AS ms_id , ms.statusstringx AS ms_statusstring , ms.statusx AS ms_status , msi.actualcontentx AS msi_actualcontent , msi.connecttimex AS msi_connecttime , msi.correctcontentx AS msi_correctcontent , msi.datex AS msi_date , msi.descriptionx AS msi_description , msi.durationx AS msi_duration , msi.errorcontentx AS msi_errorcontent , msi.idx AS msi_id , msi.monitorlocationx AS msi_monitorlocation , msi.statusstringx AS msi_statusstring , msi.statusx AS msi_status FROM monitorstatusx AS ms , monitorstatusitemx AS msi , monitorx AS mx , monitorstatus_statusitemsx AS mssisx , monitorstatusitemlistd8ea58a5x AS litem WHERE ms.jdoidx =3D mssisx.jdoidx AND mssisx.statusitemsx =3D litem.jdoidx AND litem.statusitemlistx =3D msi.jdoidx AND mx.jdoidx =3D ms.monitorx AND ms.datex BETWEEN '2003-06-20 08:57:21.36' AND '2003-06-29 08:57:21.36' AND m.idx =3D 'M-TEST_1444-TEST_00_10560561260561463219352' ORDER BY ms.datex DESC; --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-LHvEiE/xCZxS6sxjzJM5 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA++bGH6DETLow6vwwRAgrHAJ47GFg/7kg6zY36gxyEWmqhXRjoIwCfRFqw BKdXAP3pac6FQa3y0fJx2Nk= =19Ve -----END PGP SIGNATURE----- --=-LHvEiE/xCZxS6sxjzJM5-- From pgsql-performance-owner@postgresql.org Wed Jun 25 11:48:54 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1C9B130EB94 for ; Wed, 25 Jun 2003 14:48:53 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 48038-10 for ; Wed, 25 Jun 2003 11:48:42 -0300 (ADT) Received: from mwinf0302.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.28]) by svr1.postgresql.org (Postfix) with ESMTP id 371D330FAF4 for ; Wed, 25 Jun 2003 11:48:42 -0300 (ADT) Received: from Paris (unknown [80.15.41.168]) by mwinf0302.wanadoo.fr (SMTP Server) with ESMTP id 2C283C00026B; Wed, 25 Jun 2003 16:48:42 +0200 (CEST) Reply-To: From: "Michael Mattox" To: =?iso-8859-1?Q?SZUCS_G=E1bor?= , Subject: Re: How to optimize monstrous query, sorts instead of using index Date: Wed, 25 Jun 2003 16:48:46 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal In-Reply-To: <008e01c33b24$49f091b0$0403a8c0@fejleszt4> X-Archive-Number: 200306/167 X-Sequence-Number: 2251 > Finally, decided to do an ad-hoc adjustment. Try this, or (wild guess) try > to completely eliminate the WHERE part by subselects on ms and monitorx. > > This may be faster, slower, or even give different results, based > on whether > I guessed the 1:N relationships right or not. It's much slower but I appreciate you taking the time to try. I'm pretty new to SQL so I must admin this query is very confusing for me. I'm using Java Data Objects (JDO, an O/R mapping framework) but the implementation I'm using (Kodo) isn't smart enough to do all the joins efficiently, which is why I had to rewrite this query by hand. Here's the output: veriguard=# explain select ms.averageconnecttimex as ms_averageconnecttime, ms.averagedurationx as ms_averageduration, ms.datex as ms_date, ms.idx as ms_id, ms.statusstringx as ms_statusstring, ms.statusx as ms_status, msi.actualcontentx as msi_actualcontent, msi.connecttimex as msi_connecttime, msi.correctcontentx as msi_correctcontent, msi.datex as msi_date, msi.descriptionx as msi_description, msi.durationx as msi_duration, msi.errorcontentx as msi_errorcontent, msi.idx as msi_id, msi.monitorlocationx as msi_monitorlocation, msi.statusstringx as msi_statusstring, msi.statusx as msi_status from monitorstatusx ms LEFT JOIN monitorx ON (monitorx.jdoidx = ms.monitorx) LEFT JOIN monitorstatus_statusitemsx ms_si ON (ms.jdoidx = ms_si.jdoidx) LEFT JOIN monitorstatusitemlistd8ea58a5x msil ON (ms_si.statusitemsx = msil.jdoidx) LEFT JOIN monitorstatusitemx msi ON (msil.statusitemlistx = msi.jdoidx) where monitorx.idx = 'M-TEST_1444-TEST_00_10560561260561463219352' AND ms.datex >= '2003-06-20 08:57:21.36' AND ms.datex <= '2003-06-29 08:57:21.36'; QUERY PLAN ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ------------------------------------- Merge Join (cost=1006209.47..1283529.68 rows=751715 width=826) Merge Cond: ("outer".jdoidx = "inner".statusitemlistx) -> Index Scan using monitorstatusitemx_pkey on monitorstatusitemx msi (cost=0.00..247679.64 rows=6595427 width=665) -> Sort (cost=1006209.47..1008088.76 rows=751715 width=161) Sort Key: msil.statusitemlistx -> Merge Join (cost=697910.17..864079.59 rows=751715 width=161) Merge Cond: ("outer".jdoidx = "inner".statusitemsx) -> Index Scan using monitorstatusitejdoid7db0befci on monitorstatusitemlistd8ea58a5x msil (cost=0.00..136564.80 rows=6595427 width=16) -> Sort (cost=697910.17..699789.46 rows=751715 width=145) Sort Key: ms_si.statusitemsx -> Merge Join (cost=385727.49..561594.96 rows=751715 width=145) Merge Cond: ("outer".jdoidx = "inner".jdoidx) -> Index Scan using monitorstatus_stjdoidb742c9b3i on monitorstatus_statusitemsx ms_si (cost=0.00..146268.80 rows=6595427 width=16) -> Sort (cost=385727.49..387606.78 rows=751715 width=129) Sort Key: ms.jdoidx -> Hash Join (cost=155.66..255240.65 rows=751715 width=129) Hash Cond: ("outer".monitorx = "inner".jdoidx) Filter: ("inner".idx = 'M-TEST_1444-TEST_00_10560561260561463219352'::character varying) -> Seq Scan on monitorstatusx ms (cost=0.00..240050.69 rows=751715 width=83) Filter: ((datex >= '2003-06-20 08:57:21.36'::timestamp without time zone) AND (datex <= '2003-06-29 08:57:21.36'::timestamp without time zone)) -> Hash (cost=151.93..151.93 rows=1493 width=46) -> Seq Scan on monitorx (cost=0.00..151.93 rows=1493 width=46) (22 rows) veriguard=# From pgsql-performance-owner@postgresql.org Wed Jun 25 12:09:45 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id A266130FC4B for ; Wed, 25 Jun 2003 15:09:41 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 53857-08 for ; Wed, 25 Jun 2003 12:09:24 -0300 (ADT) Received: from mwinf0303.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.28]) by svr1.postgresql.org (Postfix) with ESMTP id 658AF30FC41 for ; Wed, 25 Jun 2003 12:09:18 -0300 (ADT) Received: from Paris (ABoulogne-110-1-3-168.w80-15.abo.wanadoo.fr [80.15.41.168]) by mwinf0303.wanadoo.fr (SMTP Server) with ESMTP id E55BF500083D; Wed, 25 Jun 2003 17:09:16 +0200 (CEST) Reply-To: From: "Michael Mattox" To: "Rod Taylor" Cc: "Postgresql Performance" Subject: Re: How to optimize monstrous query, sorts instead of Date: Wed, 25 Jun 2003 17:09:21 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal In-Reply-To: <1056551304.25587.52.camel@jester> X-Archive-Number: 200306/168 X-Sequence-Number: 2252 With a slight correction (you had m & mx so I changed them to be all mx, I hope this is what you intended) this query works. It's exactly the same speed, but it doesn't give me the warnings I was getting: NOTICE: Adding missing FROM-clause entry for table "monitorx" NOTICE: Adding missing FROM-clause entry for table "monitorstatus_statusitemsx" NOTICE: Adding missing FROM-clause entry for table "monitorstatusitemlistd8ea58a5x" I never knew what those were from, I even searched Google trying to find out and I couldn't understand it so I gave up. Thanks for pointing this out for me, and thanks for fixing my query. Michael > -----Original Message----- > From: pgsql-performance-owner@postgresql.org > [mailto:pgsql-performance-owner@postgresql.org]On Behalf Of Rod Taylor > Sent: Wednesday, June 25, 2003 4:28 PM > To: michael.mattox@verideon.com > Cc: Postgresql Performance > Subject: Re: [PERFORM] How to optimize monstrous query, sorts instead of > > > > I didn't notice that before, thanks for pointing that out. I just tried > > adding monitorx.idx to the select and it ended up making my query take > > several minutes long. Any ideas how I can fix this and keep my > performance? > > By using it aliased and non-aliased (2 different references to the same > table) you've caused it to join itself. > > Try this: > > SELECT m.idx > , ms.averageconnecttimex AS ms_averageconnecttime > , ms.averagedurationx AS ms_averageduration > , ms.datex AS ms_date > , ms.idx AS ms_id > , ms.statusstringx AS ms_statusstring > , ms.statusx AS ms_status > , msi.actualcontentx AS msi_actualcontent > , msi.connecttimex AS msi_connecttime > , msi.correctcontentx AS msi_correctcontent > , msi.datex AS msi_date > , msi.descriptionx AS msi_description > , msi.durationx AS msi_duration > , msi.errorcontentx AS msi_errorcontent > , msi.idx AS msi_id > , msi.monitorlocationx AS msi_monitorlocation > , msi.statusstringx AS msi_statusstring > , msi.statusx AS msi_status > > FROM monitorstatusx AS ms > , monitorstatusitemx AS msi > > , monitorx AS mx > , monitorstatus_statusitemsx AS mssisx > , monitorstatusitemlistd8ea58a5x AS litem > > WHERE ms.jdoidx = mssisx.jdoidx > AND mssisx.statusitemsx = litem.jdoidx > AND litem.statusitemlistx = msi.jdoidx > AND mx.jdoidx = ms.monitorx > AND ms.datex BETWEEN '2003-06-20 08:57:21.36' > AND '2003-06-29 08:57:21.36' > AND m.idx = 'M-TEST_1444-TEST_00_10560561260561463219352' > > ORDER BY ms.datex DESC; > > -- > Rod Taylor > > PGP Key: http://www.rbt.ca/rbtpub.asc > From pgsql-performance-owner@postgresql.org Wed Jun 25 12:55:24 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id E194430FC74 for ; Wed, 25 Jun 2003 15:55:23 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 63914-04 for ; Wed, 25 Jun 2003 12:55:13 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 7D33030FC8F for ; Wed, 25 Jun 2003 12:55:10 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5PFt9QQ003649; Wed, 25 Jun 2003 11:55:09 -0400 (EDT) To: Rod Taylor Cc: michael.mattox@verideon.com, Postgresql Performance Subject: Re: How to optimize monstrous query, sorts instead of In-reply-to: <1056548165.25587.23.camel@jester> References: <1056548165.25587.23.camel@jester> Comments: In-reply-to Rod Taylor message dated "25 Jun 2003 09:36:06 -0400" Date: Wed, 25 Jun 2003 11:55:09 -0400 Message-ID: <3648.1056556509@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/169 X-Sequence-Number: 2253 Rod Taylor writes: >> monitorstatusx_datex_monitorx_index on monitorstatusx ms >> (cost=3D0.00..1159.33 rows=3D890 width=3D83) (actual time=3D0.19..1287.02= > rows=3D628 >> loops=3D1) >> Index Cond: (("outer".jdoidx =3D ms.moni= > torx) >> AND (ms.datex >=3D '2003-06-20 08:57:21.36'::timestamp without time zone)= > AND >> (ms.datex <=3D '2003-06-29 08:57:21.36'::timestamp without time zone)) > You can see that it used the new multi-key index for both items, rather > than finding for monitorx, then filtering out unwanted results by datex. What is the column ordering of the combined index? Unless datex is the first column, there is no chance of using it to create the required sort order anyway. I think this index condition is suggesting that monitorx is the first column. However, I agree with Rod's point that "avoid the sort" is not the mindset to use to optimize this query. The joins are the problem. You might try forcing different join types (see enable_nestloop and friends) to get an idea of whether a different plan is likely to help. regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jun 25 08:30:43 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id E291D30FBF3 for ; Wed, 25 Jun 2003 11:30:40 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 26296-05 for ; Wed, 25 Jun 2003 08:30:30 -0300 (ADT) Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) by svr1.postgresql.org (Postfix) with ESMTP id 6A98F30FBDA for ; Wed, 25 Jun 2003 08:30:29 -0300 (ADT) Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h5PGWiYi006515; Wed, 25 Jun 2003 14:32:44 -0200 Received: from localhost (achill@localhost) by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id h5PGWh8Z006511; Wed, 25 Jun 2003 14:32:43 -0200 Date: Wed, 25 Jun 2003 14:32:43 -0200 (GMT+2) From: Achilleus Mantzios To: Rod Taylor Cc: michael.mattox@verideon.com, Postgresql Performance Subject: Re: Performance advice In-Reply-To: <1056539367.69651.60.camel@jester> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200306/154 X-Sequence-Number: 2238 I agree that a "directed graph"-like performance map would be difficult to be written or understood. What i think would be ideal (helpful/feasible) is some kind of documentation of the algorithms involved in the planner/optimizer, along with some pointers to postgresql.conf parameters where applicable. This way we will know - Why something is happening - If it is the best plan - What tuning is possible On 25 Jun 2003, Rod Taylor wrote: > > > I think the biggest area of confusion for me was that the various parameters > > are very briefly described and no context is given for their parameters. > > > improvements to the performance sections of the documentation would make a > > huge difference. > > Agreed.. Josh has done some work recently re-arranging things to make > them easier to find, but the content hasn't changed much. > > Thanks for your thoughts! > > -- ================================================================== Achilleus Mantzios S/W Engineer IT dept Dynacom Tankers Mngmt Nikis 4, Glyfada Athens 16610 Greece tel: +30-210-8981112 fax: +30-210-8981877 email: achill at matrix dot gatewaynet dot com mantzios at softlab dot ece dot ntua dot gr From pgsql-performance-owner@postgresql.org Wed Jun 25 13:40:00 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1948430FCA3 for ; Wed, 25 Jun 2003 16:39:57 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 72386-05 for ; Wed, 25 Jun 2003 13:39:46 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 77DEF30FC8F for ; Wed, 25 Jun 2003 13:39:40 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5PGdbQQ004032; Wed, 25 Jun 2003 12:39:37 -0400 (EDT) To: michael.mattox@verideon.com Cc: =?iso-8859-1?Q?SZUCS_G=E1bor?= , pgsql-performance@postgresql.org Subject: Re: How to optimize monstrous query, sorts instead of using index In-reply-to: References: Comments: In-reply-to "Michael Mattox" message dated "Wed, 25 Jun 2003 16:48:46 +0200" Date: Wed, 25 Jun 2003 12:39:37 -0400 Message-ID: <4031.1056559177@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/170 X-Sequence-Number: 2254 "Michael Mattox" writes: > It's much slower but I appreciate you taking the time to try. I'm pretty > new to SQL so I must admin this query is very confusing for me. I'm using > Java Data Objects (JDO, an O/R mapping framework) but the implementation I'm > using (Kodo) isn't smart enough to do all the joins efficiently, which is > why I had to rewrite this query by hand. It wasn't till I read that :-( that I noticed that you were doing nested left joins. Fooling with the join order may be your best route to a solution --- have you read http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=explicit-joins.html regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jun 25 16:26:21 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id DDF4B30E404 for ; Wed, 25 Jun 2003 19:26:20 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 84417-10 for ; Wed, 25 Jun 2003 16:26:10 -0300 (ADT) Received: from claxson.com (mx7.claxson.com [200.32.96.144]) by svr1.postgresql.org (Postfix) with ESMTP id ED60130FC25 for ; Wed, 25 Jun 2003 16:25:50 -0300 (ADT) content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 Subject: Similar querys, better execution time on worst execution plan Date: Wed, 25 Jun 2003 16:25:44 -0300 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Similar querys, better execution time on worst execution plan Thread-Index: AcM7OG6ya5F6f7RjTem7UD4TAe7kDwAFaYvA From: "Fernando Papa" To: X-Archive-Number: 200306/171 X-Sequence-Number: 2255 Hi all! I have a strange behavior with this query: SELECT c.id_contenido,p.fecha_publicacion,c.titulo_esp,c.activo,c.activo,s.= label_esp as label_sbc,p.orden ,p.tapa_spc,p.tapa_cat,p.tapa_principal,p.id_publicacion,ca.label_esp as la= bel_cat,sp.label_esp as label_spc FROM cont_contenido c ,cont_publicacion p ,cont_sbc s ,cont_cat ca ,cont_sp= c sp WHERE c.id_instalacion =3D 2 AND s.id_instalacion =3D 2 AND p.id_instalacion =3D 2 AND c.id_contenido =3D p.id_contenido AND c.id_sbc =3D s.id_sbc --AND (c.activo =3D 'S' or c.activo =3D 's') --AND (s.activo =3D 'S' or s.activo =3D 's') AND upper(c.activo) =3D 'S' AND upper(s.activo) =3D 'S' AND ca.id_instalacion =3D 2 AND sp.id_instalacion =3D 2 AND ca.id_cat =3D s.id_cat AND sp.id_spc =3D ca.id_spc ORDER BY sp.label_esp ,ca.label_esp ,p.orden This is the execution plan: Sort (cost=3D128.81..128.83 rows=3D5 width=3D189) Sort Key: sp.label_esp, ca.label_esp, p.orden -> Nested Loop (cost=3D0.00..128.76 rows=3D5 width=3D189) Join Filter: ("outer".id_contenido =3D "inner".id_contenido) -> Nested Loop (cost=3D0.00..24.70 rows=3D1 width=3D134) Join Filter: ("inner".id_spc =3D "outer".id_spc) -> Nested Loop (cost=3D0.00..22.46 rows=3D1 width=3D111) -> Nested Loop (cost=3D0.00..6.89 rows=3D1 width=3D68) Join Filter: ("inner".id_cat =3D "outer".id_cat) -> Seq Scan on cont_sbc s (cost=3D0.00..4.44 ro= ws=3D1 width=3D35) Filter: ((id_instalacion =3D 2::numeric) AN= D (upper((activo)::text) =3D 'S'::text)) -> Seq Scan on cont_cat ca (cost=3D0.00..2.31 r= ows=3D11 width=3D33) Filter: (id_instalacion =3D 2::numeric) -> Index Scan using cont_cont_cont_sbc_fk_i on cont_co= ntenido c (cost=3D0.00..15.56 rows=3D1 width=3D43) Index Cond: ((c.id_instalacion =3D 2::numeric) AN= D (c.id_sbc =3D "outer".id_sbc)) Filter: (upper((activo)::text) =3D 'S'::text) -> Seq Scan on cont_spc sp (cost=3D0.00..2.16 rows=3D6 widt= h=3D23) Filter: (id_instalacion =3D 2::numeric) -> Seq Scan on cont_publicacion p (cost=3D0.00..98.54 rows=3D442 = width=3D55) Filter: (id_instalacion =3D 2::numeric) If I replace both "uppers" with "...=3D 'S' or ...=3D 's'": SELECT c.id_contenido,p.fecha_publicacion,c.titulo_esp,c.activo,c.activo,s.= label_esp as label_sbc,p.orden ,p.tapa_spc,p.tapa_cat,p.tapa_principal,p.id_publicacion,ca.label_esp as la= bel_cat,sp.label_esp as label_spc FROM cont_contenido c ,cont_publicacion p ,cont_sbc s ,cont_cat ca ,cont_sp= c sp WHERE c.id_instalacion =3D 2 AND s.id_instalacion =3D 2 AND p.id_instalacion =3D 2 AND c.id_contenido =3D p.id_contenido AND c.id_sbc =3D s.id_sbc AND (c.activo =3D 'S' or c.activo =3D 's') AND (s.activo =3D 'S' or s.activo =3D 's') AND ca.id_instalacion =3D 2 AND sp.id_instalacion =3D 2 AND ca.id_cat =3D s.id_cat AND sp.id_spc =3D ca.id_spc ORDER BY sp.label_esp ,ca.label_esp ,p.orden This is the Execution plan: Sort (cost=3D193.98..194.62 rows=3D256 width=3D189) Sort Key: sp.label_esp, ca.label_esp, p.orden -> Merge Join (cost=3D178.07..183.75 rows=3D256 width=3D189) Merge Cond: ("outer".id_contenido =3D "inner".id_contenido) -> Sort (cost=3D60.11..60.25 rows=3D56 width=3D134) Sort Key: c.id_contenido -> Merge Join (cost=3D57.31..58.50 rows=3D56 width=3D134) Merge Cond: ("outer".id_sbc =3D "inner".id_sbc) -> Sort (cost=3D10.60..10.64 rows=3D15 width=3D91) Sort Key: s.id_sbc -> Merge Join (cost=3D10.00..10.32 rows=3D15 wi= dth=3D91) Merge Cond: ("outer".id_cat =3D "inner".id_= cat) -> Sort (cost=3D5.10..5.12 rows=3D10 widt= h=3D56) Sort Key: ca.id_cat -> Merge Join (cost=3D4.74..4.94 ro= ws=3D10 width=3D56) Merge Cond: ("outer".id_spc =3D= "inner".id_spc) -> Sort (cost=3D2.50..2.53 ro= ws=3D11 width=3D33) Sort Key: ca.id_spc -> Seq Scan on cont_cat = ca (cost=3D0.00..2.31 rows=3D11 width=3D33) Filter: (id_instala= cion =3D 2::numeric) -> Sort (cost=3D2.24..2.26 ro= ws=3D6 width=3D23) Sort Key: sp.id_spc -> Seq Scan on cont_spc = sp (cost=3D0.00..2.16 rows=3D6 width=3D23) Filter: (id_instala= cion =3D 2::numeric) -> Sort (cost=3D4.90..4.96 rows=3D21 widt= h=3D35) Sort Key: s.id_cat -> Seq Scan on cont_sbc s (cost=3D0= .00..4.44 rows=3D21 width=3D35) Filter: ((id_instalacion =3D 2:= :numeric) AND ((activo =3D 'S'::character varying) OR (activo =3D 's'::char= acter varying))) -> Sort (cost=3D46.70..46.94 rows=3D93 width=3D43) Sort Key: c.id_sbc -> Seq Scan on cont_contenido c (cost=3D0.00..4= 3.66 rows=3D93 width=3D43) Filter: ((id_instalacion =3D 2::numeric) AN= D ((activo =3D 'S'::character varying) OR (activo =3D 's'::character varyin= g))) -> Sort (cost=3D117.96..119.06 rows=3D442 width=3D55) Sort Key: p.id_contenido -> Seq Scan on cont_publicacion p (cost=3D0.00..98.54 rows= =3D442 width=3D55) Filter: (id_instalacion =3D 2::numeric) The question is, why the query with the worst execution plan (most expensiv= e, the second) runs faster the query with the better execution plan? First Query: 10 runs, avg: 8 sec. Second Query: 10 runs, avg: 1.8 sec. I see a fail on the "best" exec plan, the rows I get are around 430, so the= first EP expect only 5 rows and the second EP expect 256. I run 7.3.2 over Solaris. I did "vacuum full analyze" before=20 Thanks in advance! Fernando.- From pgsql-performance-owner@postgresql.org Wed Jun 25 18:33:37 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 70AEB30FC27 for ; Wed, 25 Jun 2003 21:33:36 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 11569-01 for ; Wed, 25 Jun 2003 18:33:25 -0300 (ADT) Received: from mail.planetpages.com (owa.planetpages.com [64.198.47.75]) by svr1.postgresql.org (Postfix) with ESMTP id 0C7A930FC07 for ; Wed, 25 Jun 2003 18:33:25 -0300 (ADT) Received: from CRMSPRAY.mcldpub.net ([10.5.19.51]) by mail.planetpages.com with Microsoft SMTPSVC(5.0.2195.2966); Wed, 25 Jun 2003 16:29:52 -0500 Received: by CRMSPRAY.mcldpub.net from localhost (router,slmail V5.1); Wed, 25 Jun 2003 16:33:22 -0500 for Received: from crmsmail.corp.ybusa.net [10.5.19.33] by CRMSPRAY.mcldpub.net [10.5.19.51] (CMSPraetor 5.10.4411) with ESMTP id 908F0ECB0AD24556A8075AE04114D589 for ; Wed, 25 Jun 2003 16:33:20 -0500 Received: by crmsmail.corp.ybusa.net with Internet Mail Service (5.5.2653.19) id ; Wed, 25 Jun 2003 16:33:20 -0500 From: "Sailer, Denis (YBUSA-CDR)" To: "'pgsql-performance@postgresql.org'" Message-ID: <58D6EF5727036048BC9E08ECB711A42092ECD0@crmsmail.corp.ybusa.net> Subject: Query running slower than same on Oracle Date: Wed, 25 Jun 2003 16:33:16 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-SLUIDL: 0B4C5CB1-1A0F42BE-A20AF08A-B667AE73 X-OriginalArrivalTime: 25 Jun 2003 21:29:52.0094 (UTC) FILETIME=[E9BDDFE0:01C33B60] X-Archive-Number: 200306/172 X-Sequence-Number: 2256 We are evaluating PostgreSQL for a typical data warehouse application. I have 3 tables below that are part of a Star schema design. The query listed below runs in 16 seconds on Oracle 9.2 and 3+ minutes on PostgreSQL 7.3.3 Here are the details. I'm wondering what else can be done to tune this type of query. Is 3 minutes reasonable given the amount of data that is loaded into the 3 tables? Is there anyone else who has made comparisons between Oracle and PostgreSQL? ---------------------------------------------------------------------------- ------------------------------------------------------------------------ Oracle 9.2 is running on a windows/2000 server, 600MHz PIII, 512MB ram Shared Pool 48MB Buffer Cache 98MB Large Pool 8MB Java Pool 32MB ========= Total SGA 186MB ---------------------------------------------------------------------------- ------------------------------------------------------------------------ PostgreSQL is running on Redhat Linux 7.2, 733MHz PIII processor, 383MB ram. shared_buffers = 12384 (96 MB) sort_mem = 16384 ---------------------------------------------------------------------------- ------------------------------------------------------------------------ explain analyze select fiscalyearquarter, description, sum(amount_quantity) from time t, revenue r, statistic s Where t.fiscalyear = 2002 and r.timekey = t.timekey and r.statisticskey = s.statisticskey group by fiscalyearquarter, description; QUERY PLAN ---------------------------------------------------------------------------- ------------------------------------------------------------------------ Aggregate (cost=124685.74..127078.87 rows=23931 width=48) (actual time=170682.53..189640.85 rows=8 loops=1) -> Group (cost=124685.74..126480.59 rows=239313 width=48) (actual time=169508.49..185478.90 rows=1082454 loops=1) -> Sort (cost=124685.74..125284.02 rows=239313 width=48) (actual time=169508.47..171853.03 rows=1082454 loops=1) Sort Key: t.fiscalyearquarter, s.description -> Hash Join (cost=6.46..94784.90 rows=239313 width=48) (actual time=140.20..47685.46 rows=1082454 loops=1) Hash Cond: ("outer".statisticskey = "inner".statisticskey) -> Hash Join (cost=5.43..90595.90 rows=239313 width=32) (actual time=139.96..39672.76 rows=1082454 loops=1) Hash Cond: ("outer".timekey = "inner".timekey) -> Seq Scan on revenue r (cost=0.00..68454.04 rows=3829004 width=17) (actual time=0.01..26336.95 rows=3829004 loops=1) -> Hash (cost=5.40..5.40 rows=12 width=15) (actual time=0.79..0.79 rows=0 loops=1) -> Seq Scan on "time" t (cost=0.00..5.40 rows=12 width=15) (actual time=0.36..0.75 rows=12 loops=1) Filter: (fiscalyear = 2002::numeric) -> Hash (cost=1.02..1.02 rows=2 width=16) (actual time=0.04..0.04 rows=0 loops=1) -> Seq Scan on statistic s (cost=0.00..1.02 rows=2 width=16) (actual time=0.02..0.03 rows=2 loops=1) Total runtime: 195409.79 msec This gives you an idea of the size of each table in the query ---------------------------------------------------------------------------- ------------------------------------------------------------------------ pubnet=# vacuum analyze verbose revenue; INFO: --Relation dw.revenue-- INFO: Pages 30164: Changed 0, Empty 0; Tup 3829004: Vac 0, Keep 0, UnUsed 17. Total CPU 1.87s/0.73u sec elapsed 9.97 sec. INFO: Analyzing dw.revenue VACUUM pubnet=# vacuum analyze verbose statistic; INFO: --Relation dw.statistic-- INFO: Pages 1: Changed 0, Empty 0; Tup 2: Vac 0, Keep 0, UnUsed 1. Total CPU 0.00s/0.00u sec elapsed 0.01 sec. INFO: Analyzing dw.statistic VACUUM pubnet=# vacuum analyze verbose time; INFO: --Relation dw.time-- INFO: Pages 3: Changed 0, Empty 0; Tup 192: Vac 0, Keep 0, UnUsed 33. Total CPU 0.00s/0.00u sec elapsed 0.02 sec. INFO: Analyzing dw.time VACUUM pubnet=# I tried to disable the use of hash join to see what might happen. This causes the optimizer to use a merge join. The timings are worse. Here is the plan for that QUERY PLAN ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -------- Aggregate (cost=665570.44..667963.57 rows=23931 width=48) (actual time=362121.97..381081.18 rows=8 loops=1) -> Group (cost=665570.44..667365.29 rows=239313 width=48) (actual time=360948.51..376904.14 rows=1082454 loops=1) -> Sort (cost=665570.44..666168.72 rows=239313 width=48) (actual time=360948.48..363285.85 rows=1082454 loops=1) Sort Key: t.fiscalyearquarter, s.description -> Merge Join (cost=631481.61..635669.60 rows=239313 width=48) (actual time=263257.77..276625.27 rows=1082454 loops=1) Merge Cond: ("outer".statisticskey = "inner".statisticskey) -> Sort (cost=631480.58..632078.86 rows=239313 width=32) (actual time=260561.38..264151.04 rows=1082454 loops=1) Sort Key: r.statisticskey -> Merge Join (cost=587963.25..610099.74 rows=239313 width=32) (actual time=217380.88..231958.36 rows=1082454 loops=1) Merge Cond: ("outer".timekey = "inner".timekey) -> Sort (cost=5.62..5.65 rows=12 width=15) (actual time=14.90..14.92 rows=12 loops=1) Sort Key: t.timekey -> Seq Scan on "time" t (cost=0.00..5.40 rows=12 width=15) (actual time=13.47..14.83 rows=12 loops=1) Filter: (fiscalyear = 2002::numeric) -> Sort (cost=587957.63..597530.14 rows=3829004 width=17) (actual time=214776.92..224634.94 rows=1455997 loops=1) Sort Key: r.timekey -> Seq Scan on revenue r (cost=0.00..68454.04 rows=3829004 width=17) (actual time=1.33..31014.95 rows=3829004 loops=1) -> Sort (cost=1.03..1.03 rows=2 width=16) (actual time=2696.35..3765.93 rows=541228 loops=1) Sort Key: s.statisticskey -> Seq Scan on statistic s (cost=0.00..1.02 rows=2 width=16) (actual time=19.50..19.52 rows=2 loops=1) Total runtime: 385939.85 msec The Query plan in Oracle looks like this... ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -------- SORT GROUP BY HASH JOIN MERGE JOIN CARTESIAN TABLE ACCESS FULL DBA_ADMIN STATISTIC BUFFER SORT TABLE ACCESS FULL DBA_ADMIN TIME TABLE ACCESS FULL DBA_ADMIN REVENUE From pgsql-performance-owner@postgresql.org Wed Jun 25 18:50:56 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id D199530FC07 for ; Wed, 25 Jun 2003 21:50:55 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 11633-05 for ; Wed, 25 Jun 2003 18:50:45 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 3D93830FCF5 for ; Wed, 25 Jun 2003 18:50:45 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5PLojQQ018326; Wed, 25 Jun 2003 17:50:45 -0400 (EDT) To: "Sailer, Denis (YBUSA-CDR)" Cc: "'pgsql-performance@postgresql.org'" Subject: Re: Query running slower than same on Oracle In-reply-to: <58D6EF5727036048BC9E08ECB711A42092ECD0@crmsmail.corp.ybusa.net> References: <58D6EF5727036048BC9E08ECB711A42092ECD0@crmsmail.corp.ybusa.net> Comments: In-reply-to "Sailer, Denis (YBUSA-CDR)" message dated "Wed, 25 Jun 2003 16:33:16 -0500" Date: Wed, 25 Jun 2003 17:50:45 -0400 Message-ID: <18325.1056577845@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/173 X-Sequence-Number: 2257 "Sailer, Denis (YBUSA-CDR)" writes: > We are evaluating PostgreSQL for a typical data warehouse application. I > have 3 tables below that are part of a Star schema design. The query listed > below runs in 16 seconds on Oracle 9.2 and 3+ minutes on PostgreSQL 7.3.3 > Here are the details. The majority of the runtime seems to be going into the sort step. There is not much to be done about this in 7.3, but 7.4 should use a hashed aggregation approach for this query, which'd eliminate the sort step and hopefully reduce the time a great deal. Since you're only doing evaluation at this point, it might be worth your while to try out CVS tip ... regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jun 25 18:52:38 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 5339D30FCFE for ; Wed, 25 Jun 2003 21:52:37 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 11058-09 for ; Wed, 25 Jun 2003 18:52:27 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id 9CE1730FC66 for ; Wed, 25 Jun 2003 18:52:26 -0300 (ADT) Received: from [66.219.92.2] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3153993; Wed, 25 Jun 2003 14:52:39 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: "Sailer, Denis (YBUSA-CDR)" , "'pgsql-performance@postgresql.org'" Subject: Re: Query running slower than same on Oracle Date: Wed, 25 Jun 2003 14:51:33 -0700 User-Agent: KMail/1.4.3 References: <58D6EF5727036048BC9E08ECB711A42092ECD0@crmsmail.corp.ybusa.net> In-Reply-To: <58D6EF5727036048BC9E08ECB711A42092ECD0@crmsmail.corp.ybusa.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200306251451.33928.josh@agliodbs.com> X-Archive-Number: 200306/174 X-Sequence-Number: 2258 Denis, > I'm wondering what else can be done to tune this type of query. Is 3 > minutes reasonable given the amount of data that is loaded into the 3 > tables? Is there anyone else who has made comparisons between Oracle and > PostgreSQL? We will probably be a bit slower on aggregates than Oracle is, for reasons= =20 discussed on this list ad nauseum. However, it also looks from the querie= s=20 like you forgot to index your foriegn keys. --=20 -Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Thu Jun 26 07:30:33 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 24CAE30FEC5 for ; Thu, 26 Jun 2003 10:30:30 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 29976-04 for ; Thu, 26 Jun 2003 07:30:19 -0300 (ADT) Received: from mail.deltav.hu (oldmail.deltav.hu [213.163.0.192]) by svr1.postgresql.org (Postfix) with ESMTP id B2E5A30FEA7 for ; Thu, 26 Jun 2003 07:30:18 -0300 (ADT) Received: from fejleszt4 ([213.163.10.103]) by mail.deltav.hu (Netscape Messaging Server 3.6) with SMTP id AAA2A16 for ; Thu, 26 Jun 2003 12:30:16 +0200 Message-ID: <001c01c33bce$090aa460$0403a8c0@fejleszt4> From: =?iso-8859-1?Q?SZUCS_G=E1bor?= To: References: Subject: Re: Similar querys, better execution time on worst execution plan Date: Thu, 26 Jun 2003 12:30:59 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Archive-Number: 200306/175 X-Sequence-Number: 2259 Fernando, 1. Try EXPLAIN ANALYZE. Cost alone isn't an absolute measure. I think it's only to see which parts of the query are expected to be slowest. However, EXP ANA will give you exact times in msec (which effectively means it executes the query). 2. I think calling upper() for each row costs more than direct comparison, but not sure 3. Notice that there are seq scans with filter conditions like "id_instalacion = 2::numeric" Do you have indices on id_instalacion, which seems to be a numeric field? if so, try casting the constant expressions in the query to numeric so that postgresql may find the index. If you don't have such indices, it may be worth to create them. (I guess you only have it on the table aliased with c, since it does an index scan there. 4. another guess may be indices on (id_instalacion, activo), or, if activo has few possible values (for example, it may be only one of three letters, say, 'S', 'A' or 'K'), partial indices like: CREATE INDEX cont_sbc_id_ins_S ON cont_sbc (id_instalacion) WHERE activo in ('S', 's'); CREATE INDEX cont_sbc_id_ins_A ON cont_sbc (id_instalacion) WHERE activo in ('A', 'a'); CREATE INDEX cont_sbc_id_ins_K ON cont_sbc (id_instalacion) WHERE activo in ('K', 'k'); G. ------------------------------- cut here ------------------------------- WHERE c.id_instalacion = 2 AND s.id_instalacion = 2 AND p.id_instalacion = 2 ... -> Seq Scan on cont_sbc s (cost=0.00..4.44 rows=1 width=35) Filter: ((id_instalacion = 2::numeric) AND (upper((activo)::text) = 'S'::text)) -> Index Scan using cont_cont_cont_sbc_fk_i on cont_contenido c (cost=0.00..15.56 rows=1 width=43) Index Cond: ((c.id_instalacion = 2::numeric) AND (c.id_sbc = "outer".id_sbc)) Filter: (upper((activo)::text) = 'S'::text) -> Seq Scan on cont_publicacion p (cost=0.00..98.54 rows=442 width=55) Filter: (id_instalacion = 2::numeric) From pgsql-performance-owner@postgresql.org Thu Jun 26 09:50:10 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id A5DE530FE70 for ; Thu, 26 Jun 2003 12:50:08 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 48111-08 for ; Thu, 26 Jun 2003 09:49:58 -0300 (ADT) Received: from email06.aon.at (WARSL402PIP3.highway.telekom.at [195.3.96.75]) by svr1.postgresql.org (Postfix) with SMTP id 53DFB30F9FA for ; Thu, 26 Jun 2003 09:49:57 -0300 (ADT) Received: (qmail 402542 invoked from network); 26 Jun 2003 12:49:55 -0000 Received: from m161p001.dipool.highway.telekom.at (HELO cantor) ([62.46.10.1]) (envelope-sender ) by qmail6rs.highway.telekom.at (qmail-ldap-1.03) with SMTP for ; 26 Jun 2003 12:49:55 -0000 From: Manfred Koizar To: Cc: Subject: Re: Performance advice Date: Thu, 26 Jun 2003 14:49:54 +0200 Message-ID: <28plfvck3q28qgipvgfjfdc9rk77b170tq@4ax.com> References: In-Reply-To: X-Mailer: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/176 X-Sequence-Number: 2260 On Wed, 25 Jun 2003 11:47:48 +0200, "Michael Mattox" wrote: >> |INFO: --Relation public.jdo_sequencex-- >> |INFO: Pages 28: Changed 1, Empty 0; Tup 1: Vac 5124, Keep 0, UnUsed 0. >> ^ ^^^^ >> This table could stand more frequent VACUUMs, every 15 minutes or so. > >Can you explain what the "Vac" is That's a long story, where shall I start? Search for MVCC in the docs and in the list archives. So you know that every DELETE and every UPDATE leaves behind old versions of tuples. The space occupied by these cannot be used immediately. VACUUM is responsible for finding dead tuples, which are so old that there is no active transaction that could be interested in their contents, and reclaiming the space. The number of such tuples is reported as "Vac". > and how you knew that it should be vacuumed more often? jdo_sequencex stores (5000 old versions and 1 active version of) a single row in 28 pages. Depending on when you did ANALYSE it and depending on the SQL statement, the planner might think that a sequential scan is the most efficient way to access this single row. A seq scan has to read 28 pages instead of a single page. Well, probably all 28 pages are in the OS cache or even in PG's shared buffers, but 27 pages are just wasted and push out pages you could make better use of. And processing those 28 pages does not come at no CPU cost. If you VACUUM frequently enough, this relation never grows beyond one page. >I'm using Java Data Objects (JDO) which is an O/R mapper. It generated the >schema from my object model by default it used a table for a sequence. I >just got finished configuring it to use a real postgres sequence. With the >way they have it designed, it opens and closes a connection each time it >retrieves a sequence. Would I get a performance increase if I modify their >code to retrieve multiple sequence numbers in one connection? For example I >could have it grab 50 at a time, which would replace 50 connections with 1. Better yet you modify the code to use the normal access functions for sequences. Servus Manfred From pgsql-performance-owner@postgresql.org Thu Jun 26 10:15:40 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id D40A830FC24 for ; Thu, 26 Jun 2003 13:15:29 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 48130-10 for ; Thu, 26 Jun 2003 10:15:19 -0300 (ADT) Received: from server.beierfeld.kabeljournal.de (pD9E1AEC9.dip.t-dialin.net [217.225.174.201]) by svr1.postgresql.org (Postfix) with SMTP id 6EA7830FC38 for ; Thu, 26 Jun 2003 10:15:17 -0300 (ADT) Received: (qmail 24209 invoked from network); 26 Jun 2003 13:15:16 -0000 Received: from station158.beierfeld.kabeljournal.de (192.168.128.158) by server.beierfeld.kabeljournal.de with SMTP; 26 Jun 2003 13:15:16 -0000 Date: Thu, 26 Jun 2003 15:15:15 +0200 From: Andre Schubert To: pgsql-performance@postgresql.org Subject: problem with pg_statistics Message-Id: <20030626151515.5fd0faf0.andre@km3.de> Organization: km3 teledienst GmbH X-Mailer: Sylpheed version 0.9.1 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/177 X-Sequence-Number: 2261 Hi, i think i need a little help with a problem with pg_statistic. Lets say i have a table to collect traffic-data. The table has a column time_stamp of type timesamptz. The table has a single-column index on time_stamp. The table has around 5 million records. If i delete all statistical data from pg_statistic and do a explain analyze i got this result. ------------------------------------------------------------------------- explain analyze select * from tbl_traffic where tbl_traffic.time_stamp >= '2003-05-01' and tbl_traffic.time_stamp < '2003-06-01'; NOTICE: QUERY PLAN: Index Scan using idx_ts on tbl_traffic (cost=0.00..97005.57 rows=24586 width=72) (actual time=0.19..7532.63 rows=1231474 loops=1) Total runtime: 8179.08 msec EXPLAIN ------------------------------------------------------------------------- after i do a vacuum full verbose analyze i got the following result. ------------------------------------------------------------------------- explain analyze select * from tbl_traffic where tbl_traffic.time_stamp >= '2003-05-01' and tbl_traffic.time_stamp < '2003-06-01'; NOTICE: QUERY PLAN: Seq Scan on tbl_traffic (cost=0.00..127224.24 rows=1197331 width=52) (actual time=0.03..14934.70 rows=1231474 loops=1) Total runtime: 15548.35 msec EXPLAIN ------------------------------------------------------------------------- now i disable seqscans with set enable_seqscan to off and i got the following. ------------------------------------------------------------------------- explain analyze select * from tbl_traffic where tbl_traffic.time_stamp >= '2003-05-01' and tbl_traffic.time_stamp < '2003-06-01'; NOTICE: QUERY PLAN: Index Scan using idx_ts on tbl_traffic (cost=0.00..3340294.11 rows=1197331 width=52) (actual time=0.21..7646.29 rows=1231474 loops=1) Total runtime: 8285.92 msec EXPLAIN ------------------------------------------------------------------------- Could anybody explain or give some hint why the index is not used although it is faster than a sequence-scan ? BTW: version ----------------------------------------------------------- PostgreSQL 7.2 on i686-pc-linux-gnu, compiled by GCC 2.96 Thanks in advance, as From pgsql-performance-owner@postgresql.org Thu Jun 26 10:33:55 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 7229830FCAA for ; Thu, 26 Jun 2003 13:33:50 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 53146-06 for ; Thu, 26 Jun 2003 10:33:40 -0300 (ADT) Received: from claxson.com (mx7.claxson.com [200.32.96.144]) by svr1.postgresql.org (Postfix) with ESMTP id 20EEE30F180 for ; Thu, 26 Jun 2003 10:33:39 -0300 (ADT) X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: Re: Similar querys, better execution time on worst execution plan Date: Thu, 26 Jun 2003 10:33:38 -0300 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PERFORM] Similar querys, better execution time on worst execution plan Thread-Index: AcM7zgE4fvngG1u4SoePTiwruaDUrwAF/jag From: "Fernando Papa" To: Cc: "Programador4" , =?iso-8859-1?Q?Nicol=E1s_Peralta?= , "Alejandro Maierowicz" X-Archive-Number: 200306/178 X-Sequence-Number: 2262 > -----Mensaje original----- > De: SZUCS G=E1bor [mailto:surrano@mailbox.hu]=20 > Enviado el: jueves, 26 de junio de 2003 7:31 > Para: pgsql-performance@postgresql.org > Asunto: Re: [PERFORM] Similar querys, better execution time=20 > on worst execution plan >=20 >=20 > Fernando, >=20 > 1. Try EXPLAIN ANALYZE. Cost alone isn't an absolute measure.=20 > I think it's only to see which parts of the query are=20 > expected to be slowest. However, EXP ANA will give you exact=20 > times in msec (which effectively means it executes the query). Ok, yes, I did only explay because I run several times the query and get av= g. run time. but it's true, it's better to do EXP ANA. =20 > 2. I think calling upper() for each row costs more than=20 > direct comparison, but not sure It's the only answer than I can found... maybe do a lot of uppers and then = compare will be too much than compare with 2 conditions... =20 > 3. Notice that there are seq scans with filter conditions like > "id_instalacion =3D 2::numeric" > Do you have indices on id_instalacion, which seems to be a=20 > numeric field? if so, try casting the constant expressions in=20 > the query to numeric so that postgresql may find the index.=20 > If you don't have such indices, it may be worth to create=20 > them. (I guess you only have it on the table aliased with c,=20 > since it does an index scan there. Yes, we have index on id_instalacion, but now we have only one instalation,= so the content of these field, in the 99% of the rows, it's 2. I think in = this case it's ok to choose seq scan. =20 > 4. another guess may be indices on (id_instalacion, activo),=20 > or, if activo has few possible values (for example, it may be=20 > only one of three letters, say, 'S', 'A' or 'K'), partial=20 > indices like: >=20 > CREATE INDEX cont_sbc_id_ins_S ON cont_sbc (id_instalacion) > WHERE activo in ('S', 's'); > CREATE INDEX cont_sbc_id_ins_A ON cont_sbc (id_instalacion) > WHERE activo in ('A', 'a'); > CREATE INDEX cont_sbc_id_ins_K ON cont_sbc (id_instalacion) > WHERE activo in ('K', 'k'); >=20 I need to recheck about the "quality" of "active" field. Really I don't kno= w if I found a lot of 'S', a lot of 'N', maybe we will have 50%/50% of 'S' = or 'N'. This will be important to define index. Thanks for your answer. From pgsql-performance-owner@postgresql.org Thu Jun 26 11:08:20 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 31D8130FE16 for ; Thu, 26 Jun 2003 14:08:20 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 64541-04 for ; Thu, 26 Jun 2003 11:08:09 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id F2E5830FF5A for ; Thu, 26 Jun 2003 11:08:08 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5QE86QQ024084; Thu, 26 Jun 2003 10:08:06 -0400 (EDT) To: Andre Schubert Cc: pgsql-performance@postgresql.org Subject: Re: problem with pg_statistics In-reply-to: <20030626151515.5fd0faf0.andre@km3.de> References: <20030626151515.5fd0faf0.andre@km3.de> Comments: In-reply-to Andre Schubert message dated "Thu, 26 Jun 2003 15:15:15 +0200" Date: Thu, 26 Jun 2003 10:08:05 -0400 Message-ID: <24083.1056636485@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/179 X-Sequence-Number: 2263 Andre Schubert writes: > i think i need a little help with a problem with pg_statistic. Try reducing random_page_cost --- although you'd be foolish to set it on the basis of just a single test query. Experiment with a few different tables, and keep in mind that repeated tests will be affected by caching. regards, tom lane From pgsql-performance-owner@postgresql.org Thu Jun 26 12:06:19 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 6140A30FF5F for ; Thu, 26 Jun 2003 15:06:06 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 65224-08 for ; Thu, 26 Jun 2003 12:05:53 -0300 (ADT) Received: from mail.deltav.hu (oldmail.deltav.hu [213.163.0.192]) by svr1.postgresql.org (Postfix) with ESMTP id 7E0AA30FF4B for ; Thu, 26 Jun 2003 12:05:52 -0300 (ADT) Received: from fejleszt4 ([213.163.10.103]) by mail.deltav.hu (Netscape Messaging Server 3.6) with SMTP id AAA2568 for ; Thu, 26 Jun 2003 17:05:49 +0200 Message-ID: <003f01c33bf4$87c41720$0403a8c0@fejleszt4> From: =?iso-8859-1?Q?SZUCS_G=E1bor?= To: References: Subject: Re: Similar querys, better execution time on worst execution plan Date: Thu, 26 Jun 2003 17:06:32 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Archive-Number: 200306/180 X-Sequence-Number: 2264 *happy* :))) G. ------------------------------- cut here ------------------------------- ----- Original Message ----- From: "Fernando Papa" Sent: Thursday, June 26, 2003 3:33 PM I need to recheck about the "quality" of "active" field. Really I don't know if I found a lot of 'S', a lot of 'N', maybe we will have 50%/50% of 'S' or 'N'. This will be important to define index. Thanks for your answer. From pgsql-performance-owner@postgresql.org Thu Jun 26 12:52:11 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id EEC5D30FF11 for ; Thu, 26 Jun 2003 15:52:09 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 71836-06 for ; Thu, 26 Jun 2003 12:51:59 -0300 (ADT) Received: from email05.aon.at (WARSL402PIP4.highway.telekom.at [195.3.96.79]) by svr1.postgresql.org (Postfix) with SMTP id F394530FF74 for ; Thu, 26 Jun 2003 12:51:58 -0300 (ADT) Received: (qmail 265152 invoked from network); 26 Jun 2003 15:51:56 -0000 Received: from m150p009.dipool.highway.telekom.at (HELO cantor) ([62.46.8.169]) (envelope-sender ) by qmail5rs.highway.telekom.at (qmail-ldap-1.03) with SMTP for ; 26 Jun 2003 15:51:56 -0000 From: Manfred Koizar To: Tom Lane Cc: Andre Schubert , pgsql-performance@postgresql.org Subject: Re: problem with pg_statistics Date: Thu, 26 Jun 2003 17:51:56 +0200 Message-ID: References: <20030626151515.5fd0faf0.andre@km3.de> <24083.1056636485@sss.pgh.pa.us> In-Reply-To: <24083.1056636485@sss.pgh.pa.us> X-Mailer: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/181 X-Sequence-Number: 2265 On Thu, 26 Jun 2003 10:08:05 -0400, Tom Lane wrote: >Andre Schubert writes: >> i think i need a little help with a problem with pg_statistic. > >Try reducing random_page_cost With index scan cost being more than 25 * seq scan cost, I guess that - all other things held equal - even random_page_cost = 1 wouldn't help. Andre might also want to experiment with effective_cache_size and with ALTER TABLE ... SET STATISTICS. Or there's something wrong with correlation? Andre, what hardware is this running on? What are the values of shared_buffers, random_page_cost, effective_cache_size, ... ? Could you show us the result of SELECT * FROM pg_stats WHERE tablename = "tbl_traffic" AND attname = "time_stamp"; Servus Manfred From pgsql-performance-owner@postgresql.org Thu Jun 26 13:04:14 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 591DE30FF81 for ; Thu, 26 Jun 2003 16:04:13 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 75024-08 for ; Thu, 26 Jun 2003 13:04:03 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 7C22430FF88 for ; Thu, 26 Jun 2003 13:04:02 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5QG3qQQ025815; Thu, 26 Jun 2003 12:03:52 -0400 (EDT) To: Manfred Koizar Cc: Andre Schubert , pgsql-performance@postgresql.org Subject: Re: problem with pg_statistics In-reply-to: References: <20030626151515.5fd0faf0.andre@km3.de> <24083.1056636485@sss.pgh.pa.us> Comments: In-reply-to Manfred Koizar message dated "Thu, 26 Jun 2003 17:51:56 +0200" Date: Thu, 26 Jun 2003 12:03:52 -0400 Message-ID: <25814.1056643432@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/182 X-Sequence-Number: 2266 Manfred Koizar writes: > On Thu, 26 Jun 2003 10:08:05 -0400, Tom Lane > wrote: >> Try reducing random_page_cost > With index scan cost being more than 25 * seq scan cost, I guess that > - all other things held equal - even random_page_cost = 1 wouldn't > help. Oh, you're right, I was comparing the wrong estimated costs. Yeah, changing random_page_cost won't fix it. > Or there's something wrong with correlation? That seems like a good bet. Andre, is this table likely to be physically ordered by time_stamp, or nearly so? If so, do you expect that condition to persist, or is it just an artifact of a test setup? regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jun 27 03:07:50 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id B6B61310116 for ; Fri, 27 Jun 2003 06:07:49 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 98788-07 for ; Fri, 27 Jun 2003 03:07:39 -0300 (ADT) Received: from server.beierfeld.kabeljournal.de (pD9529362.dip.t-dialin.net [217.82.147.98]) by svr1.postgresql.org (Postfix) with SMTP id 5FF7230FF56 for ; Fri, 27 Jun 2003 03:07:38 -0300 (ADT) Received: (qmail 5727 invoked from network); 27 Jun 2003 06:07:36 -0000 Received: from station158.beierfeld.kabeljournal.de (192.168.128.158) by server.beierfeld.kabeljournal.de with SMTP; 27 Jun 2003 06:07:36 -0000 Date: Fri, 27 Jun 2003 08:07:35 +0200 From: Andre Schubert To: Tom Lane Cc: mkoi-pg@aon.at, pgsql-performance@postgresql.org Subject: Re: problem with pg_statistics Message-Id: <20030627080735.66d6bdf0.andre.schubert@km3.de> In-Reply-To: <25814.1056643432@sss.pgh.pa.us> References: <20030626151515.5fd0faf0.andre@km3.de> <24083.1056636485@sss.pgh.pa.us> <25814.1056643432@sss.pgh.pa.us> Organization: km3 teledienst GmbH X-Mailer: Sylpheed version 0.9.1 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/183 X-Sequence-Number: 2267 On Thu, 26 Jun 2003 12:03:52 -0400 Tom Lane wrote: > Manfred Koizar writes: > > On Thu, 26 Jun 2003 10:08:05 -0400, Tom Lane > > wrote: > >> Try reducing random_page_cost > > > With index scan cost being more than 25 * seq scan cost, I guess that > > - all other things held equal - even random_page_cost = 1 wouldn't > > help. > > Oh, you're right, I was comparing the wrong estimated costs. Yeah, > changing random_page_cost won't fix it. > > > Or there's something wrong with correlation? > > That seems like a good bet. Andre, is this table likely to be > physically ordered by time_stamp, or nearly so? If so, do you > expect that condition to persist, or is it just an artifact of > a test setup? > First of all thanks for the quick response. We have three servers at different places, all servers are running with athlon processors and have ram between 512M up to 1024M, and a frequency between 700 and 1400Mhz. All servers running under Linux 7.2 Kernel 2.4.20. We use this table to collect traffic of our clients. Traffic data are inserted every 5 minutes with the actual datetime of the transaction, thatswhy the table should be physically order by time_stamp. All servers are running in production and i could reproduce the problem on all three servers. To answer Manfreds questions: > Andre, what hardware is this running on? What are the values of > shared_buffers, random_page_cost, effective_cache_size, ... ? Could > you show us the result of > > SELECT * FROM pg_stats > WHERE tablename = "tbl_traffic" AND attname = "time_stamp"; The only changes we have made are sort_mem = 32000 shared_buffers = 13000 All other values are commented out and should be set to default by postgres itself. #max_fsm_relations = 100 # min 10, fsm is free space map #max_fsm_pages = 10000 # min 1000, fsm is free space map #effective_cache_size = 1000 # default in 8k pages #random_page_cost = 4 #cpu_tuple_cost = 0.01 #cpu_index_tuple_cost = 0.001 #cpu_operator_cost = 0.0025 Hope this help ... Thanks, as From pgsql-performance-owner@postgresql.org Fri Jun 27 03:13:23 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id C487230EF13 for ; Fri, 27 Jun 2003 06:13:22 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 09774-01 for ; Fri, 27 Jun 2003 03:13:12 -0300 (ADT) Received: from server.beierfeld.kabeljournal.de (pD9529362.dip.t-dialin.net [217.82.147.98]) by svr1.postgresql.org (Postfix) with SMTP id 302A730E656 for ; Fri, 27 Jun 2003 03:13:11 -0300 (ADT) Received: (qmail 5873 invoked from network); 27 Jun 2003 06:13:08 -0000 Received: from station158.beierfeld.kabeljournal.de (192.168.128.158) by server.beierfeld.kabeljournal.de with SMTP; 27 Jun 2003 06:13:08 -0000 Date: Fri, 27 Jun 2003 08:13:06 +0200 From: Andre Schubert To: Tom Lane Cc: mkoi-pg@aon.at, pgsql-performance@postgresql.org Subject: Re: problem with pg_statistics Message-Id: <20030627081306.71ffbb2e.andre.schubert@km3.de> In-Reply-To: <25814.1056643432@sss.pgh.pa.us> References: <20030626151515.5fd0faf0.andre@km3.de> <24083.1056636485@sss.pgh.pa.us> <25814.1056643432@sss.pgh.pa.us> Organization: km3 teledienst GmbH X-Mailer: Sylpheed version 0.9.1 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/184 X-Sequence-Number: 2268 On Thu, 26 Jun 2003 12:03:52 -0400 Tom Lane wrote: > Manfred Koizar writes: > > On Thu, 26 Jun 2003 10:08:05 -0400, Tom Lane > > wrote: > >> Try reducing random_page_cost > > > With index scan cost being more than 25 * seq scan cost, I guess that > > - all other things held equal - even random_page_cost = 1 wouldn't > > help. > > Oh, you're right, I was comparing the wrong estimated costs. Yeah, > changing random_page_cost won't fix it. > > > Or there's something wrong with correlation? > > That seems like a good bet. Andre, is this table likely to be > physically ordered by time_stamp, or nearly so? If so, do you > expect that condition to persist, or is it just an artifact of > a test setup? > Sorry forgot the pg_stat query... SELECT * FROM pg_stats where tablename = 'tbl_traffic' and attname = 'time_stamp'; tablename | attname | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation -------------+------------+-----------+-----------+------------+------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------+--------------------------------------------------------------------+--------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------+------------- tbl_traffic | time_stamp | 0 | 8 | 104009 | {"2003-06-03 19:12:01.059625+02","2003-02-03 19:52:06.666296+01","2003-02-13 09:59:45.415763+01","2003 -02-28 18:10:28.536399+01","2003-04-11 18:09:42.30363+02","2003-04-26 20:35:50.110235+02","2003-05-03 11:09:32.991507+02","2003-05-20 09:53:51.271853+02","2003-05-21 2 0:55:59.155387+02","2003-06-02 02:38:28.823182+02"} | {0.00133333,0.001,0.001,0.001,0.001,0.001,0.001,0.001,0.001,0.001} | {"2002-07-01 00:00:00+02","2003-02-21 01:59: 46.107696+01","2003-03-11 15:00:37.418521+01","2003-03-26 18:14:50.028972+01","2003-04-10 13:43:20.75909+02","2003-04-27 09:03:19.592213+02","2003-05-08 22:35:41.99761 6+02","2003-05-22 15:34:42.932958+02","2003-06-03 00:53:05.870782+02","2003-06-15 08:45:41.154875+02","2003-06-27 07:18:30.265868+02"} | -0.479749 (1 row) Thanks, as From pgsql-performance-owner@postgresql.org Fri Jun 27 05:43:14 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1BE2E310170 for ; Fri, 27 Jun 2003 08:43:12 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 35274-05 for ; Fri, 27 Jun 2003 05:43:01 -0300 (ADT) Received: from email05.aon.at (WARSL402PIP4.highway.telekom.at [195.3.96.79]) by svr1.postgresql.org (Postfix) with SMTP id 10B7230FCAE for ; Fri, 27 Jun 2003 05:43:01 -0300 (ADT) Received: (qmail 309384 invoked from network); 27 Jun 2003 08:43:00 -0000 Received: from m149p026.dipool.highway.telekom.at (HELO cantor) ([62.46.8.154]) (envelope-sender ) by qmail5rs.highway.telekom.at (qmail-ldap-1.03) with SMTP for ; 27 Jun 2003 08:43:00 -0000 From: Manfred Koizar To: Andre Schubert Cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: problem with pg_statistics Date: Fri, 27 Jun 2003 10:43:01 +0200 Message-ID: <4avnfvkjr8q7cl8ac6f01j8rddj4pjlte0@4ax.com> References: <20030626151515.5fd0faf0.andre@km3.de> <24083.1056636485@sss.pgh.pa.us> <25814.1056643432@sss.pgh.pa.us> <20030627080735.66d6bdf0.andre.schubert@km3.de> In-Reply-To: <20030627080735.66d6bdf0.andre.schubert@km3.de> X-Mailer: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/185 X-Sequence-Number: 2269 On Fri, 27 Jun 2003 08:07:35 +0200, Andre Schubert wrote: >Traffic data are inserted every 5 minutes with the actual datetime >of the transaction, thatswhy the table should be physically order by time_stamp. So I'd expect a correlation of nearly 1. Why do your statistics show a value of -0.479749? A negative correlation is a sign of descending sort order, and correlation values closer to 0 indicate poor correspondence between column values and tuple positions. Could this be the effect of initial data loading? Are there any updates or deletions in your traffic table? >To answer Manfreds questions: >> Andre, what hardware is this running on? What are the values of >> shared_buffers, random_page_cost, effective_cache_size, ... ? Could >> you show us the result of >> >> SELECT * FROM pg_stats >> WHERE tablename = "tbl_traffic" AND attname = "time_stamp"; ^ ^ ^ ^ Oops, these should have been single quotes. It's too hot here these days :-) >sort_mem = 32000 >shared_buffers = 13000 Personally I would set them to lower values, but if you have good reasons ... >#effective_cache_size = 1000 # default in 8k pages This is definitely too low. With 512MB or more I tend to set this to ca. 80% of available RAM. Use top and free to find hints for good values. Servus Manfred From pgsql-performance-owner@postgresql.org Fri Jun 27 06:11:12 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 10010310177 for ; Fri, 27 Jun 2003 09:11:11 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 36728-04 for ; Fri, 27 Jun 2003 06:11:00 -0300 (ADT) Received: from server.beierfeld.kabeljournal.de (pD9529362.dip.t-dialin.net [217.82.147.98]) by svr1.postgresql.org (Postfix) with SMTP id 65F963101D4 for ; Fri, 27 Jun 2003 06:10:59 -0300 (ADT) Received: (qmail 10581 invoked from network); 27 Jun 2003 09:10:58 -0000 Received: from station158.beierfeld.kabeljournal.de (192.168.128.158) by server.beierfeld.kabeljournal.de with SMTP; 27 Jun 2003 09:10:58 -0000 Date: Fri, 27 Jun 2003 11:10:58 +0200 From: Andre Schubert To: Manfred Koizar Cc: tgl@sss.pgh.pa.us, pgsql-performance@postgresql.org Subject: Re: problem with pg_statistics Message-Id: <20030627111058.08f71b14.andre@km3.de> In-Reply-To: <4avnfvkjr8q7cl8ac6f01j8rddj4pjlte0@4ax.com> References: <20030626151515.5fd0faf0.andre@km3.de> <24083.1056636485@sss.pgh.pa.us> <25814.1056643432@sss.pgh.pa.us> <20030627080735.66d6bdf0.andre.schubert@km3.de> <4avnfvkjr8q7cl8ac6f01j8rddj4pjlte0@4ax.com> Organization: km3 teledienst GmbH X-Mailer: Sylpheed version 0.9.1 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/186 X-Sequence-Number: 2270 On Fri, 27 Jun 2003 10:43:01 +0200 Manfred Koizar wrote: > On Fri, 27 Jun 2003 08:07:35 +0200, Andre Schubert > wrote: > >Traffic data are inserted every 5 minutes with the actual datetime > >of the transaction, thatswhy the table should be physically order by time_stamp. > > So I'd expect a correlation of nearly 1. Why do your statistics show > a value of -0.479749? A negative correlation is a sign of descending > sort order, and correlation values closer to 0 indicate poor > correspondence between column values and tuple positions. > > Could this be the effect of initial data loading? Are there any > updates or deletions in your traffic table? > We dont make updates the traffic table. Once a month we delete the all data of the oldest month. And after that a vacuum full verbose analyze is performed. Could this cause reordering of the data ? And should i do a cluster idx_ts tbl_traffic ? > >To answer Manfreds questions: > >> Andre, what hardware is this running on? What are the values of > >> shared_buffers, random_page_cost, effective_cache_size, ... ? Could > >> you show us the result of > >> > >> SELECT * FROM pg_stats > >> WHERE tablename = "tbl_traffic" AND attname = "time_stamp"; > ^ ^ ^ ^ > Oops, these should have been single quotes. It's too hot here these > days :-) > You are so right ... :) > >#effective_cache_size = 1000 # default in 8k pages > > This is definitely too low. With 512MB or more I tend to set this to > ca. 80% of available RAM. Use top and free to find hints for good > values. > Ok, i will talk with my coworker ( he is the sysadmin of our machine ) and look if can use such amount of RAM, because there are several other processes that are running on these machines. But i will test and report ... Thanks, as From pgsql-performance-owner@postgresql.org Fri Jun 27 07:05:27 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 17B413101E7 for ; Fri, 27 Jun 2003 10:05:25 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 47982-05 for ; Fri, 27 Jun 2003 07:05:14 -0300 (ADT) Received: from email02.aon.at (WARSL402PIP7.highway.telekom.at [195.3.96.94]) by svr1.postgresql.org (Postfix) with SMTP id E08FD3101A2 for ; Fri, 27 Jun 2003 07:05:13 -0300 (ADT) Received: (qmail 105770 invoked from network); 27 Jun 2003 10:05:12 -0000 Received: from m149p026.dipool.highway.telekom.at (HELO cantor) ([62.46.8.154]) (envelope-sender ) by qmail2rs.highway.telekom.at (qmail-ldap-1.03) with SMTP for ; 27 Jun 2003 10:05:12 -0000 From: Manfred Koizar To: Andre Schubert Cc: tgl@sss.pgh.pa.us, pgsql-performance@postgresql.org Subject: Re: problem with pg_statistics Date: Fri, 27 Jun 2003 12:05:14 +0200 Message-ID: <555ofvopbsuiog6tti32natah0futga7d4@4ax.com> References: <20030626151515.5fd0faf0.andre@km3.de> <24083.1056636485@sss.pgh.pa.us> <25814.1056643432@sss.pgh.pa.us> <20030627080735.66d6bdf0.andre.schubert@km3.de> <4avnfvkjr8q7cl8ac6f01j8rddj4pjlte0@4ax.com> <20030627111058.08f71b14.andre@km3.de> In-Reply-To: <20030627111058.08f71b14.andre@km3.de> X-Mailer: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/187 X-Sequence-Number: 2271 On Fri, 27 Jun 2003 11:10:58 +0200, Andre Schubert wrote: >Once a month we delete the all data of the oldest month. >And after that a vacuum full verbose analyze is performed. >Could this cause reordering of the data ? I may be wrong, but I think VACUUM FULL starts taking tuples from the end of the relation and puts them into pages at the beginning until read and write position meet somewhere in the middle. This explains the bad correlation. >And should i do a cluster idx_ts tbl_traffic ? I think so. >> >#effective_cache_size = 1000 # default in 8k pages >> >> This is definitely too low. With 512MB or more I tend to set this to >> ca. 80% of available RAM. Use top and free to find hints for good >> values. >> > >Ok, i will talk with my coworker ( he is the sysadmin of our machine ) >and look if can use such amount of RAM, because there are several other >processes that are running on these machines. >But i will test and report ... effective_cache_size does not *control* resource consumption, it just *reports* it as a hint to the planner. Servus Manfred From pgsql-performance-owner@postgresql.org Fri Jun 27 11:31:37 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 622D73102C1 for ; Fri, 27 Jun 2003 14:31:35 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 83740-05 for ; Fri, 27 Jun 2003 11:31:24 -0300 (ADT) Received: from juliette2.openweb.be (juliette2.openweb.be [217.145.32.36]) by svr1.postgresql.org (Postfix) with SMTP id DD4003102A2 for ; Fri, 27 Jun 2003 11:31:23 -0300 (ADT) Received: (qmail 23511 invoked by uid 585); 27 Jun 2003 14:25:55 -0000 Received: from pgsql-ml@baguette.net by juliette2.openweb.be by uid 582 with qmail-scanner-1.10 (avp. Clear:0. Processed in 2.752299 secs); 27 Jun 2003 14:25:55 -0000 Received: from levure.baguette.net (HELO Morpheus) (217.145.35.101) by juliette2.openweb.be with SMTP; 27 Jun 2003 14:25:51 -0000 From: "Bruno BAGUETTE" To: Subject: Large querie with several EXISTS which will be often runned Date: Fri, 27 Jun 2003 16:32:21 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.4024 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Importance: Normal X-Spam-Status: No, hits=0.9 tagged_above=0.0 required=5.0 tests=BAYES_20, FORGED_MUA_OUTLOOK, MSGID_CHARS_SPAM, UPPERCASE_25_50 X-Spam-Level: * X-Archive-Number: 200306/188 X-Sequence-Number: 2272 Hello, I've a performance question that I would like to ask you : I have to design a DB that will manage products, and I'm adding the product's options management. A box can be red or yellow, or with black rubber or with white rubber, for example. So I have a product (the box) and two options groups (the box color and the rubber color) and four options (red,yellow,black,white). Here's my tables : /* PRODUCTS OPTIONS : */ /* ------------------ */ CREATE SEQUENCE seq_id_product_option START 1 MINVALUE 1; CREATE TABLE products_options ( pk_prdopt_id INT4 DEFAULT NEXTVAL('seq_id_product_option') NOT NULL, fk_prd_id INT4 NOT NULL, name VARCHAR(100) NOT NULL, description TEXT, price DOUBLE PRECISION NOT NULL, vat_rate NUMERIC(5,2) NOT NULL, internal_notes TEXT, CONSTRAINT products_options_pk PRIMARY KEY (pk_prdopt_id), CONSTRAINT products_options_fk_prdid FOREIGN KEY (fk_prd_id) REFERENCES products (pk_prd_id), CONSTRAINT products_options_vatrate_value CHECK (vat_rate BETWEEN 0 AND 100) ); /* PRODUCTS OPTIONS GROUP NAMES : */ /* ------------------------------ */ CREATE SEQUENCE seq_id_product_option_group START 1 MINVALUE 1; CREATE TABLE products_options_groups ( pk_prdoptgrp_id INT4 DEFAULT NEXTVAL('seq_id_product_option_group') NOT NULL, prdoptgrp_name VARCHAR(100) NOT NULL, prdoptgrp_description TEXT NOT NULL, prdoptgrp_internal_notes TEXT, CONSTRAINT products_options_groups_pk PRIMARY KEY(pk_prdoptgrp_id) ); /* PRODUCTS OPTIONS CLASSIFICATION : */ /* ------------------------------ */ CREATE TABLE products_options_classification ( fk_prdoptgrp_id INT4 NOT NULL, fk_prdopt_id INT4 NOT NULL, CONSTRAINT products_options_classification_pk PRIMARY KEY(fk_prdoptgrp_id,fk_prdopt_id), CONSTRAINT products_options_classification_fk_prdoptgrp FOREIGN KEY (fk_prdoptgrp_id) REFERENCES products_options_groups (pk_prdoptgrp_id), CONSTRAINT products_options_classification_fk_prdopt FOREIGN KEY (fk_prdopt_id) REFERENCES products_options (pk_prdopt_id) ); I'm worrying about the performances of the queries that will the most often dones, especially the select of the available options groups ('Rubber color','Box color' in my example) on one product (The box). SELECT products_options_groups.pk_prdoptgrp_id, products_options_groups.prdoptgrp_name FROM products_options_groups WHERE EXISTS ( SELECT * FROM products_options_classification WHERE products_options_classification = products_options_groups.pk_prdoptgrp_id AND EXISTS ( SELECT * FROM products_options WHERE products_options.pk_prdopt_id = products_options_classification.fk_prdopt_id AND products_options.fk_prd_id = [A PRODUCT ID WRITTEN HERE BY MY APP] ) ) ORDER BY products_options_groups.prdoptgrp_name; I will have to manage more or less 10.000 products with more or less 2-3 options by products and more or less 40 options-groups. Do you think that this query will be hard for PostgreSQL (currently 7.2.1 but I will migrate to 7.3.2 when going in production environment) ? How can I improve that query to be faster ? Thanks really much for your advices about this ! :-) --------------------------------------- Bruno BAGUETTE - pgsql-ml@baguette.net From pgsql-performance-owner@postgresql.org Fri Jun 27 12:43:05 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 64AE5310297 for ; Fri, 27 Jun 2003 15:43:04 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 92974-07 for ; Fri, 27 Jun 2003 12:42:54 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id AA66931022A for ; Fri, 27 Jun 2003 12:42:53 -0300 (ADT) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3159539; Fri, 27 Jun 2003 08:43:00 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: "Bruno BAGUETTE" , Subject: Re: Large querie with several EXISTS which will be often runned Date: Fri, 27 Jun 2003 08:41:40 -0700 User-Agent: KMail/1.4.3 References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200306270841.40634.josh@agliodbs.com> X-Archive-Number: 200306/189 X-Sequence-Number: 2273 Bruno, > I will have to manage more or less 10.000 products with more or less 2-3 > options by products and more or less 40 options-groups. > > Do you think that this query will be hard for PostgreSQL (currently > 7.2.1 but I will migrate to 7.3.2 when going in production environment) > ? > How can I improve that query to be faster ? Collapse the inner EXISTS into a straight join in the outer EXISTS. Since you are merely checking for existence, there is no reason for the subquery nesting. -- Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Fri Jun 27 16:16:38 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id CD1033100CF for ; Fri, 27 Jun 2003 19:16:35 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 22021-06 for ; Fri, 27 Jun 2003 16:16:25 -0300 (ADT) Received: from fddlnint05.fds.com (fddlnint05.fds.com [208.15.91.52]) by svr1.postgresql.org (Postfix) with ESMTP id F018F310087 for ; Fri, 27 Jun 2003 16:16:24 -0300 (ADT) Subject: Memory question To: pgsql-performance@postgresql.org X-Mailer: Lotus Notes Release 6.0 September 26, 2002 Message-ID: From: "Patrick Hatcher" Date: Fri, 27 Jun 2003 12:09:50 -0700 X-MIMETrack: Serialize by Router on FDDLNINT05/FSG/SVR/FDD(Release 5.0.4 |June 8, 2000) at 06/27/2003 03:11:57 PM MIME-Version: 1.0 Content-type: text/plain; charset=us-ascii X-Archive-Number: 200306/190 X-Sequence-Number: 2274 Sorry for posting an obvious Linux question, but have any of you encountered this and how have you fixed it. I have 6gig Ram box. I've set my shmmax to 3072000000. The database starts up fine without any issues. As soon as a query is ran or a FTP process to the server is done, the used memory shoots up and appears to never be released. My fear is that this may cause problems for my database if this number continues to grow. Below is my TOP after running a query, and shutting down PgAdmin. While not low now, the amount of free memory has dropped to around 11mg. I'll admit I'm not that Linux savvy, but am I reading this correct? --TOP 45 processes: 44 sleeping, 1 running, 0 zombie, 0 stopped CPU0 states: 0.0% user, 0.0% system, 0.0% nice, 100.0% idle CPU1 states: 0.0% user, 0.0% system, 0.0% nice, 100.0% idle CPU2 states: 0.0% user, 0.0% system, 0.0% nice, 100.0% idle CPU3 states: 0.0% user, 0.0% system, 0.0% nice, 100.0% idle Mem: 6711564K av, 6517776K used, 193788K free, 0K shrd, 25168K buff Swap: 2044056K av, 0K used, 2044056K free 6257620K cached Patrick Hatcher From pgsql-performance-owner@postgresql.org Fri Jun 27 16:51:25 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 4507230FF0D for ; Fri, 27 Jun 2003 19:51:24 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 28507-04 for ; Fri, 27 Jun 2003 16:51:13 -0300 (ADT) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by svr1.postgresql.org (Postfix) with ESMTP id 7B7F531023E for ; Fri, 27 Jun 2003 16:51:13 -0300 (ADT) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h5RJnqA0010116; Fri, 27 Jun 2003 13:49:52 -0600 (MDT) Date: Fri, 27 Jun 2003 13:44:38 -0600 (MDT) From: "scott.marlowe" To: Patrick Hatcher Cc: Subject: Re: Memory question In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailScanner: Found to be clean X-MailScanner-SpamCheck: X-Archive-Number: 200306/191 X-Sequence-Number: 2275 This is actually normal. Look at the amount cached: 6257620K. That's 6.2Gig of cache. Linux is using only 6517776k - 6257620k of memory, the rest is just acting as kernel cache. If anything tries to allocate a bit of memory, linux will flush enough cache to give the memory to the application that needs it. Note that you're only showing linux and all its applications using about 256Meg. On Fri, 27 Jun 2003, Patrick Hatcher wrote: > Sorry for posting an obvious Linux question, but have any of you > encountered this and how have you fixed it. > I have 6gig Ram box. I've set my shmmax to 3072000000. The database > starts up fine without any issues. As soon as a query is ran > or a FTP process to the server is done, the used memory shoots up and > appears to never be released. > My fear is that this may cause problems for my database if this number > continues to grow. Below is my TOP after running a query, and shutting > down PgAdmin. While not low now, the amount of free memory has dropped to > around 11mg. I'll admit I'm not that Linux savvy, but am I reading this > correct? > > --TOP > > 45 processes: 44 sleeping, 1 running, 0 zombie, 0 stopped > CPU0 states: 0.0% user, 0.0% system, 0.0% nice, 100.0% idle > CPU1 states: 0.0% user, 0.0% system, 0.0% nice, 100.0% idle > CPU2 states: 0.0% user, 0.0% system, 0.0% nice, 100.0% idle > CPU3 states: 0.0% user, 0.0% system, 0.0% nice, 100.0% idle > Mem: 6711564K av, 6517776K used, 193788K free, 0K shrd, 25168K > buff > Swap: 2044056K av, 0K used, 2044056K free 6257620K > cached > > Patrick Hatcher > > > > ---------------------------(end of broadcast)--------------------------- > TIP 7: don't forget to increase your free space map settings > From pgsql-performance-owner@postgresql.org Fri Jun 27 16:56:06 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 0A6A7310238 for ; Fri, 27 Jun 2003 19:56:04 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 22987-07 for ; Fri, 27 Jun 2003 16:55:53 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id 225B930F9DD for ; Fri, 27 Jun 2003 16:55:53 -0300 (ADT) Received: from [66.219.92.2] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3160249; Fri, 27 Jun 2003 12:55:58 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: "Patrick Hatcher" , pgsql-performance@postgresql.org Subject: Re: Memory question Date: Fri, 27 Jun 2003 12:54:51 -0700 User-Agent: KMail/1.4.3 References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200306271254.51441.josh@agliodbs.com> X-Archive-Number: 200306/192 X-Sequence-Number: 2276 Patrick, > Sorry for posting an obvious Linux question, but have any of you > encountered this and how have you fixed it. > I have 6gig Ram box. I've set my shmmax to 3072000000. The database > starts up fine without any issues. As soon as a query is ran > or a FTP process to the server is done, the used memory shoots up and > appears to never be released. What's you shared_buffers set to after our talk? Do you actually need 3gb = of=20 shmmax?=20=20 > My fear is that this may cause problems for my database if this number > continues to grow. Below is my TOP after running a query, and shutting > down PgAdmin. While not low now, the amount of free memory has dropped to > around 11mg. I'll admit I'm not that Linux savvy, but am I reading this > correct? No.=20=20=20 > Mem: 6711564K av, 6517776K used, 193788K free, 0K shrd, 25168K The "used" figure in Top doesn't really tell you anything, since it include= s=20 the kernel buffer which tries to take up all available memory. If you=20 actually look at the list of processes, I think you'll find that you're onl= y=20 using 1-2% of memory for applications. I'm not sure what app would show your "real" free memory. --=20 -Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Fri Jun 27 17:05:13 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id EB50031026E for ; Fri, 27 Jun 2003 20:05:12 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 25073-09 for ; Fri, 27 Jun 2003 17:05:02 -0300 (ADT) Received: from fddlnint05.fds.com (fddlnint05.fds.com [208.15.91.52]) by svr1.postgresql.org (Postfix) with ESMTP id ED25030E404 for ; Fri, 27 Jun 2003 17:05:01 -0300 (ADT) In-Reply-To: <200306271254.51441.josh@agliodbs.com> Subject: Re: Memory question To: josh@agliodbs.com Cc: pgsql-performance@postgresql.org X-Mailer: Lotus Notes Release 6.0 September 26, 2002 Message-ID: From: "Patrick Hatcher" Date: Fri, 27 Jun 2003 12:58:22 -0700 X-MIMETrack: Serialize by Router on FDDLNINT05/FSG/SVR/FDD(Release 5.0.4 |June 8, 2000) at 06/27/2003 04:00:34 PM MIME-Version: 1.0 Content-type: text/plain; charset=us-ascii X-Archive-Number: 200306/193 X-Sequence-Number: 2277 Shared buffer is now set to 20,000 as suggested. So far so good. As far as shmmax, it really is my ignorance of Linux. We are going to play around with this number. Is there a suggested amount since I have my effective_cache_size = 625000 (or does one have nothing to do with the other) Thanks again Patrick Hatcher Josh Berkus , pgsql-performance@postgresql.org .com> cc: Subject: Re: [PERFORM] Memory question 06/27/2003 12:54 PM Please respond to josh Patrick, > Sorry for posting an obvious Linux question, but have any of you > encountered this and how have you fixed it. > I have 6gig Ram box. I've set my shmmax to 3072000000. The database > starts up fine without any issues. As soon as a query is ran > or a FTP process to the server is done, the used memory shoots up and > appears to never be released. What's you shared_buffers set to after our talk? Do you actually need 3gb of shmmax? > My fear is that this may cause problems for my database if this number > continues to grow. Below is my TOP after running a query, and shutting > down PgAdmin. While not low now, the amount of free memory has dropped to > around 11mg. I'll admit I'm not that Linux savvy, but am I reading this > correct? No. > Mem: 6711564K av, 6517776K used, 193788K free, 0K shrd, 25168K The "used" figure in Top doesn't really tell you anything, since it includes the kernel buffer which tries to take up all available memory. If you actually look at the list of processes, I think you'll find that you're only using 1-2% of memory for applications. I'm not sure what app would show your "real" free memory. -- -Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Fri Jun 27 17:06:03 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 655FC31025D for ; Fri, 27 Jun 2003 20:06:02 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 30391-02 for ; Fri, 27 Jun 2003 17:05:52 -0300 (ADT) Received: from fddlnint05.fds.com (fddlnint05.fds.com [208.15.91.52]) by svr1.postgresql.org (Postfix) with ESMTP id C403E310241 for ; Fri, 27 Jun 2003 17:05:51 -0300 (ADT) In-Reply-To: Subject: Re: Memory question To: scott.marlowe@ihs.com Cc: pgsql-performance@postgresql.org X-Mailer: Lotus Notes Release 6.0 September 26, 2002 Message-ID: From: "Patrick Hatcher" Date: Fri, 27 Jun 2003 12:59:23 -0700 X-MIMETrack: Serialize by Router on FDDLNINT05/FSG/SVR/FDD(Release 5.0.4 |June 8, 2000) at 06/27/2003 04:01:24 PM MIME-Version: 1.0 Content-type: text/plain; charset=us-ascii X-Archive-Number: 200306/194 X-Sequence-Number: 2278 Thank you Patrick Hatcher "scott.marlowe " To: Patrick Hatcher @ihs.com> Subject: Re: [PERFORM] Memory question 06/27/2003 12:44 PM This is actually normal. Look at the amount cached: 6257620K. That's 6.2Gig of cache. Linux is using only 6517776k - 6257620k of memory, the rest is just acting as kernel cache. If anything tries to allocate a bit of memory, linux will flush enough cache to give the memory to the application that needs it. Note that you're only showing linux and all its applications using about 256Meg. On Fri, 27 Jun 2003, Patrick Hatcher wrote: > Sorry for posting an obvious Linux question, but have any of you > encountered this and how have you fixed it. > I have 6gig Ram box. I've set my shmmax to 3072000000. The database > starts up fine without any issues. As soon as a query is ran > or a FTP process to the server is done, the used memory shoots up and > appears to never be released. > My fear is that this may cause problems for my database if this number > continues to grow. Below is my TOP after running a query, and shutting > down PgAdmin. While not low now, the amount of free memory has dropped to > around 11mg. I'll admit I'm not that Linux savvy, but am I reading this > correct? > > --TOP > > 45 processes: 44 sleeping, 1 running, 0 zombie, 0 stopped > CPU0 states: 0.0% user, 0.0% system, 0.0% nice, 100.0% idle > CPU1 states: 0.0% user, 0.0% system, 0.0% nice, 100.0% idle > CPU2 states: 0.0% user, 0.0% system, 0.0% nice, 100.0% idle > CPU3 states: 0.0% user, 0.0% system, 0.0% nice, 100.0% idle > Mem: 6711564K av, 6517776K used, 193788K free, 0K shrd, 25168K > buff > Swap: 2044056K av, 0K used, 2044056K free 6257620K > cached > > Patrick Hatcher > > > > ---------------------------(end of broadcast)--------------------------- > TIP 7: don't forget to increase your free space map settings > From pgsql-performance-owner@postgresql.org Fri Jun 27 17:17:21 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 05320310265 for ; Fri, 27 Jun 2003 20:17:19 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 34065-01 for ; Fri, 27 Jun 2003 17:17:08 -0300 (ADT) Received: from indygecko.com (h24-77-222-182.ok.shawcable.net [24.77.222.182]) by svr1.postgresql.org (Postfix) with ESMTP id 990DF31026F for ; Fri, 27 Jun 2003 17:17:07 -0300 (ADT) Received: from [192.168.10.10] ([::ffff:192.168.10.10]) by indygecko.com with esmtp; Fri, 27 Jun 2003 13:17:04 -0700 Subject: Re: Memory question From: Jord Tanner To: Patrick Hatcher , pgsql-performance@postgresql.org In-Reply-To: References: Organization: Message-Id: <1056745023.4726.50.camel@gecko> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.2.2 (1.2.2-5) Date: 27 Jun 2003 13:17:04 -0700 X-Archive-Number: 200306/195 X-Sequence-Number: 2279 On Fri, 2003-06-27 at 12:09, Patrick Hatcher wrote: > I have 6gig Ram box. I've set my shmmax to 3072000000. The database > starts up fine without any issues. As soon as a query is ran > or a FTP process to the server is done, the used memory shoots up and > appears to never be released. In my experience Linux likes to allocate almost all available RAM. I've never had any trouble with that. I'm looking at the memory meter on my RH9 development workstation and it is at 95%. Performance is good, so I just trust that the kernel knows what it is doing. > Mem: 6711564K av, 6517776K used, 193788K free, 0K shrd, 25168K > buff > Swap: 2044056K av, 0K used, 2044056K free 6257620K > cached I've heard anecdotally that Linux has troubles if the swap space is less than the RAM size. I note that you have 6G of RAM, but only 2G of swap. I'm sure others on the list will have more definitive opinions. -- Jord Tanner From pgsql-performance-owner@postgresql.org Fri Jun 27 17:31:43 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id B6160310250 for ; Fri, 27 Jun 2003 20:31:41 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 30444-09 for ; Fri, 27 Jun 2003 17:31:31 -0300 (ADT) Received: from mail.blarg.net (zoot.blarg.net [206.124.128.9]) by svr1.postgresql.org (Postfix) with ESMTP id 2E9BB310241 for ; Fri, 27 Jun 2003 17:31:31 -0300 (ADT) Received: from poindextrose.org (poindextrose.org [206.124.144.246]) by mail.blarg.net (Postfix) with ESMTP id E1EA133B88 for ; Fri, 27 Jun 2003 13:30:30 -0700 (PDT) Date: Fri, 27 Jun 2003 13:30:28 -0700 Subject: Re: Memory question Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v552) From: Matthew Hixson To: pgsql-performance@postgresql.org Content-Transfer-Encoding: 7bit In-Reply-To: <1056745023.4726.50.camel@gecko> Message-Id: <30A40B16-A8DE-11D7-81EC-000393669C1A@poindextrose.org> X-Mailer: Apple Mail (2.552) X-Archive-Number: 200306/196 X-Sequence-Number: 2280 On Friday, June 27, 2003, at 01:17 PM, Jord Tanner wrote: > On Fri, 2003-06-27 at 12:09, Patrick Hatcher wrote: > > > >> I have 6gig Ram box. I've set my shmmax to 3072000000. The database >> starts up fine without any issues. As soon as a query is ran >> or a FTP process to the server is done, the used memory shoots up and >> appears to never be released. > > In my experience Linux likes to allocate almost all available RAM. I've > never had any trouble with that. I'm looking at the memory meter on my > RH9 development workstation and it is at 95%. Performance is good, so I > just trust that the kernel knows what it is doing. > > > >> Mem: 6711564K av, 6517776K used, 193788K free, 0K shrd, >> 25168K >> buff >> Swap: 2044056K av, 0K used, 2044056K free >> 6257620K >> cached > > I've heard anecdotally that Linux has troubles if the swap space is > less > than the RAM size. I note that you have 6G of RAM, but only 2G of swap. I've heard that too, but it doesn't seem to make much sense to me. If you get to the point where your machine is _needing_ 2GB of swap then something has gone horribly wrong (or you just need more RAM in the machine) and it will just crawl until the kernel kills off whatever process causes the swap space to be exceeded. Seems to me that you should only have that much swap if you can't afford more RAM or you've tapped out your machine's capacity, and your application needs that much memory. -M@ From pgsql-performance-owner@postgresql.org Fri Jun 27 17:52:16 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 1F0483102EC for ; Fri, 27 Jun 2003 20:49:30 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 33369-07 for ; Fri, 27 Jun 2003 17:49:19 -0300 (ADT) Received: from mailhost3.tudelft.nl (mailhost3.tudelft.nl [130.161.180.83]) by svr1.postgresql.org (Postfix) with ESMTP id 6F6BA31026F for ; Fri, 27 Jun 2003 17:49:19 -0300 (ADT) Received: from 127.0.0.1 (localhost [127.0.0.1]) by rav.antivirus (Postfix) with SMTP id 3420B53A; Fri, 27 Jun 2003 22:49:19 +0200 (MEST) Received: from listserv.tudelft.nl (listserv.tudelft.nl [130.161.180.33]) by mailhost3.tudelft.nl (Postfix) with ESMTP id 5B8EC539; Fri, 27 Jun 2003 22:49:18 +0200 (MEST) Received: from acm (x193056-2.shuis-s.tudelft.nl [145.94.193.58]) by listserv.tudelft.nl (8.12.8p1/8.12.8) with ESMTP id h5RKn3Db024520; Fri, 27 Jun 2003 22:49:16 +0200 (MEST) From: "Arjen van der Meijden" To: , "'Patrick Hatcher'" , Subject: Re: Memory question Date: Fri, 27 Jun 2003 22:49:17 +0200 Message-ID: <004901c33ced$98cf6430$3ac15e91@acm> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 In-Reply-To: <200306271254.51441.josh@agliodbs.com> Importance: Normal X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Archive-Number: 200306/197 X-Sequence-Number: 2281 > The "used" figure in Top doesn't really tell you anything, > since it includes > the kernel buffer which tries to take up all available > memory. If you > actually look at the list of processes, I think you'll find > that you're only > using 1-2% of memory for applications. > > I'm not sure what app would show your "real" free memory. The command 'free' shows what you like to know: $ free total used free shared buffers cached Mem: 1551480 1505656 45824 0 101400 1015540 -/+ buffers/cache: 388716 1162764 Swap: 524264 23088 501176 The used/free amounts on the second line are the interesting ones in this case. Arjen From pgsql-performance-owner@postgresql.org Fri Jun 27 17:57:09 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 30F393102A5 for ; Fri, 27 Jun 2003 20:57:08 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 36852-06 for ; Fri, 27 Jun 2003 17:56:57 -0300 (ADT) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by svr1.postgresql.org (Postfix) with ESMTP id 6FA0B3102AA for ; Fri, 27 Jun 2003 17:56:57 -0300 (ADT) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h5RKudA0015020; Fri, 27 Jun 2003 14:56:39 -0600 (MDT) Date: Fri, 27 Jun 2003 14:51:25 -0600 (MDT) From: "scott.marlowe" To: Matthew Hixson Cc: Subject: Re: Memory question In-Reply-To: <30A40B16-A8DE-11D7-81EC-000393669C1A@poindextrose.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailScanner: Found to be clean X-MailScanner-SpamCheck: X-Archive-Number: 200306/199 X-Sequence-Number: 2283 On Fri, 27 Jun 2003, Matthew Hixson wrote: > On Friday, June 27, 2003, at 01:17 PM, Jord Tanner wrote: > > I've heard anecdotally that Linux has troubles if the swap space is > > less > > than the RAM size. I note that you have 6G of RAM, but only 2G of swap. > > I've heard that too, but it doesn't seem to make much sense to me. If > you get to the point where your machine is _needing_ 2GB of swap then > something has gone horribly wrong (or you just need more RAM in the > machine) and it will just crawl until the kernel kills off whatever > process causes the swap space to be exceeded. Seems to me that you > should only have that much swap if you can't afford more RAM or you've > tapped out your machine's capacity, and your application needs that > much memory. This was an artifact in older kernels where the swap code didn't work right unless it had as much swap as memory. I'm pretty sure that was fixed long ago in the 2.4 series. From pgsql-performance-owner@postgresql.org Fri Jun 27 17:55:54 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id A7A1B31030A for ; Fri, 27 Jun 2003 20:55:51 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 36885-04 for ; Fri, 27 Jun 2003 17:55:41 -0300 (ADT) Received: from mailhost3.tudelft.nl (mailhost3.tudelft.nl [130.161.180.83]) by svr1.postgresql.org (Postfix) with ESMTP id 14CA1310398 for ; Fri, 27 Jun 2003 17:55:41 -0300 (ADT) Received: from 127.0.0.1 (localhost [127.0.0.1]) by rav.antivirus (Postfix) with SMTP id DB8B753A; Fri, 27 Jun 2003 22:55:40 +0200 (MEST) Received: from listserv.tudelft.nl (listserv.tudelft.nl [130.161.180.33]) by mailhost3.tudelft.nl (Postfix) with ESMTP id 68097539; Fri, 27 Jun 2003 22:55:40 +0200 (MEST) Received: from acm (x193056-2.shuis-s.tudelft.nl [145.94.193.58]) by listserv.tudelft.nl (8.12.8p1/8.12.8) with ESMTP id h5RKtQDb024581; Fri, 27 Jun 2003 22:55:40 +0200 (MEST) From: "Arjen van der Meijden" To: "'Matthew Hixson'" , Subject: Re: Memory question Date: Fri, 27 Jun 2003 22:55:40 +0200 Message-ID: <004b01c33cee$7e6b2560$3ac15e91@acm> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 In-Reply-To: <30A40B16-A8DE-11D7-81EC-000393669C1A@poindextrose.org> Importance: Normal X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Archive-Number: 200306/198 X-Sequence-Number: 2282 > I've heard that too, but it doesn't seem to make much sense > to me. If > you get to the point where your machine is _needing_ 2GB of swap then > something has gone horribly wrong (or you just need more RAM in the > machine) and it will just crawl until the kernel kills off whatever > process causes the swap space to be exceeded. Seems to me that you > should only have that much swap if you can't afford more RAM > or you've > tapped out your machine's capacity, and your application needs that > much memory. > -M@ I've heard the same, the reason behind it was that there needs to be one-to-one copy of the memory to be able to swap out everything and to have a gain in the total "memory", you'd need twice as much swap as memory to have a doubling of your memory. But afaik this behaviour has been adjusted since the 2.4.5 kernel and isn't a real issue anymore. Please keep in mind that I'm no expert at all on linux, so if you want to be sure, you'd better mail to the kernel-mailinglist orso :) Anyway, I manage a few machines with 1GB++ memory and none of them has more than 1G of swap and none of them uses that swap for more than a few MB unless something was terribly wrong, so the actual 'risk' probably doesn't have a high chance to occur. Arjen From pgsql-performance-owner@postgresql.org Sat Jun 28 06:27:02 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 45C7030FF15 for ; Sat, 28 Jun 2003 09:26:59 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 32298-09 for ; Sat, 28 Jun 2003 06:26:48 -0300 (ADT) Received: from juliette2.openweb.be (juliette2.openweb.be [217.145.32.36]) by svr1.postgresql.org (Postfix) with SMTP id B36F930DCE3 for ; Sat, 28 Jun 2003 06:26:47 -0300 (ADT) Received: (qmail 26696 invoked by uid 585); 28 Jun 2003 09:11:12 -0000 Received: from pgsql-ml@baguette.net by juliette2.openweb.be by uid 582 with qmail-scanner-1.10 (avp. Clear:0. Processed in 2.705535 secs); 28 Jun 2003 09:11:12 -0000 Received: from levure.baguette.net (HELO Morpheus) (217.145.35.101) by juliette2.openweb.be with SMTP; 28 Jun 2003 09:11:09 -0000 From: "Bruno BAGUETTE" To: "'Josh Berkus'" , "'Bruno BAGUETTE'" , Subject: RE : Large querie with several EXISTS which will be often runned Date: Sat, 28 Jun 2003 11:17:42 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.4024 In-Reply-To: <200306270841.40634.josh@agliodbs.com> X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Importance: Normal X-Archive-Number: 200306/200 X-Sequence-Number: 2284 Hello Josh, > > I will have to manage more or less 10.000 products with > more or less > > 2-3 options by products and more or less 40 options-groups. > > > > Do you think that this query will be hard for PostgreSQL (currently > > 7.2.1 but I will migrate to 7.3.2 when going in production > > environment) ? How can I improve that query to be faster ? > > Collapse the inner EXISTS into a straight join in the outer > EXISTS. Since you > are merely checking for existence, there is no reason for the > subquery > nesting. Do you mean this query ? SELECT products_options_groups.pk_prdoptgrp_id,products_options_groups.prdoptgr p_name FROM products_options_groups WHERE EXISTS ( SELECT * FROM products_options_classification INNER JOIN products_options ON products_options.pk_prdopt_id = products_options_classification.fk_prdopt_id WHERE products_options_classification = products_options_groups.pk_prdoptgrp_id AND products_options.fk_prd_id = [A PRODUCT ID WRITTEN HERE BY MY APP] ) ORDER BY products_options_groups.prdoptgrp_name; An other question, do you think that my tables are OK or is there some things I could change in order to have as much performance as possible (without de-normalize it because I want to avoid redundancy in my tables). Thanks very much for your tips ! :-) --------------------------------------- Bruno BAGUETTE - pgsql-ml@baguette.net From pgsql-performance-owner@postgresql.org Sat Jun 28 06:36:08 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 40B5130FF15 for ; Sat, 28 Jun 2003 09:36:03 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 65253-07 for ; Sat, 28 Jun 2003 06:35:51 -0300 (ADT) Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id 5298430F472 for ; Sat, 28 Jun 2003 06:35:49 -0300 (ADT) Received: (from root@localhost) by www.pspl.co.in (8.11.6/8.11.6) id h5S9ZnQ10215 for ; Sat, 28 Jun 2003 15:05:49 +0530 Received: from daithan.intranet.pspl.co.in (daithan.intranet.pspl.co.in [192.168.7.161]) by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h5S9ZmG10210 for ; Sat, 28 Jun 2003 15:05:49 +0530 From: Shridhar Daithankar To: Subject: Re: Large querie with several EXISTS which will be often runned Date: Sat, 28 Jun 2003 15:05:00 +0530 User-Agent: KMail/1.5.2 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200306281505.00407.shridhar_daithankar@nospam.persistent.co.in> X-Archive-Number: 200306/201 X-Sequence-Number: 2285 On Saturday 28 June 2003 14:47, Bruno BAGUETTE wrote: > Do you mean this query ? > > SELECT > products_options_groups.pk_prdoptgrp_id,products_options_groups.prdoptgr > p_name > FROM products_options_groups > WHERE EXISTS > ( > SELECT * > FROM products_options_classification > INNER JOIN products_options ON products_options.pk_prdopt_id = > products_options_classification.fk_prdopt_id > WHERE products_options_classification = > products_options_groups.pk_prdoptgrp_id > AND products_options.fk_prd_id = [A PRODUCT ID WRITTEN HERE BY > MY APP] > ) > ORDER BY products_options_groups.prdoptgrp_name; You can try SELECT products_options_groups.pk_prdoptgrp_id,products_options_groups.prdoptgr p_name FROM products_options_groups WHERE ( SELECT count(*) FROM products_options_classification INNER JOIN products_options ON products_options.pk_prdopt_id = products_options_classification.fk_prdopt_id WHERE products_options_classification = products_options_groups.pk_prdoptgrp_id AND products_options.fk_prd_id = [A PRODUCT ID WRITTEN HERE BY MY APP] )>0 ORDER BY products_options_groups.prdoptgrp_name; The count(*) trick will make it just another subquery and hopefully any performance issues with exists/in does not figure. Some of those issues are fixed in 7.4/CVS head though. HTH Shridhar From pgsql-performance-owner@postgresql.org Sat Jun 28 08:32:04 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 35303310444 for ; Sat, 28 Jun 2003 11:32:03 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 02620-02 for ; Sat, 28 Jun 2003 08:31:52 -0300 (ADT) Received: from mail018.syd.optusnet.com.au (mail018.syd.optusnet.com.au [210.49.20.176]) by svr1.postgresql.org (Postfix) with ESMTP id 685BC310442 for ; Sat, 28 Jun 2003 08:31:51 -0300 (ADT) Received: from COMPCON (armax3-075.dialup.optusnet.com.au [203.164.29.75]) by mail018.syd.optusnet.com.au (8.11.6p2/8.11.6) with SMTP id h5SBVlI12239 for ; Sat, 28 Jun 2003 21:31:48 +1000 Reply-To: From: "Chris Hutchinson" To: Subject: 'best practises' to speed up sorting? tuning postgresql.conf Date: Sat, 28 Jun 2003 21:31:48 +1000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Importance: Normal X-Archive-Number: 200306/202 X-Sequence-Number: 2286 I'm wondering how to speed up sorting which is slowing a query run regularly on a linux postgresql 7.3.3 system. The box is a dual PIII with 1Gb ram. The database is located on a 20Gb SCSI disk, with WAL on a separate disk. The only changes I've made to postgresql.conf so far are: shared_buffers=4000 sort_mem=4000 The results of explain analyze are below. The largest tables in the join, genotypes and ebv, contain 440681 and 3060781 rows respectively, the others contain perhaps a couple of hundred each. I've reduced the runtime of the query to 2 minutes down from 10 minutes by eliminating a left join and ORDER BY, but it would be nice to speed it up further. The time goes up to nearly 6 minutes if I put the ORDER BY back into the query. Any suggestions gratefully received. Regards, Chris Hutchinson ---------------------------------------------------------------------- 'fast query' without sort explain analyze SELECT A.genid,A.name,B.familyid,B.name,B.mumid,B.mumtype,B.dadid, B.dadtype,CBA.title,CA.sctrait,C.nvalue,C.accuracy FROM genotypes A , ebv C , sctraitdefinition CA , tpr CB , tpsystems CBA , geneticfamily B WHERE (C.genid=A.genid) and ((A.speciesid='2') and (B.familyid=A.familyid)) and ((C.runid='72') and (CA.sctraitid=C.sctraitid) and (CB.runid=C.runid) and (CBA.systemid=CB.systemid)); QUERY PLAN ------------------------------------------------------- Hash Join (cost=18114.84..287310.15 rows=678223 width=130) (actual time=11824.24..139737.82 rows=1460290 loops=1) Hash Cond: ("outer".sctraitid = "inner".sctraitid) -> Hash Join (cost=18113.32..273744.17 rows=678223 width=110) (actual time=11813.27..124934.74 rows=1460290 loops=1) Hash Cond: ("outer".runid = "inner".runid) -> Hash Join (cost=18106.69..260173.07 rows=678223 width=73) (actual time=11782.12..107005.61 rows=1460290 loops=1) Hash Cond: ("outer".genid = "inner".genid) -> Seq Scan on ebv c (cost=0.00..195640.76 rows=1392655 width=20) (actual time=4684.71..68728.26 rows=1460290 loops=1) Filter: (runid = 72) -> Hash (cost=15474.16..15474.16 rows=214612 width=53) (actual time=7089.57..7089.57 rows=0 loops=1) -> Hash Join (cost=147.83..15474.16 rows=214612 width=53) (actual time=58.74..6597.01 rows=226561 loops=1) Hash Cond: ("outer".familyid = "inner".familyid) -> Seq Scan on genotypes a (cost=0.00..9424.51 rows=214612 width=17) (actual time=10.47..3914.89 rows=226561 loops=1) Filter: (speciesid = 2) -> Hash (cost=132.46..132.46 rows=6146 width=36) (actual time=48.06..48.06 rows=0 loops=1) -> Seq Scan on geneticfamily b (cost=0.00..132.46 rows=6146 width=36) (actual time=2.90..36.74 rows=6146 loops=1) -> Hash (cost=6.60..6.60 rows=13 width=37) (actual time=31.06..31.06 rows=0 loops=1) -> Hash Join (cost=5.16..6.60 rows=13 width=37) (actual time=30.93..31.04 rows=13 loops=1) Hash Cond: ("outer".systemid = "inner".systemid) -> Seq Scan on tpsystems cba (cost=0.00..1.16 rows=16 width=29) (actual time=6.68..6.72 rows=16 loops=1) -> Hash (cost=5.13..5.13 rows=13 width=8) (actual time=24.17..24.17 rows=0 loops=1) -> Seq Scan on tpr cb (cost=0.00..5.13 rows=13 width=8) (actual time=4.75..24.15 rows=13 loops=1) -> Hash (cost=1.41..1.41 rows=41 width=20) (actual time=10.90..10.90 rows=0 loops=1) -> Seq Scan on sctraitdefinition ca (cost=0.00..1.41 rows=41 width=20) (actual time=10.72..10.82 rows=41 loops=1) Total runtime: 140736.98 msec (24 rows) 'slow query' with sort explain analyze SELECT A.genid,A.name,B.familyid,B.name,B.mumid,B.mumtype,B.dadid, B.dadtype,CBA.title,CA.sctrait,C.nvalue,C.accuracy FROM genotypes A , ebv C , sctraitdefinition CA , tpr CB , tpsystems CBA , geneticfamily B WHERE (C.genid=A.genid) and ((A.speciesid='2') and (B.familyid=A.familyid)) and ((C.runid='72') and (CA.sctraitid=C.sctraitid) and (CB.runid=C.runid) and (CBA.systemid=CB.systemid)) ORDER BY A.genid ASC,B.familyid ASC,CA.sctrait ASC; QUERY PLAN ------------------------------------------------------- Sort (cost=540740.81..542436.37 rows=678223 width=130) (actual time=322602.06..346710.43 rows=1460290 loops=1) Sort Key: a.genid, b.familyid, ca.sctrait -> Hash Join (cost=18114.84..287310.15 rows=678223 width=130) (actual time=10398.55..144991.62 rows=1460290 loops=1) Hash Cond: ("outer".sctraitid = "inner".sctraitid) -> Hash Join (cost=18113.32..273744.17 rows=678223 width=110) (actual time=10384.84..129637.23 rows=1460290 loops=1) Hash Cond: ("outer".runid = "inner".runid) -> Hash Join (cost=18106.69..260173.07 rows=678223 width=73) (actual time=10353.69..111239.94 rows=1460290 loops=1) Hash Cond: ("outer".genid = "inner".genid) -> Seq Scan on ebv c (cost=0.00..195640.76 rows=1392655 width=20) (actual time=4499.94..74509.34 rows=1460290 loops=1) Filter: (runid = 72) -> Hash (cost=15474.16..15474.16 rows=214612 width=53) (actual time=5845.85..5845.85 rows=0 loops=1) -> Hash Join (cost=147.83..15474.16 rows=214612 width=53) (actual time=58.75..5346.04 rows=226561 loops=1) Hash Cond: ("outer".familyid = "inner".familyid) -> Seq Scan on genotypes a (cost=0.00..9424.51 rows=214612 width=17) (actual time=7.00..2799.43 rows=226561 loops=1) Filter: (speciesid = 2) -> Hash (cost=132.46..132.46 rows=6146 width=36) (actual time=51.54..51.54 rows=0 loops=1) -> Seq Scan on geneticfamily b (cost=0.00..132.46 rows=6146 width=36) (actual time=2.88..39.66 rows=6146 loops=1) -> Hash (cost=6.60..6.60 rows=13 width=37) (actual time=31.05..31.05 rows=0 loops=1) -> Hash Join (cost=5.16..6.60 rows=13 width=37) (actual time=30.92..31.03 rows=13 loops=1) Hash Cond: ("outer".systemid = "inner".systemid) -> Seq Scan on tpsystems cba (cost=0.00..1.16 rows=16 width=29) (actual time=6.67..6.72 rows=16 loops=1) -> Hash (cost=5.13..5.13 rows=13 width=8) (actual time=24.17..24.17 rows=0 loops=1) -> Seq Scan on tpr cb (cost=0.00..5.13 rows=13 width=8) (actual time=4.72..24.14 rows=13 loops=1) -> Hash (cost=1.41..1.41 rows=41 width=20) (actual time=13.62..13.62 rows=0 loops=1) -> Seq Scan on sctraitdefinition ca (cost=0.00..1.41 rows=41 width=20) (actual time=13.43..13.54 rows=41 loops=1) Total runtime: 347780.04 msec (26 rows) The tables look like this: Table "public.ebv" Column | Type | Modifiers -----------+---------+----------- runid | integer | not null genid | integer | not null sctraitid | integer | not null nvalue | real | not null accuracy | real | Indexes: idx_ebg btree (genid), idx_ebv btree (runid), idx_ebvr btree (runid) Table "public.genotypes" Column | Type | Modifiers ----------------+--------------------------+-------------------------------- ------------------------- genid | integer | not null default nextval('"genotypes_genid_seq"'::text) speciesid | integer | not null familyid | integer | not null created | timestamp with time zone | not null batchid | integer | not null lastmodifiedby | integer | not null lastmodified | timestamp with time zone | not null name | character varying(100) | Indexes: genotypes_pkey primary key btree (genid), idx_gnm unique btree (speciesid, name), idx_gb btree (batchid), idxc btree (created), idxgf btree (familyid), idxgsp btree (speciesid) Table "public.tpr" Column | Type | Modifiers ---------------+--------------------------+--------------------------------- -------------------------- runid | integer | not null default nextval('"tpr_runid_seq"'::text) description | text | not null systemid | integer | not null runlog | text | ranby | integer | not null whenrun | timestamp with time zone | not null valid_p | character(1) | not null default 'f' whenvalidated | timestamp with time zone | whovalidated | integer | notes | text | Indexes: tpr_pkey primary key btree (runid), idx_tprv btree (valid_p) Table "public.geneticfamily" Column | Type | Modifiers ----------------+--------------------------+-------------------------------- -------------------------------- familyid | integer | not null default nextval('"geneticfamily_familyid_seq"'::text) speciesid | integer | not null mumid | integer | not null mumtype | character(1) | not null dadid | integer | not null dadtype | character(1) | not null batchid | integer | not null lastmodifiedby | integer | not null lastmodified | timestamp with time zone | name | character varying(100) | Indexes: geneticfamily_pkey primary key btree (familyid), idu_gfam unique btree (mumid, dadid, mumtype, dadtype), idx_gfnm unique btree (speciesid, name), idx_gfb btree (batchid), idx_gfun btree (upper(name)), idxgfd btree (dadid), idxgff btree (mumid, dadid), idxgfm btree (mumid), idxpsp btree (speciesid) Table "public.tpsystems" Column | Type | Modifiers ------------------+--------------------------+------------------------------ ------------------------------ systemid | integer | not null default nextval('"tpsystems_systemid_seq"'::text) speciesid | integer | not null title | character varying(250) | not null description | text | lastmodifiedby | integer | not null lastmodified | timestamp with time zone | not null variancechecksum | character varying(32) | Indexes: tpsystems_pkey primary key btree (systemid) Table "public.sctraitdefinition" Column | Type | Modifiers --------------------+--------------------------+---------------------------- ----------------------------------------- sctraitid | integer | not null default nextval('"sctraitdefinition_sctraitid_seq"'::text) speciesid | integer | not null sctrait | character varying(32) | not null lastmodifiedby | integer | not null lastmodified | timestamp with time zone | not null datatype | character varying(32) | datatransformation | character varying(32) | Indexes: sctraitdefinition_pkey primary key btree (sctraitid), idu_sctd unique btree (speciesid, sctrait) -------------------------------------------------------------------------- 'top' looks like this most of the time.. (except when queries are running) 8:40pm up 54 days, 7:45, 2 users, load average: 0.00, 0.19, 0.32 44 processes: 43 sleeping, 1 running, 0 zombie, 0 stopped CPU0 states: 0.1% user, 0.0% system, 0.0% nice, 99.4% idle CPU1 states: 0.0% user, 0.0% system, 0.0% nice, 100.0% idle Mem: 1028428K av, 846776K used, 181652K free, 0K shrd, 1580K buff Swap: 530104K av, 53540K used, 476564K free 804148K cached From pgsql-performance-owner@postgresql.org Sat Jun 28 08:50:30 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 999EA3103AD for ; Sat, 28 Jun 2003 11:38:53 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 77998-09 for ; Sat, 28 Jun 2003 08:38:42 -0300 (ADT) Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id 276BD3103AA for ; Sat, 28 Jun 2003 08:38:41 -0300 (ADT) Received: (from root@localhost) by www.pspl.co.in (8.11.6/8.11.6) id h5SBcfX15877 for ; Sat, 28 Jun 2003 17:08:41 +0530 Received: from daithan.intranet.pspl.co.in (daithan.intranet.pspl.co.in [192.168.7.161]) by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h5SBceG15872 for ; Sat, 28 Jun 2003 17:08:41 +0530 From: Shridhar Daithankar To: Subject: Re: 'best practises' to speed up sorting? tuning postgresql.conf Date: Sat, 28 Jun 2003 17:07:52 +0530 User-Agent: KMail/1.5.2 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200306281707.52317.shridhar_daithankar@nospam.persistent.co.in> X-Archive-Number: 200306/203 X-Sequence-Number: 2287 On Saturday 28 June 2003 17:01, Chris Hutchinson wrote: > I'm wondering how to speed up sorting which is slowing a query run > regularly on a linux postgresql 7.3.3 system. > > The box is a dual PIII with 1Gb ram. The database is located on a 20Gb SCSI > disk, with WAL on a separate disk. > > The only changes I've made to postgresql.conf so far are: > shared_buffers=4000 > sort_mem=4000 sort_mem is in kbs. So you are setting it roughyl 4MB. Given that you don't seem to have any shortage of RAM, how about 32/64/128MB RAM till things work as expected? Of course, setting it so in postgresql.conf would be a bad idea. Just set for the session that makes this query and reset it back. Keep us posted on updates.. Shridhar From pgsql-performance-owner@postgresql.org Sat Jun 28 08:58:32 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id C0B3E3103AA for ; Sat, 28 Jun 2003 11:58:29 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 73105-10 for ; Sat, 28 Jun 2003 08:58:19 -0300 (ADT) Received: from mailhost3.tudelft.nl (mailhost3.tudelft.nl [130.161.180.83]) by svr1.postgresql.org (Postfix) with ESMTP id 6150C31044F for ; Sat, 28 Jun 2003 08:58:18 -0300 (ADT) Received: from 127.0.0.1 (localhost [127.0.0.1]) by rav.antivirus (Postfix) with SMTP id 41E40479; Sat, 28 Jun 2003 13:58:18 +0200 (MEST) Received: from listserv.tudelft.nl (listserv.tudelft.nl [130.161.180.33]) by mailhost3.tudelft.nl (Postfix) with ESMTP id 77F1D464; Sat, 28 Jun 2003 13:58:17 +0200 (MEST) Received: from acm (x193056-2.shuis-s.tudelft.nl [145.94.193.58]) by listserv.tudelft.nl (8.12.8p1/8.12.8) with ESMTP id h5SBvtDb006297; Sat, 28 Jun 2003 13:58:16 +0200 (MEST) From: "Arjen van der Meijden" To: , Subject: Re: 'best practises' to speed up sorting? tuning postgresql.conf Date: Sat, 28 Jun 2003 13:58:09 +0200 Message-ID: <001001c33d6c$9590c140$3ac15e91@acm> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal X-Archive-Number: 200306/204 X-Sequence-Number: 2288 > Chris Hutchinson wrote: > I'm wondering how to speed up sorting which is slowing a > query run regularly on a linux postgresql 7.3.3 system. I see a lot of seq scans in your explain and there are no index scans, have you done a 'vacuum analyze' lately? Arjen From pgsql-performance-owner@postgresql.org Mon Jun 30 02:50:14 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 7E474310887 for ; Mon, 30 Jun 2003 05:50:05 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 91425-09 for ; Mon, 30 Jun 2003 02:49:55 -0300 (ADT) Received: from stubee.d2hosting.net (d2hosting.net [66.70.41.160]) by svr1.postgresql.org (Postfix) with ESMTP id 97B323108E0 for ; Mon, 30 Jun 2003 02:49:54 -0300 (ADT) Received: from idigx.com (cable-68-114-110-47.sli.la.charter.com [68.114.110.47]) by stubee.d2hosting.net (8.11.6/linuxconf) with ESMTP id h5U5njq32426; Mon, 30 Jun 2003 00:49:46 -0500 Message-ID: <3EFFCF73.8010801@idigx.com> Date: Mon, 30 Jun 2003 00:49:39 -0500 From: Thomas Swan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030628 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Arjen van der Meijden Cc: "'Matthew Hixson'" , pgsql-performance@postgresql.org Subject: Re: Memory question References: <004b01c33cee$7e6b2560$3ac15e91@acm> In-Reply-To: <004b01c33cee$7e6b2560$3ac15e91@acm> X-Enigmail-Version: 0.76.1.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/205 X-Sequence-Number: 2289 Arjen van der Meijden wrote: >>I've heard that too, but it doesn't seem to make much sense >>to me. If >>you get to the point where your machine is _needing_ 2GB of swap then >>something has gone horribly wrong (or you just need more RAM in the >>machine) and it will just crawl until the kernel kills off whatever >>process causes the swap space to be exceeded. Seems to me that you >>should only have that much swap if you can't afford more RAM >>or you've >>tapped out your machine's capacity, and your application needs that >>much memory. >> -M@ >> >> >I've heard the same, the reason behind it was that there needs to be >one-to-one copy of the memory to be able to swap out everything and to >have a gain in the total "memory", you'd need twice as much swap as >memory to have a doubling of your memory. > >But afaik this behaviour has been adjusted since the 2.4.5 kernel and >isn't a real issue anymore. > It may be different in vendor released kernels as the default overcommit behavior of the Linux kernel may vary. More detailed discussions can be found on the LKML, or you can find some useful summaries by searching through the last couple "Kernel Traffic" issues .. I had some unexpected problems on one system, an older RH distribution, until I actually set the swap to be double the 2GB of ram on the system: 4GB. >Please keep in mind that I'm no expert at all on linux, so if you want >to be sure, you'd better mail to the kernel-mailinglist orso :) > >Anyway, I manage a few machines with 1GB++ memory and none of them has >more than 1G of swap and none of them uses that swap for more than a few >MB unless something was terribly wrong, so the actual 'risk' probably >doesn't have a high chance to occur. > >Arjen > > > > >---------------------------(end of broadcast)--------------------------- >TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html > > From pgsql-performance-owner@postgresql.org Mon Jun 30 13:02:36 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id E7E9E3109F7 for ; Mon, 30 Jun 2003 16:02:32 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 07396-06 for ; Mon, 30 Jun 2003 13:02:22 -0300 (ADT) Received: from irko.smoothcorp.com (unknown [208.49.241.41]) by svr1.postgresql.org (Postfix) with ESMTP id CD052310958 for ; Mon, 30 Jun 2003 13:02:21 -0300 (ADT) Received: from jgardner.ifloor.com ([10.0.1.63]) by irko.smoothcorp.com with esmtp (Exim 4.12) id 19X16b-0004pF-00; Mon, 30 Jun 2003 09:02:13 -0700 Received: from jgardner.ifloor.com (localhost.localdomain [127.0.0.1]) by jgardner.ifloor.com (8.12.8/8.12.8) with ESMTP id h5UG2EHK021969; Mon, 30 Jun 2003 09:02:14 -0700 Received: from localhost (localhost [[UNIX: localhost]]) by jgardner.ifloor.com (8.12.8/8.12.8/Submit) id h5UG2DWq021967; Mon, 30 Jun 2003 09:02:13 -0700 From: Jonathan Gardner To: "scott.marlowe" , Patrick Hatcher Subject: Re: Memory question Date: Mon, 30 Jun 2003 09:02:12 -0700 User-Agent: KMail/1.5 Cc: References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Description: clearsigned data Content-Disposition: inline Message-Id: <200306300902.13161.jgardner@jonathangardner.net> X-SA-Exim-Rcpt-To: scott.marlowe@ihs.com, PHatcher@macys.com, pgsql-performance@postgresql.org X-SA-Exim-Scanned: No; SAEximRunCond expanded to false X-Archive-Number: 200306/206 X-Sequence-Number: 2290 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Friday 27 June 2003 12:44, scott.marlowe wrote: > This is actually normal. Look at the amount cached: 6257620K. That's > 6.2Gig of cache. Linux is using only 6517776k - 6257620k of memory, the > rest is just acting as kernel cache. If anything tries to allocate a bit > of memory, linux will flush enough cache to give the memory to the > application that needs it. > I think it is appropriate to add that the Linux kernel does this in an=20 extremely innovative and intelligent way. The more room you give your kerne= l=20 to cache, the more responsive it is going to be. - --=20 Jonathan Gardner (was jgardn@alumni.washington.edu) Live Free, Use Linux! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE/AF8EWgwF3QvpWNwRArmVAJwK5C2ExmS8Rayrne33UJ0KZZM4UgCgq7b5 3J1LGtofgtnKq/bPtF75lNI=3D =3D4Not -----END PGP SIGNATURE----- From pgsql-performance-owner@postgresql.org Mon Jun 30 15:00:13 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id CCF23310A2D for ; Mon, 30 Jun 2003 18:00:11 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 37727-06 for ; Mon, 30 Jun 2003 14:59:59 -0300 (ADT) Received: from root.iarchives.com (unknown [64.90.195.10]) by svr1.postgresql.org (Postfix) with ESMTP id 2CA753109F3 for ; Mon, 30 Jun 2003 14:59:59 -0300 (ADT) Received: from zucchini ([192.168.100.34]) by root.iarchives.com with Microsoft SMTPSVC(5.0.2195.5329); Mon, 30 Jun 2003 11:58:37 -0600 Message-ID: <032101c33f31$0d239910$2264a8c0@zucchini> From: "Robert Wille" To: Subject: Query planner plans very inefficient plans Date: Mon, 30 Jun 2003 11:57:20 -0600 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_031E_01C33EFE.C28187F0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 X-OriginalArrivalTime: 30 Jun 2003 17:58:37.0693 (UTC) FILETIME=[3B4682D0:01C33F31] X-Archive-Number: 200306/207 X-Sequence-Number: 2291 This is a multi-part message in MIME format. ------=_NextPart_000_031E_01C33EFE.C28187F0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I have a number of very common queries that the optimizer plans a very inef= ficient plan. I vacuum hourly. I'm wondering what I can do to make the quer= ies faster. Here are the relevant tables: create table image( imageid integer not null, /* The image's ID */ containerid integer not null, /* The container that owns it */ name varchar(120) not null, /* Its name */ state bigint not null default 0, /* Its state */ primary key (imageid), unique (containerid, name) /* All images in a container must be uni= quely named */ ); create table ancestry( containerid integer not null, /* The container that has an ancestor= */ ancestorid integer not null, /* The ancestor of the container */ unique (containerid, ancestorid), unique (ancestorid, containerid) ); I have somewhere around 3M rows in the image table, and 37K rows in the anc= estry table. The following is representative of some of the common queries = I issue: select * from image natural join ancestry where ancestorid=3D1000000 and (s= tate & 7::bigint) =3D 0::bigint; When I ask postgres to EXPLAIN it, I get the following: Merge Join (cost=3D81858.22..81900.60 rows=3D124 width=3D49) -> Sort (cost=3D81693.15..81693.15 rows=3D16288 width=3D41) -> Seq Scan on image (cost=3D0.00..80279.17 rows=3D16288 width=3D= 41) -> Sort (cost=3D165.06..165.06 rows=3D45 width=3D8) -> Index Scan using ancestry_ancestorid_key on ancestry (cost=3D0= .00..163.83 rows=3D45 width=3D8) It appears to me that the query executes as follows: 1. Scan every row in the image table to find those where (state & 7::bigint= ) =3D 0::bigint 2. Sort the results 3. Use an index on ancestry to find rows where ancestorid=3D1000000 4. Sort the results 5. Join the two It seems to me that if this query is going to return a small percentage of = the rows (which is the common case), it could be done much faster by first = joining (all columns involved in the join are indexed), and then by applyin= g the (state & 7::bigint) =3D 0::bigint constraint to the results. Similarly, when I update, I get the following: explain update image set state=3D0 from ancestry where ancestorid=3D1000000= and ancestry.containerid=3Dimage.containerid and (state & 7::bigint) =3D 0= ::bigint; NOTICE: QUERY PLAN: Merge Join (cost=3D81841.92..81884.30 rows=3D124 width=3D43) -> Sort (cost=3D81676.74..81676.74 rows=3D16288 width=3D39) -> Seq Scan on image (cost=3D0.00..80279.17 rows=3D16288 width=3D= 39) -> Sort (cost=3D165.19..165.19 rows=3D45 width=3D4) -> Index Scan using ancestry_ancestorid_key on ancestry (cost=3D0= .00..163.95 rows=3D45 width=3D4) How can I avoid the sequential scan of the entire image table (i.e. how can= I get it to perform the join first)? Thanks in advance. Robert Wille ------=_NextPart_000_031E_01C33EFE.C28187F0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I have a number of very common queries tha= t the=20 optimizer plans a very inefficient plan. I vacuum hourly. I'm wondering wha= t I=20 can do to make the queries faster.
 
Here are the relevant tables:
 
create table image(
    = imageid=20 integer not null,     /* The image's ID */
<= /DIV>
    containerid integer not= =20 null,     /* The container that owns it=20 */
    name varchar(120) not=20 null,     /* Its name */
    state bigint not null d= efault=20 0,    /* Its state */
    primary key= =20 (imageid),
    unique (containerid,=20 name)     /* All images in a container must be uni= quely=20 named */
);
 
create table ancestry(
  &nbs= p;=20 containerid integer not null,     /* The container= that=20 has an ancestor */
    ancestorid integer not=20 null,     /* The ancestor of the container=20 */
    unique (containerid, ancestorid),
  &= nbsp;=20 unique (ancestorid, containerid)
);
 
I have somewhere around 3M rows in the ima= ge table,=20 and 37K rows in the ancestry table. The following is representative of some= of=20 the common queries I issue:
 
select * from image natural join ancestry = where=20 ancestorid=3D1000000 and (state & 7::bigint) =3D 0::bigint;
 
When I ask postgres to EXPLAIN it, I get t= he=20 following:
 
Merge Join  (cost=3D81858.22..81900.6= 0 rows=3D124=20 width=3D49)
  ->  Sort  (cost=3D81693.15..81693.15 row= s=3D16288=20 width=3D41)
        ->  Seq S= can on=20 image  (cost=3D0.00..80279.17 rows=3D16288 width=3D41)
  ->=  =20 Sort  (cost=3D165.06..165.06 rows=3D45=20 width=3D8)
        ->  Index = Scan=20 using ancestry_ancestorid_key on ancestry  (cost=3D0.00..163.83 rows= =3D45=20 width=3D8)
 
It appears to me that the query executes a= s=20 follows:
 
1. Scan every row in the image table to fi= nd those=20 where (state & 7::bigint) =3D 0::bigint
2. Sort the results
3. Use an index on ancestry to find rows w= here=20 ancestorid=3D1000000
4. Sort the results
5. Join the two
 
It seems to me that if this query is going= to=20 return a small percentage of the rows (which is the common case), it could = be=20 done much faster by first joining (all columns involved in the join are=20 indexed), and then by applying the (state & 7::bigint) =3D 0::bigint=20 constraint to the results.
 
Similarly, when I update, I get the=20 following:
 
explain update image set state=3D0 from an= cestry=20 where ancestorid=3D1000000 and ancestry.containerid=3Dimage.containerid and= (state=20 & 7::bigint) =3D 0::bigint;
 
NOTICE:  QUERY PLAN:
 
Merge Join  (cost=3D81841.92..81884.3= 0 rows=3D124=20 width=3D43)
  ->  Sort  (cost=3D81676.74..81676.74 row= s=3D16288=20 width=3D39)
        ->  Seq S= can on=20 image  (cost=3D0.00..80279.17 rows=3D16288 width=3D39)
  ->=  =20 Sort  (cost=3D165.19..165.19 rows=3D45=20 width=3D4)
        ->  Index = Scan=20 using ancestry_ancestorid_key on ancestry  (cost=3D0.00..163.95 rows= =3D45=20 width=3D4)
 
How can I avoid the sequential scan of the= entire=20 image table (i.e. how can I get it to perform the join first)?

Thanks in advance.
 
Robert Wille
 
------=_NextPart_000_031E_01C33EFE.C28187F0-- From pgsql-performance-owner@postgresql.org Mon Jun 30 16:05:39 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 519D431082B for ; Mon, 30 Jun 2003 19:05:38 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 60659-01 for ; Mon, 30 Jun 2003 16:05:27 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 35A5B30FCE1 for ; Mon, 30 Jun 2003 16:05:27 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5UJ5QQQ016645; Mon, 30 Jun 2003 15:05:26 -0400 (EDT) To: "Robert Wille" Cc: pgsql-performance@postgresql.org Subject: Re: Query planner plans very inefficient plans In-reply-to: <032101c33f31$0d239910$2264a8c0@zucchini> References: <032101c33f31$0d239910$2264a8c0@zucchini> Comments: In-reply-to "Robert Wille" message dated "Mon, 30 Jun 2003 11:57:20 -0600" Date: Mon, 30 Jun 2003 15:05:26 -0400 Message-ID: <16644.1056999926@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/208 X-Sequence-Number: 2292 "Robert Wille" writes: > select * from image natural join ancestry where ancestorid=1000000 and > (state & 7::bigint) = 0::bigint; The planner is not going to have any statistics that allow it to predict the number of rows satisfying that &-condition, and so it's unsurprising if its off-the-cuff guess has little to do with reality. I'd recommend skipping any cute tricks with bit-packing, and storing the state (and any other values you query frequently) as its own column, so that the query looks like select * from image natural join ancestry where ancestorid=1000000 and state = 0; ANALYZE should be able to do a reasonable job with a column that has 8 or fewer distinct values ... regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jun 30 18:13:50 2003 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 9F672310AC7 for ; Mon, 30 Jun 2003 21:13:49 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 85652-01 for ; Mon, 30 Jun 2003 18:13:38 -0300 (ADT) Received: from perrin.int.nxad.com (internal.ext.nxad.com [69.1.70.251]) by svr1.postgresql.org (Postfix) with ESMTP id 7A4C0310ABD for ; Mon, 30 Jun 2003 18:13:37 -0300 (ADT) Received: by perrin.int.nxad.com (Postfix, from userid 1001) id 4F4E421058; Mon, 30 Jun 2003 14:13:36 -0700 (PDT) Date: Mon, 30 Jun 2003 14:13:36 -0700 From: Sean Chittenden To: Robert Wille Cc: pgsql-performance@postgresql.org Subject: Re: Query planner plans very inefficient plans Message-ID: <20030630211336.GF96753@perrin.int.nxad.com> References: <032101c33f31$0d239910$2264a8c0@zucchini> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <032101c33f31$0d239910$2264a8c0@zucchini> X-PGP-Key: finger seanc@FreeBSD.org X-PGP-Fingerprint: 3849 3760 1AFE 7B17 11A0 83A6 DD99 E31F BC84 B341 X-Web-Homepage: http://sean.chittenden.org/ User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/209 X-Sequence-Number: 2293 > I have somewhere around 3M rows in the image table, and 37K rows in the > ancestry table. The following is representative of some of the common > queries I issue: > > select * from image natural join ancestry where ancestorid=1000000 and > (state & 7::bigint) = 0::bigint; > > When I ask postgres to EXPLAIN it, I get the following: > > Merge Join (cost=81858.22..81900.60 rows=124 width=49) > -> Sort (cost=81693.15..81693.15 rows=16288 width=41) > -> Seq Scan on image (cost=0.00..80279.17 rows=16288 width=41) > -> Sort (cost=165.06..165.06 rows=45 width=8) > -> Index Scan using ancestry_ancestorid_key on ancestry > (cost=0.00..163.83 rows=45 width=8) > > It appears to me that the query executes as follows: > > 1. Scan every row in the image table to find those where (state & > 7::bigint) = 0::bigint > 2. Sort the results > 3. Use an index on ancestry to find rows where ancestorid=1000000 > 4. Sort the results > 5. Join the two FWIW, I use INTs as bit vectors for options in various applications and have run into this in a few cases. In the database, I only care about a few bits in the options INT, so what I did was create a function for each of the bits that I care about and then a function index. Between the two, I've managed to solve my performance problems. CREATE FUNCTION app_option_foo_is_set(INT) RETURNS BOOL IMMUTABLE AS ' BEGIN IF $1 & 7::INT THEN RETURN TRUE; ELSE RETURN FALSE; END IF; END; ' LANGUAGE 'plpgsql'; CREATE INDEX app_option_foo_fidx ON app_option_tbl (app_option_foo_is_set(options)); VACUUM ANALYZE; Just make sure that you set your function to be IMMUTABLE. -sc PS It'd be slick if PostgreSQL would collapse adjacent booleans into a bit in a byte: it'd save some apps a chunk of space. 32 options == 32 bytes with the type BOOL, but if adjacent BOOLs were collapsed, it'd only be 4 bytes on disk and maybe some page header data. -- Sean Chittenden