Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id EF2E59FA31C for ; Tue, 18 Sep 2007 13:22:33 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 04281-01-8 for ; Tue, 18 Sep 2007 13:22:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mx00.pub.collaborativefusion.com (mx00.pub.collaborativefusion.com [206.210.89.199]) by postgresql.org (Postfix) with ESMTP id 3D4F69FA5A6 for ; Tue, 18 Sep 2007 13:18:52 -0300 (ADT) Received: from vanquish.pitbpa0.priv.collaborativefusion.com (vanquish.pitbpa0.priv.collaborativefusion.com [192.168.2.61]) (SSL: TLSv1/SSLv3,256bits,AES256-SHA) by wingspan with esmtp; Tue, 18 Sep 2007 12:18:45 -0400 id 00056418.46EFFA65.0000154D Date: Tue, 18 Sep 2007 12:18:45 -0400 From: Bill Moran To: "Galantucci Giovanni" Cc: pgsql-performance@postgresql.org Subject: Re: R: DELETE queries slow down Message-Id: <20070918121845.19008a51.wmoran@collaborativefusion.com> In-Reply-To: References: <873axdpp6v.fsf@oxford.xeocode.com> Organization: Collaborative Fusion X-Mailer: Sylpheed 2.4.4 (GTK+ 2.10.14; i386-portbld-freebsd6.2) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/311 X-Sequence-Number: 26856 In response to "Galantucci Giovanni" : > I perform simple INSERT and simple where-clause DELETE. > I also force a commit after every DELETE. Do you mean that you delete 1 row at a time? This is slower than batching your deletes. > My two tables are about these: >=20 > TABLE_A > Column_1 | column2 | ....... >=20 > TABLE_B > Column_1B foreign key references TABLE_A(column_1) on delete cascade | ..= ....... >=20 > Every row in TABLE_B is also present in TABLE_A, but the contrary is not = true. > After hours in which I insert and delete only on TABLE_A (everything ok),= I start inserting also on TABLE_B, exploiting the constrain on column_1B. = After the first DELETE I perform on both tables, each following DELETE last= s for minutes, with cpu usage on 99,9%. > I tried also to perform a VACUUM after each DELETE, but had no benefits. > Even the EXPLAIN ANALYZE of the DELETE shows no changes with respect to t= he previous DELETEs: it uses an index on column_1 of TABLE_A. Are you unable to provide these details? (i.e. output of explain, the actual table schema, actual queries) Without them, the question is very vague and difficult to give advice on. If the planner comes up with the same plan whether running fast or slow, the question is what part of that plan is no longer valid (what part's actual time no longer matches it's predicted time) > My doubt is that the query planner is not enough fast to follow sudden ch= anges in the way I use the DB, is there a way in which I can help it to adj= ust its statistics and its query planner more quickly? See: http://www.postgresql.org/docs/8.2/static/sql-analyze.html which also has links to other information on this topic. If you can demonstrate that the statistics are stale, you might benefit from manual analyze after large operations. > My other doubt is that the foreign key on TABLE_B is a problem when I try= to delete from TABLE_A, and postgres tries to find nonexistent constrained= rows on TABLE_B. It's quite possible, considering the fact that you seem to be CPU bound. >=20 > -----Messaggio originale----- > Da: Gregory Stark [mailto:stark@enterprisedb.com]=20 > Inviato: luned=EC 17 settembre 2007 12.22 > A: Heikki Linnakangas > Cc: Galantucci Giovanni; pgsql-performance@postgresql.org > Oggetto: Re: DELETE queries slow down >=20 > "Heikki Linnakangas" writes: >=20 > > Galantucci Giovanni wrote: > > > >> For 1 or 2 hours we update only one table, and everything goes ok, whe= re > >> DELETE last at most 6 or 7 seconds. > >>=20 > >> Then for a minute we do INSERT on both table, and everything continue > >> going ok, with DELETE that last about 10 seconds. > >>=20 > >> From that moment on, DELETES become timeless, and last for 240 and more > >> seconds!=20 >=20 > What do the inserts and deletes actually look like? Are there subqueries = or > joins or are they just inserting values and deleting simple where clauses? >=20 > And are these in autocommit mode or are you running multiple commands in a > single transaction? >=20 > Generally it's faster to run more commands in a single transaction but wh= at > I'm worried about is that you may have a transaction open which you aren't > committing for a long time. This can stop vacuum from being able to clean= up > dead space and if it's in the middle of a query can actually cause vacuum= to > get stuck waiting for the query to finish using the page it's using. --=20 Bill Moran Collaborative Fusion Inc. http://people.collaborativefusion.com/~wmoran/ wmoran@collaborativefusion.com Phone: 412-422-3463x4023