X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 10774D1B526 for ; Tue, 9 Sep 2003 14:41:25 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 16452-05 for ; Tue, 9 Sep 2003 11:40:55 -0300 (ADT) Received: from anchor-post-30.mail.demon.net (anchor-post-30.mail.demon.net [194.217.242.88]) by svr1.postgresql.org (Postfix) with ESMTP id 60EC5D1B4F6 for ; Tue, 9 Sep 2003 11:40:51 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-30.mail.demon.net with esmtp (Exim 3.35 #1) id 19wjfr-000J1k-0U; Tue, 09 Sep 2003 15:40:55 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 5E420177A3; Tue, 9 Sep 2003 15:40:54 +0100 (BST) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 15F591720E; Tue, 9 Sep 2003 15:40:53 +0100 (BST) From: Richard Huxton To: "Mindaugas Riauba" , Subject: Re: Need advice about triggers Date: Tue, 9 Sep 2003 15:40:51 +0100 User-Agent: KMail/1.5 References: <00be01c376cf$91510620$f20214ac@bite.lt> <200309091414.23458.dev@archonet.com> <00dc01c376d6$f9f99c30$f20214ac@bite.lt> In-Reply-To: <00dc01c376d6$f9f99c30$f20214ac@bite.lt> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_zZeX/rn0IcgGLdE" Message-Id: <200309091540.51382.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/153 X-Sequence-Number: 3519 --Boundary-00=_zZeX/rn0IcgGLdE Content-Type: text/plain; charset="windows-1257" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Tuesday 09 September 2003 14:33, Mindaugas Riauba wrote: > > Well, try it without the trigger. If performance improves markedly, it > might > > be worth rewriting in C. > > Nope. Execution time is practically the same without trigger. OK - no point in rewriting it then. > > If not, you're probably saturating the disk I/O - using iostat/vmstat > > will > > let > > > you see what's happening. If it is your disks, you might see if moving > > the WAL onto a separate drive would help, or check the archives for > > plenty of discussion about raid setups. > > Bottleneck in this case is CPU. postmaster process uses almost 100% of > CPU. > Disk I/O should not be a problem in this case. vmstat shows ~300kb/s > write activity. Hmm - I must admit I wasn't expecting that. Closest I can get on my test machine here: AMD 400MHz / 256MB / IDE disk / other stuff running is about 20 secs. I've attached the perl script I used - what sort of timings does it give you? -- Richard Huxton Archonet Ltd --Boundary-00=_zZeX/rn0IcgGLdE Content-Type: text/x-perl; charset="windows-1257"; name="big_update_test.pl" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="big_update_test.pl" #!/usr/bin/perl -w use DBI; use Benchmark; # How many clients, how many inserts each my $num_upd = 10000; my $num_rows = 1000; my $dbname = "richardh"; my $dbh = DBI->connect("dbi:Pg:dbname=$dbname", "", ""); # Comment out create_table after the first run. create_table($dbh, $num_rows); my $t0 = new Benchmark; run_updates($dbh, $num_rows, $num_upd); my $t1 = new Benchmark; $td = timediff($t1, $t0); print "the code took:",timestr($td),"\n"; $dbh->disconnect; exit; sub create_table { my $dbh = shift; my $num_rows = shift; my $sth = $dbh->prepare("CREATE TABLE foo (a int4, v varchar(100), t timestamp with time zone, PRIMARY KEY (a))"); $sth->execute or die $dbh->errstr; $sth = $dbh->prepare("INSERT INTO foo (a,v,t) VALUES (?,?,now())"); my $vartext = 'AAAAAAAA'; for (my $i=0; $i<$num_rows; $i++) { $sth->execute($i,$vartext) or die $dbh->errstr; $vartext++; } } sub run_updates { my $dbh = shift; my $num_rows = shift; my $num_upd = shift; my $batchsize = 500; my $sth = $dbh->prepare("UPDATE foo SET t=now() WHERE a=?"); for (my $i=0; $i<$num_upd; $i++) { if ($i % $batchsize==0) { $dbh->begin_work; } if ($i % $batchsize==499) { $dbh->commit; print "update $i\n"; $dbh->do("VACUUM foo;"); } $sth->execute() or die $dbh->errstr; } } --Boundary-00=_zZeX/rn0IcgGLdE--