Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tdr3r-0003qF-HG for pgsql-performance@arkaria.postgresql.org; Wed, 28 Nov 2012 23:28:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Tdr3q-0006za-A1 for pgsql-performance@arkaria.postgresql.org; Wed, 28 Nov 2012 23:28:58 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tdr3p-0006zU-25 for pgsql-performance@postgresql.org; Wed, 28 Nov 2012 23:28:57 +0000 Received: from mail-da0-f46.google.com ([209.85.210.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tdr3n-0003g5-IK for pgsql-performance@postgresql.org; Wed, 28 Nov 2012 23:28:56 +0000 Received: by mail-da0-f46.google.com with SMTP id p5so4975173dak.19 for ; Wed, 28 Nov 2012 15:28:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding :x-gm-message-state; bh=CuZPc90dyPF+588d1KdTUumtxq5gaxBFUBjkbViZvQI=; b=TV/Le2/fHDyJadXGBsqvtnWYFxOCeoStXpxUACkungTxYTxXVMXVSOROoqaU648gDf u9Y4+4BMBe+ddvaRGPu/BaIPuezdobGp7FdIjRnd1MN/Xgw1vYRXMXtvzVuAUfha3MNy v4JBdjkxVP7OyMuiTwzZvNrBysz3xjVuzCbzERgOxTKngmuY6zRjvtJuy/ZG3SJ9jyhk U/upZ1UIYp/Dcw/bouy6v7U6CmoNkEb/CHusAYWy0k2mgkyheCJwuxyfkwHVlV7MAwEA 3RcqD6aKZsOVKd+zgtm1/2yV4C1cdyUjQq907NbkBPGoy/M7VEAWpqb/hCL101vpxv35 Esdg== Received: by 10.66.85.134 with SMTP id h6mr56388190paz.36.1354145334239; Wed, 28 Nov 2012 15:28:54 -0800 (PST) Received: from ?IPv6:::1? ([2600:3c01::f03c:91ff:fe93:2ae4]) by mx.google.com with ESMTPS id ve6sm123574pbc.58.2012.11.28.15.28.52 (version=SSLv3 cipher=OTHER); Wed, 28 Nov 2012 15:28:53 -0800 (PST) Subject: Re: Savepoints in transactions for speed? From: Jeff Davis To: Mike Blackwell Cc: pgsql-performance@postgresql.org In-Reply-To: References: Content-Type: text/plain; charset="ISO-8859-1" Date: Wed, 28 Nov 2012 15:28:51 -0800 Message-ID: <1354145331.1766.84.camel@sussancws0025> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQn0UIlO2thvfCX+N0MGfa4oWd8hSAL5JQXAPhWjWAkGAB1Ttmhufn2zorUpS/yvQ1xhRJtA X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On Tue, 2012-11-27 at 16:04 -0600, Mike Blackwell wrote: > I need to delete about 1.5 million records from a table and reload it > in one transaction. The usual advice when loading with inserts seems > to be group them into transactions of around 1k records. Committing > at that point would leave the table in an inconsistent state. Would > issuing a savepoint every 1k or so records negate whatever downside > there is to keeping a transaction open for all 1.5 million records, or > just add more overhead? A large transaction isn't really a big problem for postgres, and 1.5M records should be processed quickly anyway. The main problem with a long-running delete or update transaction is that the dead tuples (deleted tuples or the old version of an updated tuple) can't be removed until the transaction finishes. That can cause temporary "bloat", but 1.5M records shouldn't be noticeable. Adding subtransactions into the mix won't help, but probably won't hurt, either. The transaction will still run just as long, and you still can't delete the tuples ahead of time (unless you abort a subtransaction). If you *do* use subtransactions, make sure to release them as quickly as you create them (don't just use ROLLBACK TO, that still leaves the savepoint there); having 1500 open subtransactions might cause performance problems elsewhere. Regards, Jeff Davis -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance