Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TF0lG-0003lI-8V for pgsql-performance@postgresql.org; Fri, 21 Sep 2012 10:47:06 +0000 Received: from benvolio.jonathanleighton.com ([173.255.230.218]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TF0lD-0002UL-6s for pgsql-performance@postgresql.org; Fri, 21 Sep 2012 10:47:05 +0000 Received: from localhost (benvolio.jonathanleighton.com [127.0.0.1]) by benvolio.jonathanleighton.com (iRedMail) with ESMTP id D1740A8C8 for ; Fri, 21 Sep 2012 11:47:00 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= jonathanleighton.com; h=content-transfer-encoding:content-type :content-type:subject:subject:to:mime-version:user-agent:from :from:date:date:message-id; s=dkim; t=1348224420; x=1349088420; bh=kNXmzKp5/1KwEDSPD4G3dyLQbI5ZjTrW+Yu7jERlq6Y=; b=UA8xd/UlysUB JIyC4/jd4pf2S7dU8oH5W63NNFhMFv0ESjI02jq+z1fUwGEQd+gRU68HPMA+g+8m mw0KFT72USSK3vzGTjH2seb3vFljkrYXlKuippiU9ShNFRTBAfRuLxyZPSBxJ3j2 SD8P6LZqoKnKn7RljnGmNuC4hUA138w= X-Virus-Scanned: Debian amavisd-new at benvolio.jonathanleighton.com Received: from benvolio.jonathanleighton.com ([127.0.0.1]) by localhost (benvolio.jonathanleighton.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eKHHwcjwHcjb for ; Fri, 21 Sep 2012 11:47:00 +0100 (BST) Received: from [192.168.0.5] (unknown [2.31.220.143]) by benvolio.jonathanleighton.com (iRedMail) with ESMTPSA id 319BDA893 for ; Fri, 21 Sep 2012 11:46:59 +0100 (BST) Message-ID: <505C45A2.1080601@jonathanleighton.com> Date: Fri, 21 Sep 2012 11:46:58 +0100 From: Jon Leighton User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120828 Thunderbird/15.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Cost of opening and closing an empty transaction X-Enigmail-Version: 1.4.4 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.5 (--) X-Archive-Number: 201209/93 X-Sequence-Number: 47839 Hello! I'm one of the developers of the Ruby on Rails web framework. In some situations, the framework generates an empty transaction block. I.e. we sent a BEGIN and then later a COMMIT, with no other queries in the middle. We currently can't avoid doing this, because a user *may* send queries inside the transaction. I am considering the possibility of making the transaction lazy. So we would delay sending the BEGIN until we have the first query ready to go. If that query never comes then neither BEGIN nor COMMIT would ever be sent. So my question is: is this a worthwhile optimisation to make? In particular, I am wondering whether empty transactions increase the work the database has to do when there are several other connections open? I.e. does it cause contention? If anyone has any insight about other database servers that would also be welcome. Thanks! Jon Leighton -- http://jonathanleighton.com/