Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X2Pmd-00030C-T6 for pgsql-performance@arkaria.postgresql.org; Wed, 02 Jul 2014 19:01:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X2Pmd-0005zK-Cz for pgsql-performance@arkaria.postgresql.org; Wed, 02 Jul 2014 19:01:31 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X2Pmc-0005zB-Gb for pgsql-performance@postgresql.org; Wed, 02 Jul 2014 19:01:30 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X2PmZ-0002Tt-2l for pgsql-performance@postgresql.org; Wed, 02 Jul 2014 19:01:28 +0000 Received: by mail.anarazel.de (Postfix, from userid 108) id CF2834F0001; Wed, 2 Jul 2014 21:01:23 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on mail X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from anarazel.de (p5DDC4445.dip0.t-ipconnect.de [93.220.68.69]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id 181236E0001; Wed, 2 Jul 2014 21:01:12 +0200 (CEST) Received: by anarazel.de (Postfix, from userid 1000) id 1C191100585; Wed, 2 Jul 2014 21:01:11 +0200 (CEST) Date: Wed, 2 Jul 2014 21:01:11 +0200 From: Andres Freund To: Tom Lane Cc: Jeff Frost , Matheus de Oliveira , Soni M , Heikki Linnakangas , pgsql-performance Subject: Re: Postgres Replaying WAL slowly Message-ID: <20140702190111.GC25909@awork2.anarazel.de> References: <20140630201523.GV26930@awork2.anarazel.de> <943ECC8E-8899-422E-937C-50DE20E1F7AC@pgexperts.com> <21474.1404160784@sss.pgh.pa.us> <2E438E7D-E3C1-47A1-A1AF-9FE50A14A302@pgexperts.com> <571D044B-260A-4E06-ACBC-8869B8F73C0F@pgexperts.com> <24455.1404169460@sss.pgh.pa.us> <608DF51D-AEFB-422B-AD2C-ABA9A114AA27@pgexperts.com> <18433.1404242437@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <18433.1404242437@sss.pgh.pa.us> 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 2014-07-01 15:20:37 -0400, Tom Lane wrote: > Jeff Frost writes: > >> On Jun 30, 2014, at 4:04 PM, Tom Lane wrote: > >>> Did you check whether the locks were all on temp tables of the > >>> ON COMMIT DROP persuasion? > > > And indeed it did catch up overnight and the lag increased shortly after a correlating spike in AccessExclusiveLocks that were generated by temp table creation with on commit drop. > > OK, so we have a pretty clear idea of where the problem is now. > > It seems like there are three, not mutually exclusive, ways we might > address this: > > 1. Local revisions inside StandbyReleaseLocks to make it perform better in > the presence of many locks. This would only be likely to improve matters > much if there's a fixable O(N^2) algorithmic issue; but there might well > be one. > > It sounded like Andres had taken a preliminary look at #1 and found a > possible avenue for improvement, which I'd encourage him to pursue. > I don't have the resources to do this right now, but yes, I think we can get relatively easily get rid of the O(num_locks * num_subtransactions) behaviour. > 2. Avoid WAL-logging AccessExclusiveLocks associated with temp tables, on > the grounds that no standby should be touching them. I'm not entirely > sure that that argument is bulletproof though; in particular, even though > a standby couldn't access the table's data, it's possible that it would be > interested in seeing consistent catalog entries. Hm. We definitely perform checks surprisingly late for those. It's possible to do SELECT * FROM pg_temp_.whatever; without an error f there's no rows of if the rest of the plan doesn't do accesses to that table. The check prohibiting access is only in bufmgr.c... So yea, I don't think we can do this for at least < 9.4. And there it'll still be hard. > 3. Avoid WAL-logging AccessExclusiveLocks associated with > new-in-transaction tables, temp or not, on the grounds that no standby > could even see such tables until they're committed. We could go a bit > further and not take out any locks on a new-in-transaction table in the > first place, on the grounds that other transactions on the master can't > see 'em either. > > For both #2 and the conservative version of #3, the main implementation > problem would be whether the lock WAL-logging code has cheap access to > the necessary information. I suspect it doesn't. Not trivially. It's logged directly in LockAcquireExtended(). We could add the information into locktags as there's unused fields for relation locktags, but brrr. > The radical version of #3 might be pretty easy to do, at least to the > extent of removing locks taken out during CREATE TABLE. I suspect there > are some assertions or other consistency checks that would get unhappy if > we manipulate relations without locks, though, so those would have to be > taught about the exception. > > Also, we sometimes forget new-in-transaction > status during relcache flush events; it's not clear if that would be a > problem for this. I think that hole is actually pluggable in newer releases - at least there's no code around that assumes rd_createSubid now is persistent, even across cache resets. But I think more importantly it's probably quite possible to hit a similar problem without ON COMMIT DROP relations. Say DISCARD TEMP inside a transaction (with several subxacts) or so? So we probaly really should fix the bad scaling. Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance