Received: from sunpine.krs.ru (SunPine.krs.ru [195.161.16.37]) by hub.org (8.9.3/8.9.3) with ESMTP id CAA66229; Mon, 26 Jul 1999 02:26:42 -0400 (EDT) (envelope-from vadim@krs.ru) Received: from krs.ru (dune.krs.ru [195.161.16.38]) by sunpine.krs.ru (8.8.8/8.8.8) with ESMTP id OAA02023; Mon, 26 Jul 1999 14:26:08 +0800 (KRSS) Sender: root@sunpine.krs.ru Message-ID: <379BFF7E.BD57269E@krs.ru> Date: Mon, 26 Jul 1999 14:26:06 +0800 From: Vadim Mikheev Organization: OJSC Rostelecom (Krasnoyarsk) X-Mailer: Mozilla 4.5 [en] (X11; I; FreeBSD 3.0-RELEASE i386) X-Accept-Language: ru, en MIME-Version: 1.0 To: Oleg Bartunov CC: Tom Lane , pgsql-hackers@postgreSQL.org, pgsql-sql@postgreSQL.org Subject: Re: [SQL] inserts/updates problem under stressing ! References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Oleg Bartunov wrote: > > > > > SELECT FOR UPDATE will not help: if there was no record for > > particular key then nothing will be locked and two records with > > the same key will be inserted. > > > > Oleg, use LOCK IN SHARE ROW EXCLUSIVE MODE. > > Thanks Vadim. Just tried this, but still I see a difference between > count hits (accumulated) from db and access_log. In my test these numbers are: > 95 and 109. So I lost 14 hits ! And no errors ! > In my handler I have now: > > my $sth = $dbh->do("LOCK TABLE hits IN SHARE ROW EXCLUSIVE MODE"); > my $sth = $dbh->do("SELECT acc_hits($1)") || die $dbh->errstr; > > am I right ? You should run LOCK and SELECT inside BEGIN/END (i.e. in the same transaction), do you? Vadim