X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id B04C9D1B568 for ; Tue, 28 Oct 2003 14:17:16 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 00849-03 for ; Tue, 28 Oct 2003 10:16:49 -0400 (AST) Received: from dhcp-7-248.ma.lycos.com (waltham-nat.ma.lycos.com [209.202.205.1]) by svr1.postgresql.org (Postfix) with SMTP id 55E59D1B54B for ; Tue, 28 Oct 2003 10:16:45 -0400 (AST) Received: (qmail 26233 invoked from network); 28 Oct 2003 14:18:37 -0000 Received: from dhcp-7-41.ma.lycos.com (HELO squeegit) (10.124.7.41) by dhcp-7-248.ma.lycos.com with SMTP; 28 Oct 2003 14:18:37 -0000 Date: Tue, 28 Oct 2003 09:16:45 -0500 From: Jeff To: pgsql-performance@postgresql.org Subject: Adding foreign key performance Message-Id: <20031028091645.3d610841.threshar@torgo.978.org> X-Mailer: Sylpheed version 0.9.7 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/700 X-Sequence-Number: 4448 I recalled seeing a thread on -HACKERS about some major improvements to the speed of adding an FK to an existing table in 7.4. Naturally I was curious and decided to give it a whirl. My findings are not too good. In fact, they are bad. Could it be this patch never made it in? Anyway, here's the info. Machine: Linux 2.4.18 [stock rh8], p3 500, 512mb, 4x18GB scsi raid 0 Two tables: members and watchedmembers with 1045720 and 829994 rows respectivly. freshly vacuum analyze'd for each PG: 7.4b4, 10k shared buff, 256mb effective cache: 485706ms 7.3.4 [same settings]: 412304.76 ms Now the odd thing during that operation was that the machine was about oh, 50-70% _idle_ during the whole time. Then I started thinking more about it and realized hearing if you bump sort_mem up ridiculously high during a foreign key add it helps. So I did. Bumped it up to 256MB. [again, vacuum analyze'd each beforehand] 7.3.4: 328912ms [cpu pegged] 7.4b4: 298383ms [cpu pegged] Quite an improvement I'd say. Perhaps we should make note of this somewhere? Performance guide? Docs? And this leads to the place we'd get a huge benefit: Restoring backups.. If there were some way to bump up sort_mem while doing the restore.. things would be much more pleasant. [Although, even better would be to disable FK stuff while restoring a backup and assume the backup is "sane"] How we'd go about doing that is the subject of much debate. Perhaps add the functionality to pg_restore? ie, pg_restore -s 256MB mybackup.db? It would just end up issuing a set sort_mem=256000.. What do you guys think? -- Jeff Trout http://www.jefftrout.com/ http://www.stuarthamm.net/