Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 45A70EC7B26 for ; Fri, 6 Jul 2012 10:39:07 -0300 (ADT) Received: from mail-pb0-f46.google.com ([209.85.160.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Sn8kT-0002EW-Ry for pgsql-performance@postgresql.org; Fri, 06 Jul 2012 13:39:06 +0000 Received: by pbbrp8 with SMTP id rp8so14640903pbb.19 for ; Fri, 06 Jul 2012 06:38:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=XBcLqEVn0bxKYdOgyIPCDNNx+NCaWcsNb7PAV5/c3FY=; b=iqTMU4+4TnRQzKhEUGWbAQkK1SuzP0mST8xD1ZiUqAmiWkUBVtkW37Db72FIt7oe2y 8VXWob8w9cww3p+1Yu2j2zrtLWNUfJnmzJHEEDWwoedfclshXEnAQQhclG8w2KbSnh3N hhxqjE/gPWJlbEzcswblMaxflwcEcfTFx3+wmG4v/AixSO0LZizD6arcSpzUfPJlCgY4 l7OmbERU2ZQQg8Rws5UTw8dDJpToeI9Ok5aS7Ptct9xqmIM0YDRKDwRY4Z4Oo9RS9a+4 UQM68Zpa4gcwOxcO1O3+CcgXPx0BwOK+RG79E9TnxAnlzoNyfHqtyWsmOUQerEW14WYX jEag== Received: by 10.68.116.203 with SMTP id jy11mr35874931pbb.129.1341581931337; Fri, 06 Jul 2012 06:38:51 -0700 (PDT) Received: from ayaki.localdomain (124-169-169-118.dyn.iinet.net.au. [124.169.169.118]) by mx.google.com with ESMTPS id pq5sm21907451pbb.30.2012.07.06.06.38.47 (version=SSLv3 cipher=OTHER); Fri, 06 Jul 2012 06:38:49 -0700 (PDT) Message-ID: <4FF6EA64.9010308@ringerc.id.au> Date: Fri, 06 Jul 2012 21:38:44 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0 MIME-Version: 1.0 To: Daniel Farina CC: Stanislaw Pankevich , pgsql-performance@postgresql.org Subject: Re: PostgreSQL db, 30 tables with number of rows < 100 (not huge) - the fastest way to clean each non-empty table and reset unique identifier column of empty ones. References: <4FF6CC11.2000904@ringerc.id.au> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQlReEhTUGlPfLYtMl5sXrDgGyJW8iDqhW+RHYJJ3VnQlpy3Ti7pnBXn7m2EOAoD8X+A5QFV X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/60 X-Sequence-Number: 47241 On 07/06/2012 07:38 PM, Daniel Farina wrote: > On Fri, Jul 6, 2012 at 4:29 AM, Craig Ringer wrote: >> 1) Truncate each table. It is too slow, I think, especially for empty >> tables. >> >> Really?!? TRUNCATE should be extremely fast, especially on empty tables. >> >> You're aware that you can TRUNCATE many tables in one run, right? >> >> TRUNCATE TABLE a, b, c, d, e, f, g; > I have seen in "trivial" cases -- in terms of data size -- where > TRUNCATE is much slower than a full-table DELETE. The most common use > case for that is rapid setup/teardown of tests, where it can add up > quite quickly and in a very big way. This is probably an artifact the > speed of one's file system to truncate and/or unlink everything. That makes some sense, actually. DELETEing from a table that has no foreign keys, triggers, etc while nothing else is accessing the table is fairly cheap and doesn't take much (any?) cleanup work afterwards. For tiny deletes I can easily see it being better than forcing the OS to journal a metadata change or two and a couple of fsync()s for a truncate. I suspect truncating many tables at once will prove a win over iteratively DELETEing from many tables at once. I'd benchmark it except that it's optimizing something I don't care about at all, and the results would be massively dependent on the file system (ext3, ext4, xfs) and its journal configuration. -- Craig Ringer