Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bS8B5-00012M-Cb for pgsql-admin@arkaria.postgresql.org; Tue, 26 Jul 2016 19:38:07 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bS8B4-0002dC-NU for pgsql-admin@arkaria.postgresql.org; Tue, 26 Jul 2016 19:38:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bS89O-0008F8-41 for pgsql-admin@postgresql.org; Tue, 26 Jul 2016 19:36:22 +0000 Received: from internet06.ebureau.com ([65.127.24.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bS89K-0006gT-OF for pgsql-admin@postgresql.org; Tue, 26 Jul 2016 19:36:21 +0000 Received: from localhost (localhost [127.0.0.1]) by internet06.ebureau.com (Postfix) with ESMTP id 070A75D9BEED; Tue, 26 Jul 2016 14:36:16 -0500 (CDT) X-Virus-Scanned: amavisd-new at ebureau.com Received: from internet06.ebureau.com ([127.0.0.1]) by localhost (internet06.ebureau.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dM9V4wf8kTV6; Tue, 26 Jul 2016 14:36:13 -0500 (CDT) Received: from [172.16.2.113] (unknown [67.148.93.60]) by internet06.ebureau.com (Postfix) with ESMTPSA id E93625D9BEDD; Tue, 26 Jul 2016 14:36:12 -0500 (CDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: Database 'template1' vacuum From: Natalie Wenz In-Reply-To: Date: Tue, 26 Jul 2016 14:36:11 -0500 Cc: Kevin Grittner Content-Transfer-Encoding: quoted-printable Message-Id: References: <95F2FD17-7813-4718-B99F-165B177EA6E9@ebureau.com> To: pgsql-admin X-Mailer: Apple Mail (2.3124) X-Pg-Spam-Score: -3.2 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org > On Jul 26, 2016, at 1:20 PM, Kevin Grittner wrote: >=20 > On Tue, Jul 26, 2016 at 1:08 PM, Natalie Wenz > wrote: >=20 >> ERROR: database is not accepting commands to avoid wraparound >> data loss in database "template1" >>=20 >> This error popped up right after I restarted a database that had >> just finished running a vacuum freeze in single user mode for the >> postgres database (the only database we use). >> (That was in response to: ERROR: database is not accepting >> commands to avoid wraparound data loss in database "postgres") >>=20 >> I'm confused about the need to vacuum template1. All of our >> activity is in the database named postgres. Do all of the >> databases share the same set of xids? >=20 > Yes. >=20 >> If they do, why would the single user backend vacuum not handle >> all of the databases at once? >=20 > A connection is always to a particular database. The big question > is why autovacuum didn't keep you out of trouble. You didn't turn > that off, did you? If not, please describe your hardware and > workload, and show you vacuum/autovacuum configuration values. I can see why you would be wondering that. :) Autovacuum is definitely on. = This situation might be considered "maintenance fallout". This database is = very large (45 TB, currently, I believe), with most of the space being occu= pied by one table. (The database is basically a big transaction log, with a= nearly all traffic being inserts. No deletes or updates on that big table.= ). I recently migrated it from 9.3 to 9.5, from one Free BSD host to anothe= r. As you can imagine, that took some time. I tried to reduce the time by "= dumping" the large table in chunks using "copy" and a date range, thereby i= ncreasing the concurrency for both dumping and restoring that data. The pro= blem is, I forgot that, even though I didn't use very many xids importing t= he data that way, it still meant that alllllll of that data would need to b= e frozen later. Once the data was all migrated and we resumed our regular t= raffic, we quickly got into trouble with the xids, since the auto vacuum co= uldn't freeze all 45 TB of that one big table while fielding up to... 500 m= illion inserts per day? (typically around 6k inserts/second) So we disabled= external connections to allow the database to vacuum, buffering the new tr= ansactions elsewhere. Now that the first enormous vacuum freeze is complete= , we are "unspooling" the data that was buffered while the database vacuume= d. Between the hardware and postgres software, we easily see this hit 65 th= ousand inserts per second. (Wooo, modern hardware! Excellent software!) Of= course, that means that we've run out of xids again in the span of about 1= 0 hours; no tuning of the auto vacuum that we've tried is able to keep pace= with that. So. I'm currently suffering through a cycle of unspool buffered= transactions, vacuum freeze while transactions buffer, unspool . . .=20 At this point, I have just left the auto vacuum defaults in place for this = database, and it generally keeps up with our typical 6k insert/second workl= oad. Even so, maintenance is problematic. We are looking into batch inserts= in the future, or table partitioning (would that help with concurrency for= maintenance? dumping, restoring, vacuuming?), or both. We also keep hoping= that maybe, just maybe, we'll see a version of postgres with 64-bit xids? = :D Anyway, template1: this is expected behavior? I'm maybe on my third or four= th round of unspool, then single user vacuum freeze. The auto vacuum is on = and free to run while I'm unspooling. I'm surprised that the auto vacuum wo= uldn't have already have vacuumed that very small database, or that haven't= been prompted to vacuum template1 prior to this, if the only transactions = in this database would have occurred during the initdb for the postgres dat= abase. Does it get used for other things during normal database operations? --=20 Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin