Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XKDMv-0003nZ-D3 for pgsql-performance@arkaria.postgresql.org; Wed, 20 Aug 2014 21:24:33 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XKDMu-00029H-T3 for pgsql-performance@arkaria.postgresql.org; Wed, 20 Aug 2014 21:24:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XKDMu-000298-29 for pgsql-performance@postgresql.org; Wed, 20 Aug 2014 21:24:32 +0000 Received: from nm24.bullet.mail.ne1.yahoo.com ([98.138.90.87]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XKDMo-0005aO-R9 for pgsql-performance@postgresql.org; Wed, 20 Aug 2014 21:24:31 +0000 Received: from [98.138.226.180] by nm24.bullet.mail.ne1.yahoo.com with NNFMP; 20 Aug 2014 21:24:22 -0000 Received: from [98.138.89.194] by tm15.bullet.mail.ne1.yahoo.com with NNFMP; 20 Aug 2014 21:24:22 -0000 Received: from [127.0.0.1] by omp1052.mail.ne1.yahoo.com with NNFMP; 20 Aug 2014 21:24:22 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 763238.81523.bm@omp1052.mail.ne1.yahoo.com Received: (qmail 62063 invoked by uid 60001); 20 Aug 2014 21:24:22 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s1024; t=1408569862; bh=G73h9Rqbk7CDD3sfjZw2dvuj5brdYkZ9LhQ4/Y29Cw4=; h=References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=AGAqU/DtRXpaV7qb4z/2fPC6UC55cYs+6JcsOf/LqqNGvujwrUvbxi+JnhZd+2NiD8+HZ9m9dg5jdFZ2dnvLml3lFKg4cX69AVyASwQP5uHhHvAnHhaK7wkIbXBk5JEvdLdrXN2SeT+Q/abAQzl4Q6dz+G8qlgpkDlqKqS+jnPM= X-YMail-OSG: t1cozGQVM1keM2j36lL9IQfHwO85E0Tlets_HzQKmU7iyzM YtT.HiEGZ84CXTZaXzZZbh6peoKYNvb4Gjjr0JDhJpGx.tpmaNp19GsdhnXl IKmt1O_5YyCkAIOK32OtVVVyI.yzYsViLZKVGe2MfYs42xugWUxra25GQUej ULPJx1GrlURhhZDPnHxmY1BKpAEWMoeZAlvDsVd7nhh88usp7499edgxR2uH v_WlZ7l5Xx5vkhrZIkRMxP2CPCzhFtpqUFZQabSGtlO16rQaZQTmRWYuCUmf ce4U5KeqdvdWZZA8qoUN0KMH2J0UpdjTZyARuqhBfb7nFjHjXPiUxxd3vNUA a_xS0dqaRU5tI4iXPiDi79s5bf8oex3S96V4gFgSWkRbTiUd0MY6qvqcI1Cl faR9cSvquIt2yZYcjlP6wVXaTyRNBm8igmytwZEc2sMXhKb0UONBfxVSGs3C DZVHLAtTWvsdWZqLvG6M8MKc6KmNreBFji8T6z0hLK_eicOiUX2FIWPV2TJq NQmhLkjnpPc0m2VqIndRH7Zi76AA2tJG5IGcUdLFNzj0HIdrPWeiPCkdbqCB NMq7qrOs8Gp4xsSrUN.ymn5OQqc1OutDwduZDR..Iz8JVsF85YU4M6IO9Yae WOxxEuFgx71Bzdbc_dcjjW8xr_eRPn7ArYNXPxtANSLH7U95VbtKXJ1B0xqu YKJjd0kzEeHA7PUSs5oHsrvQdhebEbk9XB2g6WJ34Quq9gG1tm04fhcjF2vd Wc95A7ajeCKFMp9Db1E_NqDz99ad7Y1O0PKPP9ceR6cO_Kw-- Received: from [24.178.25.147] by web122303.mail.ne1.yahoo.com via HTTP; Wed, 20 Aug 2014 14:24:22 PDT X-Rocket-MIMEInfo: 002.001, S2V2aW4gR3JpdHRuZXIgPGtncml0dG5AeW1haWwuY29tPiB3cm90ZToKPiBEYXZlIE93ZW5zIDxkYXZlQHRlYW11bmlmeS5jb20.IHdyb3RlOgo.Cj4.IEkgbm93IGhhdmUgOCBob3VycyB3b3J0aCBvZiBzbmFwc2hvdHMgZnJvbSBwZ19zdGF0X2FjdGl2aXR5IGFuZAo.PiBwZ19sb2NrcyAoMTYgc25hcHNob3RzIGZyb20gZWFjaCB0YWJsZS92aWV3KS7CoCBJIGhhdmUgdHVybmVkIG9mZgo.PiBjb2xsZWN0aW9uIGF0IHRoaXMgcG9pbnQsIGJ1dCBJIGFtIHN0aWxsIGFibGUgdG8gcXVlcnkgcGdfbG9ja3MKPgoBMAEBAQE- X-Mailer: YahooMailWebService/0.8.201.700 References: <20140819171710.GA15735@awork2.anarazel.de> <1408471302.64928.YahooMailNeo@web122302.mail.ne1.yahoo.com> <1408473810.64930.YahooMailNeo@web122304.mail.ne1.yahoo.com> <1408558502.11006.YahooMailNeo@web122302.mail.ne1.yahoo.com> Message-ID: <1408569862.61116.YahooMailNeo@web122303.mail.ne1.yahoo.com> Date: Wed, 20 Aug 2014 14:24:22 -0700 From: Kevin Grittner Reply-To: Kevin Grittner Subject: Re: query against pg_locks leads to large memory alloc To: Kevin Grittner , Dave Owens Cc: Andres Freund , Merlin Moncure , Matheus de Oliveira , postgres performance list In-Reply-To: <1408558502.11006.YahooMailNeo@web122302.mail.ne1.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -2.0 (--) 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 Kevin Grittner wrote: > Dave Owens wrote: > >> I now have 8 hours worth of snapshots from pg_stat_activity and >> pg_locks (16 snapshots from each table/view).=A0 I have turned off >> collection at this point, but I am still able to query pg_locks > > Could you take the earliest one after activity started, and the > latest one before you stopped collecting them, compress them, and > email them to me off-list, please? Dave did this, off-list.=A0 There is one transaction which has been running for over 20 minutes, which seems to be the cause of the accumulation.=A0 I note that this query does not hold any of the locks it would need to take before modifying data, and it has not been assigned a transactionid -- both signs that it has (so far) not modified any data.=A0 If it is not going to modify any, it would not have caused this accumulation of locks if it was flagged as READ ONLY.=A0 This is very important to do if you are using serializable transactions in PostgreSQL. To quantify that, I show the number of SIReadLocks in total: test=3D# select count(*) from locks_snap_16 where mode =3D 'SIReadLock'; =A0 count --------- =A03910257 (1 row) ... and the number of those which are only around because there is an open overlapping transaction, not flagged as read only: test=3D# select count(*) from locks_snap_16 l test-#=A0=A0 where mode =3D 'SIReadLock' test-#=A0=A0=A0=A0 and not exists (select * from locks_snap_16 a test(#=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 wh= ere a.locktype =3D 'virtualxid' test(#=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 and a.virtualxid =3D l.virtualtransaction); =A0 count --------- =A03565155 (1 row) I can't stress enough how important it is that the advice near the bottom of this section of the documentation is heeded: http://www.postgresql.org/docs/9.2/interactive/transaction-iso.html#XACT-SE= RIALIZABLE Those bullet-points are listed roughly in order of importance; there is a reason this one is listed first: =A0- Declare transactions as READ ONLY when possible. In some shops using SERIALIZABLE transactions, I have seen them set default_transaction_read_only =3D on, and explicitly set it off for transactions which will (or might) modify data. If you have a long-running report that might itself grab a lot of predicate locks (a/k/a SIReadLocks), you can avoid that by declaring the transaction as READ ONLY DEFERRABLE.=A0 If you do that, the transaction will wait to begin execution until it can acquire a snapshot guaranteed not to show any anomalies (like the example referenced in an earlier post can show).=A0 It then runs without acquiring any predicate locks, just like a REPEATABLE READ transaction.=A0 In fairly busy benchmarks, we never saw it take more than six seconds to acquire such a snapshot, although the wait time is not bounded.=A0 Again, getting such a snapshot will be possible sooner if you declare transactions as READ ONLY when possible.=A0 :-) -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance