Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id A32D72B2868 for ; Mon, 25 Jun 2012 12:52:02 -0300 (ADT) Received: from mail-we0-f174.google.com ([74.125.82.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SjBa5-0004Pd-A1 for pgsql-performance@postgresql.org; Mon, 25 Jun 2012 15:52:02 +0000 Received: by weyu7 with SMTP id u7so2900967wey.19 for ; Mon, 25 Jun 2012 08:51:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=mhFkLWTp+/r039zBPsGZDvcwUccdF4TA1ab1IgCBAMw=; b=I2Pbew6j+TeerzCril0mqaxT60EdC+yk/f//i1Ga14/zD5/dSuoxdE7PXFAE6qyQYn aEA/pfgbIvc57/NnN/r2aVqAx29ZPE/PPgH4u8BOjkbtovzmu2X97+vZsCg2Q/InwGHJ zx+kVFPbEc6enqJHmCBJnQmrcfYvhM0aP253XiCpuN6yedOkrk+e4m6jCpJkkyEs7FDd 6K4KkZcTee48LOVPAK9UjXMkX3M2UZq3HAmk9a2h6PSyOQo41fBfA3MJUBGEPh65Fv/N 63pNh2NFXwskqIs/afpCFTiSfd1uBmWgRZV9Nh1mdhKfja/KzejSm84kmimpOwpbyfD9 tVnA== Received: by 10.216.196.72 with SMTP id q50mr6882684wen.90.1340639506422; Mon, 25 Jun 2012 08:51:46 -0700 (PDT) Received: from [10.64.1.26] ([94.45.140.16]) by mx.google.com with ESMTPS id ce3sm7662114wib.11.2012.06.25.08.51.44 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Jun 2012 08:51:45 -0700 (PDT) Message-ID: <4FE88924.4060303@gmail.com> Date: Mon, 25 Jun 2012 18:52:04 +0300 From: Vitalii Tymchyshyn User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: Frits Jalvingh CC: pgsql-performance@postgresql.org Subject: Re: Postgres delete performance problem References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -2.3 (--) X-Archive-Number: 201206/130 X-Sequence-Number: 47156 Hello. This may be wrong type for parameter, like using setObject(param, value) instead of setObject(param, value, type). Especially if value passed is string object. AFAIR index may be skipped in this case. You can check by changing statement to "delete from xxx where xxx_pk=?::bigint". If it works, check how parameter is set in java code. 25.06.12 18:42, Frits Jalvingh написав(ла): > Hi, > > I have a Java application that tries to synchronize tables in two > databases (remote source to local target). It does so by removing all > constraints, then it compares table contents row by row, inserts > missing rows and deletes "extra" rows in the target database. Delete > performance is incredibly bad: it handles 100 record deletes in about > 16 to 20 seconds(!). Insert and update performance is fine. > > The Java statement to handle the delete uses a prepared statement: > > "delete from xxx where xxx_pk=?" > > The delete statement is then executed using addBatch() and > executeBatch() (the latter every 100 deletes), and committed. Not > using executeBatch makes no difference. > > An example table where deletes are slow: > > pzlnew=# \d cfs_file > Table "public.cfs_file" > Column | Type | Modifiers > ------------------+-----------------------------+----------- > cfsid | bigint | not null > cfs_date_created | timestamp without time zone | not null > cfs_name | character varying(512) | not null > cfs_cfaid | bigint | > cfs_cfdid | bigint | > Indexes: > "cfs_file_pkey" PRIMARY KEY, btree (cfsid) > > with no FK constraints at all, and a table size of 940204 rows. > > While deleting, postgres takes 100% CPU all of the time. > > > Inserts and updates are handled in exactly the same way, and these are > a few orders of magnitude faster than the deletes. > > I am running the DB on an Ubuntu 12.04 - 64bits machine with Postgres > 9.1, the machine is a fast machine with the database on ssd, ext4, > with 16GB of RAM and a i7-3770 CPU @ 3.40GHz. > > Anyone has any idea? > > Thanks in advance, > > Frits >