Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YHMrl-0007Vb-T4 for pgsql-performance@arkaria.postgresql.org; Sat, 31 Jan 2015 01:28:54 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YHMrk-0007NQ-GX for pgsql-performance@arkaria.postgresql.org; Sat, 31 Jan 2015 01:28:52 +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 1YHMrj-0007NK-Lu for pgsql-performance@postgresql.org; Sat, 31 Jan 2015 01:28:51 +0000 Received: from mail-bn1bon0663.outbound.protection.outlook.com ([2a01:111:f400:fc10::1:663] helo=na01-bn1-obe.outbound.protection.outlook.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YHMrd-0001ph-UK for pgsql-performance@postgresql.org; Sat, 31 Jan 2015 01:28:50 +0000 Received: from decina.local (24.55.12.91) by BY1PR11MB0343.namprd11.prod.outlook.com (25.160.206.156) with Microsoft SMTP Server (TLS) id 15.1.75.20; Sat, 31 Jan 2015 01:28:36 +0000 Message-ID: <54CC2FBA.1040506@BlueTreble.com> Date: Fri, 30 Jan 2015 19:28:26 -0600 From: Jim Nasby User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Slava Mudry , Subject: Re: why pg_class.relfrozenxid needs to be updated for frozen tables (where all rows have xmin=2)? References: In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [24.55.12.91] X-ClientProxiedBy: BY1PR00CA0003.namprd00.prod.outlook.com (25.160.102.13) To BY1PR11MB0343.namprd11.prod.outlook.com (25.160.206.156) Authentication-Results: postgresql.org; dkim=none (message not signed) header.d=none; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:BY1PR11MB0343; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004); SRVR:BY1PR11MB0343; X-Forefront-PRVS: 0473A03F3F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(377454003)(24454002)(51704005)(479174004)(87976001)(46102003)(65956001)(59896002)(122386002)(40100003)(65806001)(77156002)(66066001)(62966003)(76176999)(2950100001)(2420400003)(15975445007)(36756003)(65816999)(87266999)(47776003)(50986999)(33656002)(54356999)(23676002)(64126003)(42186005)(50466002)(107886001)(92566002)(83506001)(86362001)(551934003)(19580395003)(85282002)(336755003)(18886065003); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR11MB0343; H:decina.local; FPR:; SPF:None; MLV:sfv; LANG:en; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:BY1PR11MB0343; X-OriginatorOrg: bluetreble.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2015 01:28:36.1748 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR11MB0343 X-Pg-Spam-Score: -1.9 (-) 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 1/30/15 5:44 PM, Slava Mudry wrote: > Hi, > I have to deal with badly written system which regularly suffers from > transaction wraparound issue. This issue is happenning every 10-14 days > and forces me to take system offline and vacuum in single-user mode. > Main causes for this are (afaik): > 1) heavy transaction traffic + 100+GB of stale tables > 2) slow i/o (rotational drives) > 3) autovacuum can't keep up. > > Basically the database stores events data in daily partitioned table > "daily_events". > What I did, was - I ran vaccum freeze on all partitions (the tables are > never touched after they're done for a day). I have also scheduled > vacuum-freeze for a partition after it's done writing. > > This essentially set xmin in each partition to "frozen" value of "2". > However, to my surprise, this was not enough! > Postgres stores relfrozenxid in pg_class and this value apparently is > getting old pretty fast (due to high volume of transactions). > And it seems that it doesn't really matter that xmin is frozen for a > table, the relfrozenxid is what causing transaction wraparound. relfrozenxid is only part of the picture. A database-wide freeze vacuum will be controlled by pg_database.datfrozenxid. What version is this? You may also be suffering from multixact wrap. > Why is that? and most importantly - why updating pg_class.relfrozenxid > requires huge amount of i/o by vacuum process for tables that are never > updated? Because it has to scan the entire table to see what the oldest XID is. We don't check to see if relfrozenxid is already 2, though I suppose we could add that. > Is it safe to just update pg_class.relfrozenxid for tables where xmin=2 > for all rows? Same for linked toast table? That would be a great way to lose data... You need to look at relations where relfrozenxid is >= 3 and see why relfrozenxid isn't advancing fast enough on them. Check your cost delay settings as well as the *freeze* settings. It's very likely that on a system this busy autovac would never keep up with default settings. Also, keep in mind that transaction and multixact IDs are cluster-wide, so this is going to affect all databases in that instance. You should think about ways to move the heaviest transaction workload to a separate cluster; possibly putting the raw updates there and having a separate process that aggregates that data into fewer transactions for the main cluster. -- Jim Nasby, Data Architect, Blue Treble Consulting Data in Trouble? Get it in Treble! http://BlueTreble.com -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance