Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id B9EAD1337B47 for ; Thu, 17 Mar 2011 14:57:43 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 24121-01-3 for ; Thu, 17 Mar 2011 17:57:36 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail148094.authsmtp.co.uk (outmail148094.authsmtp.co.uk [62.13.148.94]) by mail.postgresql.org (Postfix) with ESMTP id 228501337CBB for ; Thu, 17 Mar 2011 14:56:47 -0300 (ADT) Received: from mail-c194.authsmtp.com (mail-c194.authsmtp.com [62.13.128.121]) by punt7.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id p2HHuiuC083811; Thu, 17 Mar 2011 17:56:44 GMT Received: from [192.168.0.3] ([81.5.146.37]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2) with ESMTP id p2HHubRB056851; Thu, 17 Mar 2011 17:56:37 GMT Subject: Re: [COMMITTERS] pgsql: Efficient transaction-controlled synchronous replication. From: Simon Riggs To: Robert Haas Cc: Fujii Masao , PostgreSQL-development In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Date: Thu, 17 Mar 2011 17:56:36 +0000 Message-ID: <1300384596.18619.1823.camel@ebony> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-Server-Quench: e8162892-50bf-11e0-80b9-0022640b883e X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdxZQATClZOTQEd DAteCiN5VAwpPBRK HVkIKg5MJUcNSQVJ NksadRtFaQJbYFhD HGQLWlVEUVp7XGV/ aAIfZQRDZ1RPWwN0 U09WR1pVCwUmQR55 fltMMGtycgNOfX8+ ZERiXnMVCUx7c0R1 S0xJEG1UM3phaTUf TUhYJQpJcANIfBlB agJ3XHBYLwdSbGoL PyYYHB0LBgAXGw9y ZyQsEW4/e30+ViYz XAkGT30CE0METCQ+ KQBuNkQVGl0YOVkz Nl1kUlUeLwUVDglT EyMFGz5fLFkbQCws EBgSR0MGFDxWSDtd BRtuSgDw X-Authentic-SMTP: 61633235383639.1015:706 X-AuthFastPath: 0 (Was 255) X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.419 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FS_REPLICA=3.599, SARE_SPEC_REPLICA=0.72 X-Spam-Level: ** X-Archive-Number: 201103/1083 X-Sequence-Number: 184333 On Thu, 2011-03-17 at 13:46 -0400, Robert Haas wrote: > On Fri, Mar 11, 2011 at 5:46 AM, Fujii Masao wrote: > > On Fri, Mar 11, 2011 at 5:04 AM, Robert Haas wrote: > >>> if ((wrote_xlog && XactSyncCommit) || forceSyncCommit || nrels > 0 || > >>> SyncRepRequested()) > >>> > >>> Whenever synchronous_replication is TRUE, we disable synchronous_commit. > >>> But, before disabling that, we should check also max_wal_senders and > >>> synchronous_standby_names? Otherwise, synchronous_commit can > >>> be disabled unexpectedly even in non replication case. > >> > >> Yeah, that's bad. At the risk of repeating myself, I don't think this > >> code should be checking SyncRepRequested() in the first place. If the > >> user has turned off synchronous_commit, then we should just commit > >> asynchronously, even if sync rep is otherwise in force. Otherwise, > >> this if statement is going to get really complicated. The logic is > >> already at least mildly wrong here anyway: clearly we do NOT need to > >> commit synchronously if the transaction has not written xlog, even if > >> sync rep is enabled. > > > > Yeah, not to wait for replication when synchronous_commit is disabled > > seems to be more reasonable. > > On further review, I've changed my mind. Making synchronous_commit > trump synchronous_replication is appealing conceptually, but it's > going to lead to some weird corner cases. For example, a transaction > that drops a non-temporary relation always commits synchronously; and > 2PC also ignores synchronous_commit. In the case where > synchronous_commit=off and synchronous_replication=on, we'd either > have to decide that these sorts of transactions aren't going to > replicate synchronously (which would give synchronous_commit a rather > long reach into areas it doesn't currently touch) or else that it's OK > for CREATE TABLE foo () to be totally asynchronous but that DROP TABLE > foo requires sync commit AND sync rep. That's pretty weird. > > What makes more sense to me after having thought about this more > carefully is to simply make a blanket rule that when > synchronous_replication=on, synchronous_commit has no effect. That is > easy to understand and document. I'm inclined to think it's OK to let > synchronous_replication have this effect even if max_wal_senders=0 or > synchronous_standby_names=''; you shouldn't turn > synchronous_replication on just for kicks, and I don't think we want > to complicate the test in RecordTransactionCommit() more than > necessary. We should, however, adjust the logic so that a transaction > which has not written WAL can still commit asynchronously, because > such a transaction has only touched temp or unlogged tables and so > it's not important for it to make it to the standby, where that data > doesn't exist anyway. Agree to that. Not read your other stuff yet, will do that later. -- Simon Riggs http://www.2ndQuadrant.com/books/ PostgreSQL Development, 24x7 Support, Training and Services